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