|
33 | 33 | import shlex
|
34 | 34 | import random
|
35 | 35 | from .pull_req_state import PullReqState
|
| 36 | +from .pull_request_events import all as all_pull_request_events |
36 | 37 |
|
37 | 38 | global_cfg = {}
|
38 | 39 |
|
@@ -1166,66 +1167,85 @@ def synchronize(repo_label, repo_cfg, logger, gh, states, repos, db, mergeable_q
|
1166 | 1167 | states[repo_label] = {}
|
1167 | 1168 | repos[repo_label] = Repository(repo, repo_label, db)
|
1168 | 1169 |
|
| 1170 | + print("Getting pulls...") |
1169 | 1171 | for pull in repo.iter_pulls(state='open'):
|
1170 |
| - db.execute( |
1171 |
| - 'SELECT status FROM pull WHERE repo = ? AND num = ?', |
1172 |
| - [repo_label, pull.number]) |
1173 |
| - row = db.fetchone() |
1174 |
| - if row: |
1175 |
| - status = row[0] |
1176 |
| - else: |
1177 |
| - status = '' |
1178 |
| - for info in utils.github_iter_statuses(repo, pull.head.sha): |
1179 |
| - if info.context == 'homu': |
1180 |
| - status = info.state |
1181 |
| - break |
| 1172 | +# db.execute( |
| 1173 | +# 'SELECT status FROM pull WHERE repo = ? AND num = ?', |
| 1174 | +# [repo_label, pull.number]) |
| 1175 | +# row = db.fetchone() |
| 1176 | +# if row: |
| 1177 | +# status = row[0] |
| 1178 | +# else: |
| 1179 | +# status = '' |
| 1180 | +# for info in utils.github_iter_statuses(repo, pull.head.sha): |
| 1181 | +# if info.context == 'homu': |
| 1182 | +# status = info.state |
| 1183 | +# break |
| 1184 | + |
| 1185 | + if pull.number in [60966, 60730, 60547, 59312]: |
| 1186 | + # TODO: WHY DOES THIS HAPPEN!? |
| 1187 | + print("Skipping {} because GraphQL never returns a success!".format(pull.number)) |
| 1188 | + continue |
| 1189 | + |
| 1190 | + print("{}/{}#{}".format(repo_cfg['owner'], repo_cfg['name'], pull.number)) |
| 1191 | + access_token = global_cfg['github']['access_token'] |
| 1192 | + response = all_pull_request_events(access_token, repo_cfg['owner'], repo_cfg['name'], pull.number) |
| 1193 | + status = '' |
1182 | 1194 |
|
1183 | 1195 | state = PullReqState(pull.number, pull.head.sha, status, db, repo_label, mergeable_que, gh, repo_cfg['owner'], repo_cfg['name'], repo_cfg.get('labels', {}), repos) # noqa
|
1184 |
| - state.title = pull.title |
| 1196 | + state.cfg = repo_cfg |
| 1197 | + state.title = response.initial_title |
1185 | 1198 | state.body = pull.body
|
1186 | 1199 | state.head_ref = pull.head.repo[0] + ':' + pull.head.ref
|
1187 | 1200 | state.base_ref = pull.base.ref
|
1188 |
| - state.set_mergeable(None) |
1189 |
| - state.assignee = pull.assignee.login if pull.assignee else '' |
1190 |
| - |
1191 |
| - for comment in pull.iter_comments(): |
1192 |
| - if comment.original_commit_id == pull.head.sha: |
1193 |
| - parse_commands( |
1194 |
| - comment.body, |
1195 |
| - comment.user.login, |
1196 |
| - repo_label, |
1197 |
| - repo_cfg, |
1198 |
| - state, |
1199 |
| - my_username, |
1200 |
| - db, |
1201 |
| - states, |
1202 |
| - sha=comment.original_commit_id, |
1203 |
| - command_src=comment.to_json()['html_url'], |
1204 |
| - # FIXME switch to `comment.html_url` |
1205 |
| - # after updating github3 to 1.3.0+ |
1206 |
| - ) |
1207 |
| - |
1208 |
| - for comment in pull.iter_issue_comments(): |
1209 |
| - parse_commands( |
1210 |
| - comment.body, |
1211 |
| - comment.user.login, |
1212 |
| - repo_label, |
1213 |
| - repo_cfg, |
1214 |
| - state, |
1215 |
| - my_username, |
1216 |
| - db, |
1217 |
| - states, |
1218 |
| - command_src=comment.to_json()['html_url'], |
1219 |
| - # FIXME switch to `comment.html_url` |
1220 |
| - # after updating github3 to 1.3.0+ |
1221 |
| - ) |
1222 |
| - |
1223 |
| - saved_state = saved_states.get(pull.number) |
1224 |
| - if saved_state: |
1225 |
| - for key, val in saved_state.items(): |
1226 |
| - setattr(state, key, val) |
1227 |
| - |
1228 |
| - state.save() |
| 1201 | + if response.mergeable == 'MERGEABLE': |
| 1202 | + state.set_mergeable(True) |
| 1203 | + elif response.mergeable == 'CONFLICTING': |
| 1204 | + state.set_mergeable(False) |
| 1205 | + else: |
| 1206 | + state.set_mergeable(None) |
| 1207 | + state.assignee = '' |
| 1208 | + |
| 1209 | +# for comment in pull.iter_comments(): |
| 1210 | +# if comment.original_commit_id == pull.head.sha: |
| 1211 | +# parse_commands( |
| 1212 | +# comment.body, |
| 1213 | +# comment.user.login, |
| 1214 | +# repo_label, |
| 1215 | +# repo_cfg, |
| 1216 | +# state, |
| 1217 | +# my_username, |
| 1218 | +# db, |
| 1219 | +# states, |
| 1220 | +# sha=comment.original_commit_id, |
| 1221 | +# command_src=comment.to_json()['html_url'], |
| 1222 | +# # FIXME switch to `comment.html_url` |
| 1223 | +# # after updating github3 to 1.3.0+ |
| 1224 | +# ) |
| 1225 | +# |
| 1226 | +# for comment in pull.iter_issue_comments(): |
| 1227 | +# parse_commands( |
| 1228 | +# comment.body, |
| 1229 | +# comment.user.login, |
| 1230 | +# repo_label, |
| 1231 | +# repo_cfg, |
| 1232 | +# state, |
| 1233 | +# my_username, |
| 1234 | +# db, |
| 1235 | +# states, |
| 1236 | +# command_src=comment.to_json()['html_url'], |
| 1237 | +# # FIXME switch to `comment.html_url` |
| 1238 | +# # after updating github3 to 1.3.0+ |
| 1239 | +# ) |
| 1240 | +# |
| 1241 | +# saved_state = saved_states.get(pull.number) |
| 1242 | +# if saved_state: |
| 1243 | +# for key, val in saved_state.items(): |
| 1244 | +# setattr(state, key, val) |
| 1245 | +# |
| 1246 | +# state.save() |
| 1247 | + for event in response.events: |
| 1248 | + state.process_event(event) |
1229 | 1249 |
|
1230 | 1250 | states[repo_label][pull.number] = state
|
1231 | 1251 |
|
|
0 commit comments