forked from maxking/docker-mailman
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathget_latest_ref.py
More file actions
executable file
·38 lines (28 loc) · 806 Bytes
/
get_latest_ref.py
File metadata and controls
executable file
·38 lines (28 loc) · 806 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#! /usr/bin/env python
import os
import sys
import gitlab
def usage():
print("{} <project_name> <project_branch>")
def main():
if 2 > len(sys.argv) > 3:
usage()
project_name = sys.argv[1]
if len(sys.argv) > 2:
branch_name = sys.argv[2]
else:
branch_name = 'master'
gl_token = os.getenv('GITLAB_TOKEN')
if gl_token is None:
print('GITLAB_TOKEN not set!')
exit(1)
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)
if __name__ == '__main__':
main()