Content
You are here:
Refresh repository changes
Added by David Holland over 5 years ago
I am using gitea for my git repositories. In my openproject project, I use a local path for the repository.
The only problem I have, is that if I reference a work package through my commit message, I have to explicitly go to the Reporitory section and also select the correct branch for the reference to update!
My question is, if there is any API method, or link I can setup as a post-push hook for openproject to update automatically, because it is really annyoing to constantly navigate to the repository view, in order for commit references to be processed!
Replies (7)
Hi David,
There is the repository web services you can enable in the system settings of OpenProject.
Then you can request GET /sys/fetch_changeset?id=project-identifier
This can also be done a from job. Please note the sys API is only available from localhost on packaged installations.
Alternatively you can also setup a Cron job to run a command:
openproject run bundle exec rails runner "Project.find('identifier').repository.fetch_changesets"
Best,
Oliver
Okay, I thought about doing the cronjob approach, as I saw that directly below the checkbox to enable the webservice, an api key is provided, but gitea only lets me specify an url, a content type and a secret, but to my understanding, you need to authorize with username: apikey and the api key as a password.
The question is, whether I could also run a cronjob for all my projects, or do I have to add every project manually?
Or am I completely mistaken and you don't need any authorization for the update and/or do some magic with the webhook secret? Sorry that I'm kinda lost here...
If I try to issue the GET request you have specified from the same machine (`http://localhost:6000/sys/fetch_changeset?id=project-identifier`), I unfortunately get the error `404: not found`!
Also is there some documentation on this somewhere?
At the moment this is very "magical" if you know what I mean
I solved with a cron on following command:
curl -k "https://localhost/sys/fetch_changesets?id=PROJECT_IDENTIFIER&key=API_KEY"
Yes I was hoping there would be some kind of hook that would automatically do this after I push to the git repo. The commit message is quite important in our workflow as it will show us exactly what has been done and when on the issue, the parsing of issue mentions in the git commit messages are a very important.
Now I still have to visit the repo page to make it refresh.
Is there a hook on the git http backend we can tie in to? We also have many projects so setting up a job for each project is cumbersome...
For now I created a workaround thanks to your tip:
If you create a file in /home/openproject/scripts called fetch_git_changeset.rb as shown below you can run it with
openproject run bundle exec rails runner /home/openproject/scripts/fetch_git_changesets.rb
But I would love to make it a bit smarter so it would skip repos that have not changed, any tips welcome ?
Nico Aymet wrote:
Using curl not working anymore, the /sys/fetch_changesets route has been removed in app/controllers/sys_controller.rb