thathoff / kirby-git-content

Commit and Push changes made via the Panel
MIT License
135 stars 20 forks source link

Add a panel button to push to remote #85

Closed gryzzly closed 2 years ago

gryzzly commented 2 years ago

Hey!

I am helping a friend with their Kirby website and I’d like to enable them (non-tech person) to get the content backed up on git. I think this plugin is perfect for that (I was doing commits once in a while from SSH), but their hosting plan doesn’t offer cron job integration. The content is a lot of images, so doing commits after each change to /content folder sounds slow. But if the cron job would simply trigger an endpoint, would it be a lot of work for me to add a button in the panel that triggers the push? So the friend could simply run it once a week / once in a month or after they are done with a bunch of changes.

Thanks!

moddyn6 commented 2 years ago

Hey gryzzly,

maybe a cheap solution would be to use the 'push'-route, that is implemented in the plugin already. You could create a bookmark for your friend that links to <Your-URL>/git-content/push. That should push the content every time it is called.

I am not entirely sure but I think even for a simple button with a custom link you would have to create your own plugin and add a custom section in Vue that implements this button (you may want to take a look at this cookbook recipie: https://getkirby.com/docs/cookbook/extensions/first-panel-section)

In an old version of the plugin there was a button like the one you need, but I think it got removed when the panel was switched to Vue for v3 of kirby. Maybe it will get implemented again - should not be too hard.

gryzzly commented 2 years ago

Very helpful, thanks for the kind advice!

I found this plugin called "Janitor" (https://github.com/bnomei/kirby3-janitor) that allows adding a button via fields in the blueprints, and I think adding a button to do an API call to /git-content/push should work!

I’ll update the issue once it’s working

gryzzly commented 2 years ago

@moddyn6

Hey, so I‘m trying to call the git endpoint like this:

In config.php:

'bnomei.janitor.jobs' => [
    'contentPush' => function (Kirby\Cms\Page $page = null, string $data = null) {
        // $page => page object where the button as pressed
        $kirby->call('/git-content/push?secret=foobar');
        return [
            'status' => 200,
            'label' => $page->title() . ' ' . $data,
        ];
    },
  ],
  'thathoff' => [
    'git-content' => [
      'commit' => true,
      'cronHooksEnabled' => true,
      'cronHooksSecret' => 'foobar',
      'displayErrors' => true
    ],
  ]

where contentPush is a function that Janitor calls from a button in the panel. But pressing the button is always showing a dialogue saying: No route found for path: "git-content/push" and request method: "GET".

However, I can see that the route is indeed installed at http://localhost:8000/git-content/push – if I visit it I receive the appropriate error message in JSON like this:

{"status":"forbidden","message":"Invalid secret passed"}

Do you see something obviously wrong with what I am doing?

Thanks!