##// END OF EJS Templates
Merge pull request #2260 from Carreau/fix-mpr-again...
Fernando Perez -
r8145:123c4d65 merge
parent child Browse files
Show More
@@ -1,115 +1,115
1 #!/usr/bin/env python
1 #!/usr/bin/env python
2 # -*- coding: utf-8 -*-
2 # -*- coding: utf-8 -*-
3 """
3 """
4 Usage:
4 Usage:
5 python git-mpr.py -m 1657
5 python git-mpr.py -m 1657
6 """
6 """
7 from __future__ import print_function
7 from __future__ import print_function
8
8
9 import io, os
9 import io, os
10 import argparse
10 import argparse
11 from subprocess import check_call, CalledProcessError
11 from subprocess import check_call, CalledProcessError
12
12
13 import gh_api
13 import gh_api
14
14
15 ipy_repository = 'git://github.com/ipython/ipython.git'
15 ipy_repository = 'git://github.com/ipython/ipython.git'
16 gh_project = "ipython/ipython"
16 gh_project = "ipython/ipython"
17 not_merged = {}
17 not_merged = {}
18
18
19 def merge_branch(repo, branch ):
19 def merge_branch(repo, branch ):
20 """try to merge the givent branch into the current one
20 """try to merge the givent branch into the current one
21
21
22 If something does not goes smoothly, merge is aborted
22 If something does not goes smoothly, merge is aborted
23
23
24 Returns True if merge sucessfull, False otherwise
24 Returns True if merge sucessfull, False otherwise
25 """
25 """
26 # Delete the branch first
26 # Delete the branch first
27 try :
27 try :
28 check_call(['git', 'pull', repo, branch], stdin=io.open(os.devnull))
28 check_call(['git', 'pull', repo, branch], stdin=io.open(os.devnull))
29 except CalledProcessError :
29 except CalledProcessError :
30 check_call(['git', 'merge', '--abort'])
30 check_call(['git', 'merge', '--abort'])
31 return False
31 return False
32 return True
32 return True
33
33
34
34
35 def merge_pr(num):
35 def merge_pr(num):
36 """ try to merge the branch of PR `num` into current branch
36 """ try to merge the branch of PR `num` into current branch
37 """
37 """
38 # Get Github authorisation first, so that the user is prompted straight away
38 # Get Github authorisation first, so that the user is prompted straight away
39 # if their login is needed.
39 # if their login is needed.
40
40
41 pr = gh_api.get_pull_request(gh_project, num)
41 pr = gh_api.get_pull_request(gh_project, num)
42 repo = pr['head']['repo']['clone_url']
42 repo = pr['head']['repo']['clone_url']
43
43
44
44
45 branch = pr['head']['ref']
45 branch = pr['head']['ref']
46 mergeable = merge_branch(repo=repo,
46 mergeable = merge_branch(repo=repo,
47 branch=branch,
47 branch=branch,
48 )
48 )
49 if not mergeable :
49 if not mergeable :
50 cmd = "git pull "+repo+" "+branch
50 cmd = "git pull "+repo+" "+branch
51 not_merged[str(num)] = cmd
51 not_merged[str(num)] = cmd
52 print("==============================================================================")
52 print("==============================================================================")
53 print("Something went wrong merging this branch, you can try it manually by runngin :")
53 print("Something went wrong merging this branch, you can try it manually by runngin :")
54 print(cmd)
54 print(cmd)
55 print("==============================================================================")
55 print("==============================================================================")
56
56
57
57
58 def main(*args):
58 def main(*args):
59 parser = argparse.ArgumentParser(
59 parser = argparse.ArgumentParser(
60 description="""
60 description="""
61 Merge one or more github pull requests by their number. If any
61 Merge one or more github pull requests by their number. If any
62 one pull request can't be merged as is, its merge is ignored
62 one pull request can't be merged as is, its merge is ignored
63 and the process continues with the next ones (if any).
63 and the process continues with the next ones (if any).
64 """
64 """
65 )
65 )
66
66
67 grp = parser.add_mutually_exclusive_group()
67 grp = parser.add_mutually_exclusive_group()
68 grp.add_argument(
68 grp.add_argument(
69 '-l',
69 '-l',
70 '--list',
70 '--list',
71 action='store_const',
71 action='store_const',
72 const=True,
72 const=True,
73 help='list PR, their number and their mergeability')
73 help='list PR, their number and their mergeability')
74 grp.add_argument('-a',
74 grp.add_argument('-a',
75 '--merge-all',
75 '--merge-all',
76 action='store_const',
76 action='store_const',
77 const=True ,
77 const=True ,
78 help='try to merge as many PR as possible, one by one')
78 help='try to merge as many PR as possible, one by one')
79 parser.add_argument('integers',
79 parser.add_argument('merge',
80 type=int,
80 type=int,
81 help="The pull request numbers",
81 help="The pull request numbers",
82 nargs='*',
82 nargs='*',
83 metavar='pr-number')
83 metavar='pr-number')
84 args = parser.parse_args()
84 args = parser.parse_args()
85
85
86 if(args.list):
86 if(args.list):
87 pr_list = gh_api.get_pulls_list(gh_project)
87 pr_list = gh_api.get_pulls_list(gh_project)
88 for pr in pr_list :
88 for pr in pr_list :
89 mergeable = gh_api.get_pull_request(gh_project, pr['number'])['mergeable']
89 mergeable = gh_api.get_pull_request(gh_project, pr['number'])['mergeable']
90
90
91 ismgb = u"√" if mergeable else " "
91 ismgb = u"√" if mergeable else " "
92 print(u"* #{number} [{ismgb}]: {title}".format(
92 print(u"* #{number} [{ismgb}]: {title}".format(
93 number=pr['number'],
93 number=pr['number'],
94 title=pr['title'],
94 title=pr['title'],
95 ismgb=ismgb))
95 ismgb=ismgb))
96
96
97 if(args.merge_all):
97 if(args.merge_all):
98 pr_list = gh_api.get_pulls_list(gh_project)
98 pr_list = gh_api.get_pulls_list(gh_project)
99 for pr in pr_list :
99 for pr in pr_list :
100 merge_pr(pr['number'])
100 merge_pr(pr['number'])
101
101
102
102
103 elif args.merge:
103 elif args.merge:
104 for num in args.merge :
104 for num in args.merge :
105 merge_pr(num)
105 merge_pr(num)
106
106
107 if not_merged :
107 if not_merged :
108 print('*************************************************************************************')
108 print('*************************************************************************************')
109 print('the following branch have not been merged automatically, considere doing it by hand :')
109 print('the following branch have not been merged automatically, considere doing it by hand :')
110 for num, cmd in not_merged.items() :
110 for num, cmd in not_merged.items() :
111 print( "PR {num}: {cmd}".format(num=num, cmd=cmd))
111 print( "PR {num}: {cmd}".format(num=num, cmd=cmd))
112 print('*************************************************************************************')
112 print('*************************************************************************************')
113
113
114 if __name__ == '__main__':
114 if __name__ == '__main__':
115 main()
115 main()
General Comments 0
You need to be logged in to leave comments. Login now