Skip to content

Commit

Permalink
Merge pull request #77 from thathoff/release-4.1.0
Browse files Browse the repository at this point in the history
Release 4.1.0
  • Loading branch information
thathoff authored Feb 19, 2021
2 parents 379e8f9 + 88275e1 commit 72e0794
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 21 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
<a name="4.1.0"></a>
# [4.1.0](https://github.com/thathoff/kirby-git-content/compare/v4.0.1...4.1.0) (2021-02-19)

## Features
- Add the ability to disable the plugin via the config (Thanks @mrunkel)
- Add secret parameter to the webhooks (Thanks @mrunkel)


<a name="4.0.1"></a>
# [4.0.1](https://github.com/thathoff/kirby-git-content/compare/v4.0.0...v4.0.1) (2020-11-17)

Expand Down
11 changes: 6 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ return [
'commit' => true,
],
],
]
];
```

#### Configuration Options
Expand All @@ -73,19 +73,20 @@ return [
- `pull` (Boolean): Pull remote changes first? (default: `false`)
- `commit` (Boolean): Commit your changes? (default: `true`)
- `push` (Boolean): Push your changes to remote? (default: `false`)
- `commitMessageTemplate` (String): Configure the template for the commit message (default: `:action:(:item:): :url:`)
- `commitMessage` (String): Configure the template for the commit message (default: `:action:(:item:): :url:`)
- `cronHooksEnabled` (Boolean): Whether `/git-content/push` and `/git-content/pull` endpoints are enabled or not. (default: `true`)
- `cronHooksSecret` (String): When set, this secret must be sent with the cronHooks as a get parameter. Note: If you set
a secret, only the GET method will work on the webhooks. `/git-content/(pull|push)?secret=S0up3rS3c3t`
- `displayErrors` (Boolean): Display git errors when saving pages (default: `false`)
- `gitBin` (String): Path to the `git` binary, [See Git.php](http://kbjr.github.io/Git.php/) `Git::set_bin(string $path)`
- `windowsMode` (Boolean): [See Git.php](http://kbjr.github.io/Git.php/) `Git::windows_mode()` (default: `false`)
- `disable` (Boolean): If set to `true`, the plugin won't initialize. (default: `false`)

#### Custom Commit Message

By default the commit message is composed from the template `:action:(:item:): :url:`. So for example a change to
the page `example` will be committed with the message `update(page): example`. If you would like to change that
message you can use the `thathoff.git-content.commitMessageTemplate` option to overwrite the template.

#### Configuration Options
message you can use the `thathoff.git-content.commitMessage` option to overwrite the template.

## Git LFS
Your repository might increase over time, by adding Images, Audio, Video, Binaries, etc.
Expand Down
37 changes: 21 additions & 16 deletions index.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,24 @@

$kirbyGit = new Thathoff\GitContent\KirbyGit();

Kirby::plugin('thathoff/git-content', [
'hooks' => $kirbyGit->getHooks(),
'routes' => $kirbyGit->getRoutes(),
'options' => [
'path' => null,
'branch' => null,
'pull' => null,
'push' => null,
'commit' => null,
'cronHooksEnabled' => null,
'commitMessage' => ':action:(:item:): :url:',
'windowsMode' => null,
'gitBin' => null,
'displayErrors' => null,
]
]);
# don't load plugin if it's disabled in the config.
if (!option('thathoff.git-content.disable', false)) {
Kirby::plugin('thathoff/git-content', [
'hooks' => $kirbyGit->getHooks(),
'routes' => $kirbyGit->getRoutes(),
'options' => [
'path' => null,
'branch' => null,
'pull' => null,
'push' => null,
'commit' => null,
'cronHooksEnabled' => null,
'cronHooksSecret' => null,
'commitMessage' => ':action:(:item:): :url:',
'windowsMode' => null,
'gitBin' => null,
'displayErrors' => null,
'disable' => null,
],
]);
}
11 changes: 11 additions & 0 deletions src/KirbyGit.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,17 @@ public function getRoutes()
$route['pattern'] = 'git-content/(:any)';
$route['method'] = 'GET|POST';
$route['action'] = function($gitCommand) use ($gitHelper) {
// check to see if a secret is set, and if it is, verify it
$secret = option('thathoff.git-content.cronHooksSecret', '');
if ($secret !== '') {
$passedSecret = kirby()->request()->get('secret', '');
if ($passedSecret !== $secret) {
return [
'status' => 'forbidden',
'message' => 'Invalid secret passed',
];
}
}
switch ($gitCommand) {
case "push":
try {
Expand Down

0 comments on commit 72e0794

Please sign in to comment.