|
18 | 18 | from github.Repository import Repository |
19 | 19 |
|
20 | 20 | from ci_config import CHECK_DESCRIPTIONS, REQUIRED_CHECKS, CheckDescription, StatusNames |
21 | | -from env_helper import GITHUB_REPOSITORY, GITHUB_RUN_URL, TEMP_PATH |
| 21 | +from env_helper import ( |
| 22 | + GITHUB_REPOSITORY, |
| 23 | + GITHUB_RUN_URL, |
| 24 | + GITHUB_UPSTREAM_REPOSITORY, |
| 25 | + TEMP_PATH, |
| 26 | +) |
22 | 27 | from lambda_shared_package.lambda_shared.pr import Labels |
23 | 28 | from pr_info import PRInfo |
24 | 29 | from report import ( |
|
29 | 34 | StatusType, |
30 | 35 | TestResult, |
31 | 36 | TestResults, |
| 37 | + get_status, |
32 | 38 | get_worst_status, |
33 | 39 | ) |
34 | 40 | from s3_helper import S3Helper |
@@ -500,3 +506,60 @@ def trigger_mergeable_check( |
500 | 506 | return set_mergeable_check(commit, description, state, hide_url) |
501 | 507 |
|
502 | 508 | return mergeable_status |
| 509 | + |
| 510 | + |
| 511 | +def update_upstream_sync_status( |
| 512 | + upstream_pr_number: int, |
| 513 | + sync_pr_number: int, |
| 514 | + gh: Github, |
| 515 | + mergeable_status: CommitStatus, |
| 516 | +) -> None: |
| 517 | + upstream_repo = gh.get_repo(GITHUB_UPSTREAM_REPOSITORY) |
| 518 | + upstream_pr = upstream_repo.get_pull(upstream_pr_number) |
| 519 | + sync_repo = gh.get_repo(GITHUB_REPOSITORY) |
| 520 | + sync_pr = sync_repo.get_pull(sync_pr_number) |
| 521 | + # Find the commit that is in both repos, upstream and cloud |
| 522 | + sync_commits = sync_pr.get_commits().reversed |
| 523 | + upstream_commits = upstream_pr.get_commits() |
| 524 | + # Github objects are compared by _url attribute. We can't compare them directly and |
| 525 | + # should compare commits by SHA1 |
| 526 | + upstream_shas = [uc.sha for uc in upstream_commits] |
| 527 | + logging.info("Commits in upstream PR:\n %s", ", ".join(upstream_shas)) |
| 528 | + sync_shas = [uc.sha for uc in upstream_commits] |
| 529 | + logging.info("Commits in sync PR:\n %s", ", ".join(reversed(sync_shas))) |
| 530 | + found = False |
| 531 | + for commit in sync_commits: |
| 532 | + try: |
| 533 | + idx = upstream_shas.index(commit.sha) |
| 534 | + found = True |
| 535 | + upstream_commit = upstream_commits[idx] |
| 536 | + break |
| 537 | + except ValueError: |
| 538 | + continue |
| 539 | + |
| 540 | + if not found: |
| 541 | + logging.info( |
| 542 | + "There's no same commits in upstream and sync PRs, probably force-push" |
| 543 | + ) |
| 544 | + return |
| 545 | + |
| 546 | + sync_status = get_status(mergeable_status.state) |
| 547 | + logging.info( |
| 548 | + "Using commit %s to post the %s status `%s`: [%s]", |
| 549 | + upstream_commit.sha, |
| 550 | + sync_status, |
| 551 | + StatusNames.SYNC, |
| 552 | + mergeable_status.description, |
| 553 | + ) |
| 554 | + post_commit_status( |
| 555 | + upstream_commit, |
| 556 | + sync_status, |
| 557 | + "", # let's won't expose any urls from cloud |
| 558 | + mergeable_status.description, |
| 559 | + StatusNames.SYNC, |
| 560 | + ) |
| 561 | + trigger_mergeable_check( |
| 562 | + upstream_commit, |
| 563 | + get_commit_filtered_statuses(upstream_commit), |
| 564 | + True, |
| 565 | + ) |
0 commit comments