Show More
@@ -6,37 +6,32 b' Usage:' | |||||
6 | """ |
|
6 | """ | |
7 | from __future__ import print_function |
|
7 | from __future__ import print_function | |
8 |
|
8 | |||
9 | import re |
|
|||
10 | import requests |
|
|||
11 | import argparse |
|
9 | import argparse | |
12 |
from subprocess import |
|
10 | from subprocess import check_call, CalledProcessError | |
13 | import sys |
|
|||
14 |
|
11 | |||
15 | import gh_api |
|
12 | import gh_api | |
16 |
|
13 | |||
17 | ipy_repository = 'git://github.com/ipython/ipython.git' |
|
14 | ipy_repository = 'git://github.com/ipython/ipython.git' | |
18 | gh_project="ipython/ipython" |
|
15 | gh_project = "ipython/ipython" | |
19 | not_merged={} |
|
16 | not_merged = {} | |
20 |
|
17 | |||
21 |
|
18 | def merge_branch(repo, branch ): | ||
22 | def merge_branch(repo, branch, owner, mergeable): |
|
|||
23 | """try to merge the givent branch into the current one |
|
19 | """try to merge the givent branch into the current one | |
24 |
|
20 | |||
25 | If something does not goes smoothly, merge is aborted |
|
21 | If something does not goes smoothly, merge is aborted | |
26 |
|
22 | |||
27 | Returns True if merge sucessfull, False otherwise |
|
23 | Returns True if merge sucessfull, False otherwise | |
28 | """ |
|
24 | """ | |
29 | merged_branch = "%s-%s" % (owner, branch) |
|
|||
30 | # Delete the branch first |
|
25 | # Delete the branch first | |
31 | try : |
|
26 | try : | |
32 | check_call(['git', 'pull','--no-edit',repo, branch]) |
|
27 | check_call(['git', 'pull', '--no-edit', repo, branch]) | |
33 | except CalledProcessError : |
|
28 | except CalledProcessError : | |
34 | check_call(['git', 'merge', '--abort']) |
|
29 | check_call(['git', 'merge', '--abort']) | |
35 | return False |
|
30 | return False | |
36 | return True |
|
31 | return True | |
37 |
|
32 | |||
38 |
|
33 | |||
39 | def merge_pr(num,github_api=3): |
|
34 | def merge_pr(num, github_api=3): | |
40 | """ try to merge the branch of PR `num` into current branch |
|
35 | """ try to merge the branch of PR `num` into current branch | |
41 |
|
36 | |||
42 | github_api : use github api v2 (to bypass https and issues with proxy) to find the |
|
37 | github_api : use github api v2 (to bypass https and issues with proxy) to find the | |
@@ -48,17 +43,13 b' def merge_pr(num,github_api=3):' | |||||
48 | pr = gh_api.get_pull_request(gh_project, num, github_api) |
|
43 | pr = gh_api.get_pull_request(gh_project, num, github_api) | |
49 | if github_api == 2: |
|
44 | if github_api == 2: | |
50 | repo = pr['head']['repository']['url'] |
|
45 | repo = pr['head']['repository']['url'] | |
51 | owner = pr['head']['user']['name'] |
|
|||
52 | elif github_api == 3 : |
|
46 | elif github_api == 3 : | |
53 | repo = pr['head']['repo']['clone_url'] |
|
47 | repo = pr['head']['repo']['clone_url'] | |
54 | owner = pr['head']['repo']['owner']['login'] |
|
|||
55 |
|
48 | |||
56 |
|
49 | |||
57 | branch = pr['head']['ref'] |
|
50 | branch = pr['head']['ref'] | |
58 | mergeable = merge_branch(repo=repo, |
|
51 | mergeable = merge_branch(repo=repo, | |
59 | branch=branch, |
|
52 | branch=branch, | |
60 | owner=owner, |
|
|||
61 | mergeable=pr['mergeable'], |
|
|||
62 | ) |
|
53 | ) | |
63 | if not mergeable : |
|
54 | if not mergeable : | |
64 | cmd = "git pull "+repo+" "+branch |
|
55 | cmd = "git pull "+repo+" "+branch | |
@@ -78,7 +69,7 b' def main(*args):' | |||||
78 | and continue to the next if any. |
|
69 | and continue to the next if any. | |
79 | """ |
|
70 | """ | |
80 | ) |
|
71 | ) | |
81 | parser.add_argument('-v2','--githubapiv2', action='store_const', const=2) |
|
72 | parser.add_argument('-v2', '--githubapiv2', action='store_const', const=2) | |
82 |
|
73 | |||
83 | grp = parser.add_mutually_exclusive_group() |
|
74 | grp = parser.add_mutually_exclusive_group() | |
84 | grp.add_argument( |
|
75 | grp.add_argument( | |
@@ -98,7 +89,6 b' def main(*args):' | |||||
98 | help="The pull request numbers", |
|
89 | help="The pull request numbers", | |
99 | nargs='*', |
|
90 | nargs='*', | |
100 | metavar='pr-number') |
|
91 | metavar='pr-number') | |
101 | not_merged = {}; |
|
|||
102 | args = parser.parse_args() |
|
92 | args = parser.parse_args() | |
103 | if args.githubapiv2 == 2 : |
|
93 | if args.githubapiv2 == 2 : | |
104 | github_api = 2 |
|
94 | github_api = 2 | |
@@ -108,7 +98,7 b' def main(*args):' | |||||
108 | if(args.list): |
|
98 | if(args.list): | |
109 | pr_list = gh_api.get_pulls_list(gh_project, github_api) |
|
99 | pr_list = gh_api.get_pulls_list(gh_project, github_api) | |
110 | for pr in pr_list : |
|
100 | for pr in pr_list : | |
111 | mergeable = gh_api.get_pull_request(gh_project, pr['number'],github_api=github_api)['mergeable'] |
|
101 | mergeable = gh_api.get_pull_request(gh_project, pr['number'], github_api=github_api)['mergeable'] | |
112 |
|
102 | |||
113 | ismgb = u"√" if mergeable else " " |
|
103 | ismgb = u"√" if mergeable else " " | |
114 | print(u"* #{number} [{ismgb}]: {title}".format( |
|
104 | print(u"* #{number} [{ismgb}]: {title}".format( | |
@@ -129,8 +119,8 b' def main(*args):' | |||||
129 | if not_merged : |
|
119 | if not_merged : | |
130 | print('*************************************************************************************') |
|
120 | print('*************************************************************************************') | |
131 | print('the following branch have not been merged automatically, considere doing it by hand :') |
|
121 | print('the following branch have not been merged automatically, considere doing it by hand :') | |
132 | for num,cmd in not_merged.items() : |
|
122 | for num, cmd in not_merged.items() : | |
133 | print( "PR {num}: {cmd}".format(num=num,cmd=cmd)) |
|
123 | print( "PR {num}: {cmd}".format(num=num, cmd=cmd)) | |
134 | print('*************************************************************************************') |
|
124 | print('*************************************************************************************') | |
135 |
|
125 | |||
136 | if __name__ == '__main__': |
|
126 | if __name__ == '__main__': |
General Comments 0
You need to be logged in to leave comments.
Login now