Allow filtering VCS webhooks based on branch name

Fixes #258
This commit is contained in:
rubenwardy 2024-06-22 12:13:49 +01:00
parent 09e06a159a
commit 7a94b9361f
3 changed files with 26 additions and 10 deletions

@ -162,7 +162,10 @@ def github_webhook():
ref = json["after"] ref = json["after"]
title = datetime.datetime.utcnow().strftime("%Y-%m-%d") + " " + ref[:5] title = datetime.datetime.utcnow().strftime("%Y-%m-%d") + " " + ref[:5]
branch = json["ref"].replace("refs/heads/", "") branch = json["ref"].replace("refs/heads/", "")
if branch not in [ "master", "main" ]: if package.update_config and package.update_config.ref:
if branch != package.update_config.ref:
continue
elif branch not in ["master", "main"]:
continue continue
elif event == "create": elif event == "create":

@ -48,11 +48,16 @@ def webhook_impl():
ref = json["after"] ref = json["after"]
title = datetime.datetime.utcnow().strftime("%Y-%m-%d") + " " + ref[:5] title = datetime.datetime.utcnow().strftime("%Y-%m-%d") + " " + ref[:5]
branch = json["ref"].replace("refs/heads/", "") branch = json["ref"].replace("refs/heads/", "")
if branch not in ["master", "main"]: if package.update_config and package.update_config.ref:
if branch != package.update_config.ref:
continue
elif branch not in ["master", "main"]:
continue continue
elif event == "tag_push": elif event == "tag_push":
ref = json["ref"] ref = json["ref"]
title = ref.replace("refs/tags/", "") title = ref.replace("refs/tags/", "")
else: else:
return error(400, "Unsupported event: '{}'. Only 'push', 'create:tag', and 'ping' are supported." return error(400, "Unsupported event: '{}'. Only 'push', 'create:tag', and 'ping' are supported."
.format(event or "null")) .format(event or "null"))

@ -16,14 +16,21 @@ See [Git Update Detection](/help/update_config/).
The process is as follows: The process is as follows:
1. The user creates an API Token and a webhook to use it. 1. The user creates an API Token and a webhook to use it.
2. The user pushes a commit to the git host (Gitlab or Github). 2. The user pushes a commit to the git host (GitLab or GitHub).
3. The git host posts a webhook notification to ContentDB, using the API token assigned to it. 3. The git host posts a webhook notification to ContentDB, using the API token assigned to it.
4. ContentDB checks the API token and issues a new release. 4. ContentDB checks the API token and issues a new release.
* If multiple packages match, then only the first will have a release created.
### Branch filtering
By default, "New commit" or "push" based webhooks will only work on "master"/"main" branches.
You can configure the branch used by changing "Branch name" in [Git update detection](update_config).
For example, to support production and beta packages you can have multiple packages with the same VCS repo URL
but different [Git update detection](update_config) branch names.
Tag-based webhooks are accepted on any branch.
<p class="alert alert-warning">
"New commit" or "push" based webhooks will currently only work on branches named `master` or
`main`.
</p>
## Setting up ## Setting up
@ -36,10 +43,10 @@ The process is as follows:
5. Set the content type to JSON. 5. Set the content type to JSON.
6. Set the secret to the access token that you copied. 6. Set the secret to the access token that you copied.
7. Set the events 7. Set the events
* If you want a rolling release, choose "just the push event". * If you want a rolling release, choose "just the push event".
* Or if you want a stable release cycle based on tags, * Or if you want a stable release cycle based on tags, choose "Let me select" > Branch or tag creation.
choose "Let me select" > Branch or tag creation.
8. Create. 8. Create.
9. If desired, change [Git update detection](update_config) > Branch name to configure the [branch filtering](#branch-filtering).
### GitLab ### GitLab
@ -53,6 +60,7 @@ The process is as follows:
* Or if you want a stable release cycle based on tags, * Or if you want a stable release cycle based on tags,
choose "Tag push events". choose "Tag push events".
8. Add webhook. 8. Add webhook.
9. If desired, change [Git update detection](update_config) > Branch name to configure the [branch filtering](#branch-filtering).
## Configuring Release Creation ## Configuring Release Creation