forked from cms-sw/cms-bot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
auto-trigger-pr
executable file
·60 lines (48 loc) · 2.1 KB
/
auto-trigger-pr
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#!/usr/bin/env python
from github import Github
from os.path import expanduser
from optparse import OptionParser
# Decides if a Pull Request can be automatically tested
# For now, it checks if at least one person has approved the PR
# It also checks that the PR is not being tested already.
# args[0] is the PR number
#
# If it decides that the PR can be automatically tested, it exits 0,
# otherwise it exits 1
# ---------------------------------------------------------------------------
# Start of Execution
# ---------------------------------------------------------------------------
if __name__ == "__main__":
parser = OptionParser( usage="%prog <pr-number>" )
parser.add_option("-f", "--force", dest="force", action="store_true",
help="Promote tests, regardless of status.", default=False)
opts, args = parser.parse_args()
pr_number = int( args[ 0 ] )
if not len(args):
parser.error( "Please specify the number of the pull request" )
gh = Github(login_or_token=open(expanduser("~/.github-token")).read().strip())
repo = gh.get_repo( "cms-sw/cmssw" )
issue = repo.get_issue( pr_number )
labels = [ l for l in issue.get_labels() ]
if len( labels ) == 0:
print 'It does not have any labels, not triggering'
exit( 1 )
approved_labels = [ x.name for x in labels if 'approved' in x.name ]
someone_approved = len( approved_labels ) > 0
# if noone has approved I don't trigger the tests
if not someone_approved and not opts.force:
print 'nobody has approved, tests not triggered'
exit( 1 )
elif opts.force:
print "Force passed, triggering in any case"
commits = [ c for c in repo.get_pull( pr_number ).get_commits( ) ]
last_commit_statuses = [ s for s in commits[ -1 ].get_statuses() ]
if len( last_commit_statuses ) > 0:
last_commit_last_status = last_commit_statuses[ -1 ]
# if it is already being tested I don't trigger the tests
if last_commit_last_status.state == 'pending':
print 'it is already being tested, tests not triggered'
exit( 1 )
# it passed all the filters
print 'passed all the filters, triggering'
exit( 0 )