Skip to content

Commit bfeaccb

Browse files
committed
Genesis
0 parents  commit bfeaccb

File tree

10 files changed

+342
-0
lines changed

10 files changed

+342
-0
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
.DS_Store

.gitmodules

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[submodule "vendor/git"]
2+
path = vendor/git
3+
url = [email protected]:sebastianbergmann/git.git

account_info.png

10.8 KB
Loading

autogit.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?php
2+
3+
/**
4+
* Kirby Auto Git Plugin
5+
*
6+
* @version 0.1.0
7+
* @author Pedro Borges <[email protected]>
8+
* @copyright Pedro Borges <[email protected]>
9+
* @link https://github.com/pedroborges/kirby-autogit
10+
* @license MIT
11+
*/
12+
13+
if (class_exists('Panel')) {
14+
// Load classes
15+
require_once(__DIR__ . DS . 'vendor' . DS . 'git' . DS . 'src' . DS . 'Git.php');
16+
require_once(__DIR__ . DS . 'vendor' . DS . 'git' . DS . 'src' . DS . 'Exception' . DS . 'Exception.php');
17+
require_once(__DIR__ . DS . 'vendor' . DS . 'git' . DS . 'src' . DS . 'Exception' . DS . 'RuntimeException.php');
18+
require_once(__DIR__ . DS . 'lib' . DS . 'autogit.php');
19+
20+
// Load hooks
21+
require_once(__DIR__ . DS . 'lib' . DS . 'hooks.php');
22+
}

lib/autogit.php

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
<?php
2+
3+
namespace Autogit;
4+
5+
use SebastianBergmann\Git\Git;
6+
use C;
7+
8+
class Autogit extends Git
9+
{
10+
protected $localBranch;
11+
12+
public function __construct()
13+
{
14+
parent::__construct(kirby()->roots()->content());
15+
16+
$this->localBranch = c::get('autogit.branch', 'master');
17+
18+
$this->setBranch();
19+
$this->setUser(site()->user());
20+
}
21+
22+
public static function save(...$params)
23+
{
24+
$git = new self;
25+
26+
$message = $git->getMessage($params[0], array_slice($params, 1));
27+
28+
$git->add();
29+
$git->commit($message);
30+
}
31+
32+
public function add($path = false)
33+
{
34+
$path = $path ? $path : kirby()->roots()->content();
35+
$this->execute('add '.escapeshellarg($path));
36+
}
37+
38+
public function commit($message)
39+
{
40+
$this->execute('commit -m '.escapeshellarg($message));
41+
}
42+
43+
public function setBranch($branch = false)
44+
{
45+
$branch = $branch ? $branch : c::get('autogit.branch', 'master');
46+
$this->execute("checkout -q '{$branch}'");
47+
}
48+
49+
protected function setUser($user)
50+
{
51+
$preferUser = c::get('autogit.panel.user', true);
52+
$gitUser = c::get('autogit.user.name', 'Kirby Auto Git');
53+
$gitEmail = c::get('autogit.user.email', 'autogit@localhost');
54+
55+
if ($preferUser and $user and $user->firstname()) {
56+
$gitUser = $user->firstname();
57+
58+
if ($user->lastname()) {
59+
$gitUser .= ' '.$user->lastname();
60+
}
61+
62+
$gitEmail = $user->email();
63+
}
64+
65+
$this->execute("config user.name '{$gitUser}'");
66+
$this->execute("config user.email '{$gitEmail}'");
67+
}
68+
69+
protected function getMessage($key, $params)
70+
{
71+
$translation = c::get('autogit.translation', false);
72+
73+
if (! $translation) {
74+
$translations = require __DIR__.DS.'translations.php';
75+
$language = kirby()->option('panel.language', 'en');
76+
77+
if (! array_key_exists($language, $translations)) {
78+
$language = 'en';
79+
}
80+
81+
$translation = $translations[$language];
82+
}
83+
84+
array_unshift($params, $translation[$key]);
85+
86+
return sprintf(...$params);
87+
}
88+
}

lib/hooks.php

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
<?php
2+
3+
use Autogit\Autogit;
4+
5+
kirby()->hook('panel.site.update', function ($site) {
6+
Autogit::save('site.update');
7+
});
8+
9+
kirby()->hook('panel.page.create', function ($page) {
10+
Autogit::save('page.create', $page->uri());
11+
});
12+
13+
kirby()->hook('panel.page.update', function ($page) {
14+
Autogit::save('page.update', $page->uri());
15+
});
16+
17+
kirby()->hook('panel.page.delete', function ($page) {
18+
Autogit::save('page.delete', $page->uri());
19+
});
20+
21+
kirby()->hook('panel.page.sort', function ($page) {
22+
Autogit::save('page.sort', $page->uri());
23+
});
24+
25+
kirby()->hook('panel.page.hide', function ($page) {
26+
Autogit::save('page.hide', $page->uri());
27+
});
28+
29+
kirby()->hook('panel.page.move', function ($newPage, $oldPage) {
30+
Autogit::save('page.move', $oldPage->uri(), $newPage->uri());
31+
});
32+
33+
kirby()->hook('panel.file.upload', function ($file) {
34+
Autogit::save('file.upload', "{$file->page()->uri()}/{$file->filename()}");
35+
});
36+
37+
kirby()->hook('panel.file.replace', function ($file) {
38+
Autogit::save('file.replace', "{$file->page()->uri()}/{$file->filename()}");
39+
});
40+
41+
kirby()->hook('panel.file.rename', function ($file) {
42+
Autogit::save('file.rename', "{$file->page()->uri()}/{$file->filename()}");
43+
});
44+
45+
kirby()->hook('panel.file.update', function ($file) {
46+
Autogit::save('file.update', "{$file->page()->uri()}/{$file->filename()}");
47+
});
48+
49+
kirby()->hook('panel.file.sort', function ($file) {
50+
Autogit::save('file.sort', "{$file->page()->uri()}/{$file->filename()}");
51+
});
52+
53+
kirby()->hook('panel.file.delete', function ($file) {
54+
Autogit::save('file.delete', "{$file->page()->uri()}/{$file->filename()}");
55+
});

lib/translations.php

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
<?php
2+
3+
return [
4+
5+
'en' => [
6+
'site.update' => 'Changed site options',
7+
'page.create' => 'Created page %s',
8+
'page.update' => 'Updated page %s',
9+
'page.delete' => 'Deleted page %s',
10+
'page.sort' => 'Sorted page %s',
11+
'page.hide' => 'Hid page %s',
12+
'page.move' => 'Moved page %1$s to %2$s',
13+
'file.upload' => 'Uploaded file %s',
14+
'file.replace' => 'Replaced file %s',
15+
'file.rename' => 'Renamed file %s',
16+
'file.update' => 'Updated file %s',
17+
'file.sort' => 'Sorted file %s',
18+
'file.delete' => 'Deleted file %s',
19+
],
20+
21+
'pt_BR' => [
22+
'site.update' => 'Alterou as opções do site',
23+
'page.create' => 'Criou a página %s',
24+
'page.update' => 'Atualizou a página %s',
25+
'page.delete' => 'Excluiu a página %s',
26+
'page.sort' => 'Alterou a ordem da página %s',
27+
'page.hide' => 'Escondeu a página %s',
28+
'page.move' => 'Moveu a página %1$s para %2$s',
29+
'file.upload' => 'Adicionou o arquivo %s',
30+
'file.replace' => 'Substituiu o arquivo %s',
31+
'file.rename' => 'Renomeou o arquivo %s',
32+
'file.update' => 'Atualizou o arquivo %s',
33+
'file.sort' => 'Alterou a ordem do arquivo %s',
34+
'file.delete' => 'Excluiu o arquivo %s',
35+
],
36+
37+
'pt_PT' => [
38+
'site.update' => 'Alterou as opções do site',
39+
'page.create' => 'Criou a página %s',
40+
'page.update' => 'Atualizou a página %s',
41+
'page.delete' => 'Excluiu a página %s',
42+
'page.sort' => 'Alterou a ordem da página %s',
43+
'page.hide' => 'Escondeu a página %s',
44+
'page.move' => 'Moveu a página %1$s para %2$s',
45+
'file.upload' => 'Adicionou o ficheiro %s',
46+
'file.replace' => 'Substituiu o ficheiro %s',
47+
'file.rename' => 'Renomeou o ficheiro %s',
48+
'file.update' => 'Atualizou o ficheiro %s',
49+
'file.sort' => 'Alterou a ordem do ficheiro %s',
50+
'file.delete' => 'Excluiu o ficheiro %s',
51+
],
52+
53+
];

package.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"name": "autogit",
3+
"author": "Pedro Borges <[email protected]>",
4+
"version": "0.1.0",
5+
"description": "Kirby Auto Git Plugin",
6+
"type": "kirby-plugin",
7+
"license": "MIT"
8+
}

readme.md

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
# 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)
2+
3+
## Requirements
4+
- Kirby 2.2.3+
5+
- PHP 5.6+
6+
7+
## Main features
8+
- Works on any Kirby structure
9+
- Auto commit
10+
- Localized commit messages
11+
- Panel user as commit author
12+
13+
## Installation
14+
15+
### Site Structure
16+
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.
17+
18+
> Internally Auto Git uses `kirby()->roots()->content()` to detect the `content` folder. It can have whatever name you've registered on your Kirby installation.
19+
20+
### Download
21+
[Download the files](https://github.com/pedroborges/kirby-autogit/archive/master.zip) and place them inside `site/plugins/autogit`.
22+
23+
### Kirby CLI
24+
Kirby's [command line interface](https://github.com/getkirby/cli) makes installing the Auto Git plugin a breeze:
25+
26+
$ kirby plugin:install pedroborges/kirby-autogit
27+
28+
Updating couldn't be any easier, simply run:
29+
30+
$ kirby plugin:update pedroborges/kirby-autogit
31+
32+
### Git Submodule
33+
You can add the Auto Git plugin as a Git submodule.
34+
35+
$ cd your/project/root
36+
$ git submodule add https://github.com/pedroborges/kirby-autogit.git site/plugins/autogit
37+
$ git submodule update --init --recursive
38+
$ git commit -am "Add Kirby Auto Git plugin"
39+
40+
Updating is as easy as running a few commands.
41+
42+
$ cd your/project/root
43+
$ git submodule foreach git checkout master
44+
$ git submodule foreach git pull
45+
$ git commit -am "Update submodules"
46+
$ git submodule update --init --recursive
47+
48+
## Options
49+
The following options can be set in your `/site/config/config.php`:
50+
51+
c::set('autogit.branch', 'master');
52+
c::set('autogit.panel.user', true);
53+
c::set('autogit.user.name', 'Auto Git');
54+
c::set('autogit.user.email', 'autogit@localhost');
55+
c::set('autogit.language', 'en');
56+
c::set('autogit.translation', [
57+
'site.update' => 'Changed site options',
58+
'page.create' => 'Created page %s',
59+
'page.update' => 'Updated page %s',
60+
'page.delete' => 'Deleted page %s',
61+
'page.sort' => 'Sorted page %s',
62+
'page.hide' => 'Hid page %s',
63+
'page.move' => 'Moved page %1$s to %2$s',
64+
'file.upload' => 'Uploaded file %s',
65+
'file.replace' => 'Replaced file %s',
66+
'file.rename' => 'Renamed file %s',
67+
'file.update' => 'Updated file %s',
68+
'file.sort' => 'Sorted file %s',
69+
'file.delete' => 'Deleted file %s',
70+
]);
71+
72+
### autogit.branch
73+
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.
74+
75+
### autogit.panel.user
76+
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.**
77+
78+
![User detail](https://raw.githubusercontent.com/pedroborges/kirby-autogit/master/account_info.png)
79+
80+
> Options `autogit.user.name` and `autogit.user.email` will be overridden when this is set to `true`.
81+
82+
### autogit.user.name
83+
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.
84+
85+
### autogit.user.email
86+
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.
87+
88+
### autogit.language
89+
Default commit language. You can choose from any of the languages that ships with Auto Git: `'en'`, `'pt_BR'` or `'pt_PT'`.
90+
91+
You can also use the `autogit.translation` option to provide a custom translation, see below.
92+
93+
> Feel free to send a pull request to add support for more languages.
94+
95+
### autogit.translation
96+
An array containing a custom translation. This will override the default translation set in `autogit.language`.
97+
98+
## Roadmap
99+
- Pull and push webhooks
100+
- Panel widget
101+
102+
## FAQ
103+
104+
### How do I push commits from my server to a remote repo?
105+
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.
106+
107+
## License
108+
<http://www.opensource.org/licenses/mit-license.php>
109+
110+
## Author
111+
Pedro Borges <[email protected]>

vendor/git

Submodule git added at 5100bc5

0 commit comments

Comments
 (0)