-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit bfeaccb
Showing
10 changed files
with
342 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
.DS_Store |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
[submodule "vendor/git"] | ||
path = vendor/git | ||
url = [email protected]:sebastianbergmann/git.git |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<?php | ||
|
||
/** | ||
* Kirby Auto Git Plugin | ||
* | ||
* @version 0.1.0 | ||
* @author Pedro Borges <[email protected]> | ||
* @copyright Pedro Borges <[email protected]> | ||
* @link https://github.com/pedroborges/kirby-autogit | ||
* @license MIT | ||
*/ | ||
|
||
if (class_exists('Panel')) { | ||
// Load classes | ||
require_once(__DIR__ . DS . 'vendor' . DS . 'git' . DS . 'src' . DS . 'Git.php'); | ||
require_once(__DIR__ . DS . 'vendor' . DS . 'git' . DS . 'src' . DS . 'Exception' . DS . 'Exception.php'); | ||
require_once(__DIR__ . DS . 'vendor' . DS . 'git' . DS . 'src' . DS . 'Exception' . DS . 'RuntimeException.php'); | ||
require_once(__DIR__ . DS . 'lib' . DS . 'autogit.php'); | ||
|
||
// Load hooks | ||
require_once(__DIR__ . DS . 'lib' . DS . 'hooks.php'); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
<?php | ||
|
||
namespace Autogit; | ||
|
||
use SebastianBergmann\Git\Git; | ||
use C; | ||
|
||
class Autogit extends Git | ||
{ | ||
protected $localBranch; | ||
|
||
public function __construct() | ||
{ | ||
parent::__construct(kirby()->roots()->content()); | ||
|
||
$this->localBranch = c::get('autogit.branch', 'master'); | ||
|
||
$this->setBranch(); | ||
$this->setUser(site()->user()); | ||
} | ||
|
||
public static function save(...$params) | ||
{ | ||
$git = new self; | ||
|
||
$message = $git->getMessage($params[0], array_slice($params, 1)); | ||
|
||
$git->add(); | ||
$git->commit($message); | ||
} | ||
|
||
public function add($path = false) | ||
{ | ||
$path = $path ? $path : kirby()->roots()->content(); | ||
$this->execute('add '.escapeshellarg($path)); | ||
} | ||
|
||
public function commit($message) | ||
{ | ||
$this->execute('commit -m '.escapeshellarg($message)); | ||
} | ||
|
||
public function setBranch($branch = false) | ||
{ | ||
$branch = $branch ? $branch : c::get('autogit.branch', 'master'); | ||
$this->execute("checkout -q '{$branch}'"); | ||
} | ||
|
||
protected function setUser($user) | ||
{ | ||
$preferUser = c::get('autogit.panel.user', true); | ||
$gitUser = c::get('autogit.user.name', 'Kirby Auto Git'); | ||
$gitEmail = c::get('autogit.user.email', 'autogit@localhost'); | ||
|
||
if ($preferUser and $user and $user->firstname()) { | ||
$gitUser = $user->firstname(); | ||
|
||
if ($user->lastname()) { | ||
$gitUser .= ' '.$user->lastname(); | ||
} | ||
|
||
$gitEmail = $user->email(); | ||
} | ||
|
||
$this->execute("config user.name '{$gitUser}'"); | ||
$this->execute("config user.email '{$gitEmail}'"); | ||
} | ||
|
||
protected function getMessage($key, $params) | ||
{ | ||
$translation = c::get('autogit.translation', false); | ||
|
||
if (! $translation) { | ||
$translations = require __DIR__.DS.'translations.php'; | ||
$language = kirby()->option('panel.language', 'en'); | ||
|
||
if (! array_key_exists($language, $translations)) { | ||
$language = 'en'; | ||
} | ||
|
||
$translation = $translations[$language]; | ||
} | ||
|
||
array_unshift($params, $translation[$key]); | ||
|
||
return sprintf(...$params); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
<?php | ||
|
||
use Autogit\Autogit; | ||
|
||
kirby()->hook('panel.site.update', function ($site) { | ||
Autogit::save('site.update'); | ||
}); | ||
|
||
kirby()->hook('panel.page.create', function ($page) { | ||
Autogit::save('page.create', $page->uri()); | ||
}); | ||
|
||
kirby()->hook('panel.page.update', function ($page) { | ||
Autogit::save('page.update', $page->uri()); | ||
}); | ||
|
||
kirby()->hook('panel.page.delete', function ($page) { | ||
Autogit::save('page.delete', $page->uri()); | ||
}); | ||
|
||
kirby()->hook('panel.page.sort', function ($page) { | ||
Autogit::save('page.sort', $page->uri()); | ||
}); | ||
|
||
kirby()->hook('panel.page.hide', function ($page) { | ||
Autogit::save('page.hide', $page->uri()); | ||
}); | ||
|
||
kirby()->hook('panel.page.move', function ($newPage, $oldPage) { | ||
Autogit::save('page.move', $oldPage->uri(), $newPage->uri()); | ||
}); | ||
|
||
kirby()->hook('panel.file.upload', function ($file) { | ||
Autogit::save('file.upload', "{$file->page()->uri()}/{$file->filename()}"); | ||
}); | ||
|
||
kirby()->hook('panel.file.replace', function ($file) { | ||
Autogit::save('file.replace', "{$file->page()->uri()}/{$file->filename()}"); | ||
}); | ||
|
||
kirby()->hook('panel.file.rename', function ($file) { | ||
Autogit::save('file.rename', "{$file->page()->uri()}/{$file->filename()}"); | ||
}); | ||
|
||
kirby()->hook('panel.file.update', function ($file) { | ||
Autogit::save('file.update', "{$file->page()->uri()}/{$file->filename()}"); | ||
}); | ||
|
||
kirby()->hook('panel.file.sort', function ($file) { | ||
Autogit::save('file.sort', "{$file->page()->uri()}/{$file->filename()}"); | ||
}); | ||
|
||
kirby()->hook('panel.file.delete', function ($file) { | ||
Autogit::save('file.delete', "{$file->page()->uri()}/{$file->filename()}"); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
<?php | ||
|
||
return [ | ||
|
||
'en' => [ | ||
'site.update' => 'Changed site options', | ||
'page.create' => 'Created page %s', | ||
'page.update' => 'Updated page %s', | ||
'page.delete' => 'Deleted page %s', | ||
'page.sort' => 'Sorted page %s', | ||
'page.hide' => 'Hid page %s', | ||
'page.move' => 'Moved page %1$s to %2$s', | ||
'file.upload' => 'Uploaded file %s', | ||
'file.replace' => 'Replaced file %s', | ||
'file.rename' => 'Renamed file %s', | ||
'file.update' => 'Updated file %s', | ||
'file.sort' => 'Sorted file %s', | ||
'file.delete' => 'Deleted file %s', | ||
], | ||
|
||
'pt_BR' => [ | ||
'site.update' => 'Alterou as opções do site', | ||
'page.create' => 'Criou a página %s', | ||
'page.update' => 'Atualizou a página %s', | ||
'page.delete' => 'Excluiu a página %s', | ||
'page.sort' => 'Alterou a ordem da página %s', | ||
'page.hide' => 'Escondeu a página %s', | ||
'page.move' => 'Moveu a página %1$s para %2$s', | ||
'file.upload' => 'Adicionou o arquivo %s', | ||
'file.replace' => 'Substituiu o arquivo %s', | ||
'file.rename' => 'Renomeou o arquivo %s', | ||
'file.update' => 'Atualizou o arquivo %s', | ||
'file.sort' => 'Alterou a ordem do arquivo %s', | ||
'file.delete' => 'Excluiu o arquivo %s', | ||
], | ||
|
||
'pt_PT' => [ | ||
'site.update' => 'Alterou as opções do site', | ||
'page.create' => 'Criou a página %s', | ||
'page.update' => 'Atualizou a página %s', | ||
'page.delete' => 'Excluiu a página %s', | ||
'page.sort' => 'Alterou a ordem da página %s', | ||
'page.hide' => 'Escondeu a página %s', | ||
'page.move' => 'Moveu a página %1$s para %2$s', | ||
'file.upload' => 'Adicionou o ficheiro %s', | ||
'file.replace' => 'Substituiu o ficheiro %s', | ||
'file.rename' => 'Renomeou o ficheiro %s', | ||
'file.update' => 'Atualizou o ficheiro %s', | ||
'file.sort' => 'Alterou a ordem do ficheiro %s', | ||
'file.delete' => 'Excluiu o ficheiro %s', | ||
], | ||
|
||
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"name": "autogit", | ||
"author": "Pedro Borges <[email protected]>", | ||
"version": "0.1.0", | ||
"description": "Kirby Auto Git Plugin", | ||
"type": "kirby-plugin", | ||
"license": "MIT" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
# Kirby Auto Git Plugin [![Release](https://img.shields.io/github/release/pedroborges/kirby-autogit.svg)](https://github.com/pedroborges/kirby-autogit/releases) [![Issues](https://img.shields.io/github/issues/pedroborges/kirby-autogit.svg)](https://github.com/pedroborges/kirby-autogit/issues) | ||
|
||
## Requirements | ||
- Kirby 2.2.3+ | ||
- PHP 5.6+ | ||
|
||
## Main features | ||
- Works on any Kirby structure | ||
- Auto commit | ||
- Localized commit messages | ||
- Panel user as commit author | ||
|
||
## Installation | ||
|
||
### Site Structure | ||
You can use whatever site structure fits better your needs. It doesn't matter whether your `content` folder is part of the main Git repo or is a submodule. Auto Git is smart enough to only commit changes made inside the `content` folder. | ||
|
||
> Internally Auto Git uses `kirby()->roots()->content()` to detect the `content` folder. It can have whatever name you've registered on your Kirby installation. | ||
### Download | ||
[Download the files](https://github.com/pedroborges/kirby-autogit/archive/master.zip) and place them inside `site/plugins/autogit`. | ||
|
||
### Kirby CLI | ||
Kirby's [command line interface](https://github.com/getkirby/cli) makes installing the Auto Git plugin a breeze: | ||
|
||
$ kirby plugin:install pedroborges/kirby-autogit | ||
|
||
Updating couldn't be any easier, simply run: | ||
|
||
$ kirby plugin:update pedroborges/kirby-autogit | ||
|
||
### Git Submodule | ||
You can add the Auto Git plugin as a Git submodule. | ||
|
||
$ cd your/project/root | ||
$ git submodule add https://github.com/pedroborges/kirby-autogit.git site/plugins/autogit | ||
$ git submodule update --init --recursive | ||
$ git commit -am "Add Kirby Auto Git plugin" | ||
|
||
Updating is as easy as running a few commands. | ||
|
||
$ cd your/project/root | ||
$ git submodule foreach git checkout master | ||
$ git submodule foreach git pull | ||
$ git commit -am "Update submodules" | ||
$ git submodule update --init --recursive | ||
|
||
## Options | ||
The following options can be set in your `/site/config/config.php`: | ||
|
||
c::set('autogit.branch', 'master'); | ||
c::set('autogit.panel.user', true); | ||
c::set('autogit.user.name', 'Auto Git'); | ||
c::set('autogit.user.email', 'autogit@localhost'); | ||
c::set('autogit.language', 'en'); | ||
c::set('autogit.translation', [ | ||
'site.update' => 'Changed site options', | ||
'page.create' => 'Created page %s', | ||
'page.update' => 'Updated page %s', | ||
'page.delete' => 'Deleted page %s', | ||
'page.sort' => 'Sorted page %s', | ||
'page.hide' => 'Hid page %s', | ||
'page.move' => 'Moved page %1$s to %2$s', | ||
'file.upload' => 'Uploaded file %s', | ||
'file.replace' => 'Replaced file %s', | ||
'file.rename' => 'Renamed file %s', | ||
'file.update' => 'Updated file %s', | ||
'file.sort' => 'Sorted file %s', | ||
'file.delete' => 'Deleted file %s', | ||
]); | ||
|
||
### autogit.branch | ||
Sets the Git branch where commits will go to. Auto Git **won't** create the branch for you, make sure it exists prior to changing the default value. | ||
|
||
### autogit.panel.user | ||
Sets if Auto Git should use Kirby's panel user name and email as commit author. This will enable you to see who made each change on your Git client of choice or simply by running `$ git log`. **The user must have first name and email set on their account info.** | ||
|
||
![User detail](https://raw.githubusercontent.com/pedroborges/kirby-autogit/master/account_info.png) | ||
|
||
> Options `autogit.user.name` and `autogit.user.email` will be overridden when this is set to `true`. | ||
### autogit.user.name | ||
Default commit author name. Applied only when the option `autogit.panel.user` is set to `false` or when user's first name isn't set on his account info. | ||
|
||
### autogit.user.email | ||
Default commit author email. Applied only when the option `autogit.panel.user` is set to `false` or when user's first name isn't set on his account info. | ||
|
||
### autogit.language | ||
Default commit language. You can choose from any of the languages that ships with Auto Git: `'en'`, `'pt_BR'` or `'pt_PT'`. | ||
|
||
You can also use the `autogit.translation` option to provide a custom translation, see below. | ||
|
||
> Feel free to send a pull request to add support for more languages. | ||
### autogit.translation | ||
An array containing a custom translation. This will override the default translation set in `autogit.language`. | ||
|
||
## Roadmap | ||
- Pull and push webhooks | ||
- Panel widget | ||
|
||
## FAQ | ||
|
||
### How do I push commits from my server to a remote repo? | ||
Right now the recommended way is to use a cron job to run `$ git push` frequently. Soon you'll have the option to do this manually from a panel widget or automatically by using a webhook to easily integrate with other services. | ||
|
||
## License | ||
<http://www.opensource.org/licenses/mit-license.php> | ||
|
||
## Author | ||
Pedro Borges <[email protected]> |