in sync/update.py [0:0]
def update_pr(git_gecko: Repo, git_wpt: Repo, pr: PullRequest, force_rebase: bool = False,
repo_update: bool = True) -> None:
sync = get_pr_sync(git_gecko, git_wpt, pr.number)
if sync and sync.status == "complete":
logger.info("Sync already landed")
return
if sync:
logger.info("sync status %s" % sync.landable_status)
sync_point = landing.load_sync_point(git_gecko, git_wpt)
if not sync:
# If this looks like something that came from gecko, create
# a corresponding sync
with SyncLock("upstream", None) as lock:
assert isinstance(lock, SyncLock)
upstream_sync = upstream.UpstreamSync.from_pr(lock,
git_gecko,
git_wpt,
pr.number,
pr.body)
if upstream_sync is not None:
with upstream_sync.as_mut(lock):
assert isinstance(lock, SyncLock)
upstream.update_pr(git_gecko,
git_wpt,
upstream_sync,
pr.state,
pr.merged)
else:
if pr.state != "open" and not pr.merged:
return
schedule_pr_task("opened", pr, repo_update=repo_update)
update_for_status(pr, repo_update=repo_update)
elif isinstance(sync, downstream.DownstreamSync):
with SyncLock.for_process(sync.process_name) as lock:
assert isinstance(lock, SyncLock)
with sync.as_mut(lock):
if force_rebase:
central = git_gecko.rev_parse(sync.gecko_landing_branch())
commit = git_gecko.rev_parse(sync.gecko_commits.base.sha1)
# Check if the current central is already an ancestor of the commit
if git_gecko.is_ancestor(central, commit):
sync.gecko_rebase(sync.gecko_integration_branch())
else:
sync.gecko_rebase(sync.gecko_landing_branch())
if len(sync.wpt_commits) == 0:
sync.update_wpt_commits()
if not sync.bug and not (pr.state == "closed" and not pr.merged):
sync.create_bug(git_wpt, pr.number, pr.title, pr.body)
if pr.state == "open" or pr.merged:
if pr.head.sha != sync.wpt_commits.head:
# Upstream has different commits, so run a push handler
schedule_pr_task("push", pr, repo_update=repo_update)
elif sync.latest_valid_try_push:
logger.info("Treeherder url %s" % sync.latest_valid_try_push.treeherder_url)
if not sync.latest_valid_try_push.taskgroup_id:
update_taskgroup_ids(git_gecko, git_wpt,
sync.latest_valid_try_push)
if (sync.latest_valid_try_push.taskgroup_id and
not sync.latest_valid_try_push.status == "complete"):
update_tasks(git_gecko, git_wpt, sync=sync)
if not sync.latest_valid_try_push.taskgroup_id:
logger.info("Try push doesn't have a complete decision task")
return
if not pr.merged:
update_for_status(pr, repo_update=repo_update)
else:
update_for_action(pr, "closed", repo_update=repo_update)
elif isinstance(sync, upstream.UpstreamSync):
with SyncLock.for_process(sync.process_name) as lock:
assert isinstance(lock, SyncLock)
with sync.as_mut(lock):
merge_sha = pr.merge_commit_sha if pr.merged else None
upstream.update_pr(git_gecko, git_wpt, sync, pr.state, merge_sha)
sync.try_land_pr()
if merge_sha:
if git_wpt.is_ancestor(git_wpt.rev_parse(merge_sha),
git_wpt.rev_parse(sync_point["upstream"])):
# This sync already landed, so it should be finished
sync.finish()
else:
if sync.status != "complete":
sync.status = "wpt-merged" # type: ignore