From a6d2792ee13346939b7c8cdc580a3c63c6d131f6 Mon Sep 17 00:00:00 2001 From: Abhilash Raj Date: Wed, 25 Aug 2021 04:27:50 -0700 Subject: [PATCH] Iterate over commits until we find something that passed CI (#494) * Iterate over commits until we find something that passed CI * Fix a bug --- get_latest_ref.py | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/get_latest_ref.py b/get_latest_ref.py index 4276e44..a761d7e 100755 --- a/get_latest_ref.py +++ b/get_latest_ref.py @@ -25,14 +25,17 @@ def main(): gl = gitlab.Gitlab('https://gitlab.com/', gl_token) project = gl.projects.get(project_name) - branch = project.branches.get(branch_name) - top_commit = project.commits.get(branch.commit['short_id']) - - if top_commit.last_pipeline['status'] == 'success': - print(top_commit.short_id) - else: - exit(1) + # Find the last commit in the branch that passed the CI + # successfully and return the reference to it. + for commit in project.commits.list(ref=branch_name): + stasues = list(status.status == 'success' for status in + commit.statuses.list() if status.allow_failure == False) + if len(stasues) == 0: + continue + if all(stasues): + print(commit.short_id) + break if __name__ == '__main__': main()