summaryrefslogtreecommitdiff
path: root/ci
diff options
context:
space:
mode:
authorNirbheek Chauhan <nirbheek@centricular.com>2022-10-25 19:57:49 +0530
committerNirbheek Chauhan <nirbheek@centricular.com>2022-10-25 20:27:23 +0530
commit5468d4bf5bd1990dda2345b5833f859f01c99ec9 (patch)
treed42279e5f16d3f074f90d387f13740248734f692 /ci
parentd132592423be64ec18a223b67810ac89f391277e (diff)
downloadgstreamer-5468d4bf5bd1990dda2345b5833f859f01c99ec9.tar.gz
ci: Fetch all user cerbero branches when matching branch names
Fixes CI on coordinated merges when the user has more than 20 branches in their fork, which will happen very easily since new forks will always have all the branches of the original remote. ``` ci/gitlab/trigger_cerbero_pipeline.py:48: UserWarning: Calling a `list()` method without specifying `get_all=True` or `iterator=True` will return a maximum of 20 items. Your query returned 20 of 37 items. See https://python-gitlab.readthedocs.io/en/v3.9.0/api-usage.html#pagination for more details. If this was done intentionally, then this warning can be supressed by adding the argument `get_all=False` to the `list()` call. (python-gitlab: /usr/local/lib/python3.7/site-packages/gitlab/client.py:979) if os.environ["CI_COMMIT_REF_NAME"] in [b.name for b in cerbero.branches.list()]: ```
Diffstat (limited to 'ci')
-rwxr-xr-xci/gitlab/trigger_cerbero_pipeline.py22
1 files changed, 12 insertions, 10 deletions
diff --git a/ci/gitlab/trigger_cerbero_pipeline.py b/ci/gitlab/trigger_cerbero_pipeline.py
index 6493a3f6b7..7cccb23c65 100755
--- a/ci/gitlab/trigger_cerbero_pipeline.py
+++ b/ci/gitlab/trigger_cerbero_pipeline.py
@@ -38,26 +38,28 @@ if __name__ == "__main__":
private_token=os.environ.get('GITLAB_API_TOKEN'),
job_token=os.environ.get('CI_JOB_TOKEN'))
- cerbero = None
- cerbero_name = None
+ def get_matching_user_project(project, branch):
+ cerbero = gl.projects.get(project)
+ # Search for matching branches, return only if the branch name matches
+ # exactly
+ for b in cerbero.branches.list(search=cerbero_branch, iterator=True):
+ if branch == b.name:
+ return cerbero
+ return None
+
# We do not want to run on (often out of date) user upstream branch
if os.environ["CI_COMMIT_REF_NAME"] != os.environ['GST_UPSTREAM_BRANCH']:
try:
cerbero_name = f'{os.environ["CI_PROJECT_NAMESPACE"]}/cerbero'
- cerbero = gl.projects.get(cerbero_name)
- if os.environ["CI_COMMIT_REF_NAME"] in [b.name for b in cerbero.branches.list()]:
- cerbero_branch = os.environ["CI_COMMIT_REF_NAME"]
- else:
- # No branch with a same name on the user cerbero repo... trigger
- # on upstream project
- cerbero = None
+ cerbero_branch = os.environ["CI_COMMIT_REF_NAME"]
+ cerbero = get_matching_user_project(cerbero_name, cerbero_branch)
except gitlab.exceptions.GitlabGetError:
pass
if cerbero is None:
cerbero_name = CERBERO_PROJECT
- cerbero = gl.projects.get(cerbero_name)
cerbero_branch = os.environ["GST_UPSTREAM_BRANCH"]
+ cerbero = gl.projects.get(cerbero_name)
fprint(f"-> Triggering on branch {cerbero_branch} in {cerbero_name}\n")