Get remote repository default branch
sgotti opened this issue · 1 comments
sgotti commented
It will be useful, for example to show the build badge in the agola web ui, to know the default remote repository branch.
I investigated how to retrieve the remote default branch. There're different ways:
- get the remote default branch asking for the remote HEAD branch (i.e. the output from
git remote show origin
) but this isn't feasible to do this on the agola backend (since we'll have to setup a temporary git repo, call the git command and parse the output). - A remote source api to get the remote default branch (it's available on github but I'm not sure if it's also available on gitea and gitlab).
- Retrieving and saving this information when receiving a webhook, look like github, gitea and gitlab webhooks provides information about the repository default branch (at least on push event) (https://docs.github.com/en/developers/webhooks-and-events/webhooks/webhook-events-and-payloads#push, https://docs.gitea.io/en-us/webhooks/ , https://docs.gitlab.com/ee/user/project/integrations/webhooks.html#push-events).
So when receiving a push webhook we could get the default branch and update the repository information with it (adding a new field not existing yet) (it'll remain the same until we receive a new push webhook, so if the user changes the default branch without pushing nothing we won't update it). Looks like the more feasibile and easier way.
alessandro-sorint commented
@sgotti I investigated about the api, they returns all the default branch.
I think it is the better way because we don't have webhook when the user change the default branch.
About the gateway must all the api that return the type ProjectResponse have the default branch value?