##// END OF EJS Templates
Allow checking for backports via milestone
Skipper Seabold -
Show More
@@ -32,6 +32,7 b' from gh_api import ('
32 get_pull_request,
32 get_pull_request,
33 get_pull_request_files,
33 get_pull_request_files,
34 is_pull_request,
34 is_pull_request,
35 get_milestone_id,
35 )
36 )
36
37
37 def find_rejects(root='.'):
38 def find_rejects(root='.'):
@@ -107,18 +108,33 b' def already_backported(branch, since_tag=None):'
107 lines = check_output(cmd).decode('utf8')
108 lines = check_output(cmd).decode('utf8')
108 return set(int(num) for num in backport_re.findall(lines))
109 return set(int(num) for num in backport_re.findall(lines))
109
110
110 def should_backport(labels):
111 def should_backport(labels=None, milestone=None):
111 """return set of PRs marked for backport"""
112 """return set of PRs marked for backport"""
113 if labels is None and milestone is None:
114 raise ValueError("Specify one of labels or milestone.")
115 elif labels is not None and milestone is not None:
116 raise ValueError("Specify only one of labels or milestone.")
117 if labels is not None:
112 issues = get_issues_list("ipython/ipython",
118 issues = get_issues_list("ipython/ipython",
113 labels=labels,
119 labels=labels,
114 state='closed',
120 state='closed',
115 auth=True,
121 auth=True,
116 )
122 )
123 else:
124 milestone_id = get_milestone_id("ipython/ipython", milestone,
125 auth=True)
126 issues = get_issues_list("ipython/ipython",
127 milestone=milestone_id,
128 state='closed',
129 auth=True,
130 )
131
117 should_backport = set()
132 should_backport = set()
118 for issue in issues:
133 for issue in issues:
119 if not is_pull_request(issue):
134 if not is_pull_request(issue):
120 continue
135 continue
121 pr = get_pull_request("ipython/ipython", issue['number'], auth=True)
136 pr = get_pull_request("ipython/ipython", issue['number'],
137 auth=True)
122 if not pr['merged']:
138 if not pr['merged']:
123 print ("Marked PR closed without merge: %i" % pr['number'])
139 print ("Marked PR closed without merge: %i" % pr['number'])
124 continue
140 continue
@@ -156,6 +156,23 b' def get_issues_list(project, auth=False, **params):'
156 pages = get_paged_request(url, headers=headers, **params)
156 pages = get_paged_request(url, headers=headers, **params)
157 return pages
157 return pages
158
158
159 def get_milestones(project, auth=False, **params):
160 url = "https://api.github.com/repos/{project}/milestones".format(project=project)
161 if auth:
162 headers = make_auth_header()
163 else:
164 headers = None
165 pages = get_paged_request(url, headers=headers, **params)
166 return pages
167
168 def get_milestone_id(project, milestone, auth=False, **params):
169 pages = get_milestones(project, auth=auth, **params)
170 for page in pages:
171 if page['title'] == milestone:
172 return page['number']
173 else:
174 raise ValueError("milestone %s not found" % milestone)
175
159 def is_pull_request(issue):
176 def is_pull_request(issue):
160 """Return True if the given issue is a pull request."""
177 """Return True if the given issue is a pull request."""
161 return bool(issue.get('pull_request', {}).get('html_url', None))
178 return bool(issue.get('pull_request', {}).get('html_url', None))
General Comments 0
You need to be logged in to leave comments. Login now