Skip to content

Commit acae60b

Browse files
authored
Merge pull request ClickHouse#63543 from ClickHouse/find-proper-commit-for-a-sync
Find a proper commit for cumulative `A Sync` status
2 parents 83d8c10 + 38604eb commit acae60b

File tree

2 files changed

+71
-20
lines changed

2 files changed

+71
-20
lines changed

tests/ci/ci.py

Lines changed: 7 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,10 @@
3232
RerunHelper,
3333
format_description,
3434
get_commit,
35-
get_commit_filtered_statuses,
3635
post_commit_status,
3736
set_status_comment,
38-
trigger_mergeable_check,
3937
update_mergeable_check,
38+
update_upstream_sync_status,
4039
)
4140
from digest_helper import DockerDigester, JobDigester
4241
from env_helper import (
@@ -55,7 +54,7 @@
5554
from git_helper import Runner as GitRunner
5655
from github_helper import GitHub
5756
from pr_info import PRInfo
58-
from report import ERROR, SUCCESS, BuildResult, JobReport, get_status
57+
from report import ERROR, SUCCESS, BuildResult, JobReport
5958
from s3_helper import S3Helper
6059
from synchronizer_utils import SYNC_BRANCH_PREFIX
6160
from version_helper import get_version_from_repo
@@ -2204,30 +2203,19 @@ def main() -> int:
22042203
and mergeable_status
22052204
and GITHUB_REPOSITORY != GITHUB_UPSTREAM_REPOSITORY
22062205
):
2207-
pr_number = int(pr_info.head_ref.split("/pr/", maxsplit=1)[1])
2208-
upstream_repo = gh.get_repo(GITHUB_UPSTREAM_REPOSITORY)
2209-
head_sha = upstream_repo.get_pull(pr_number).head.sha
2210-
upstream_commit = upstream_repo.get_commit(head_sha)
2211-
post_commit_status(
2212-
upstream_commit,
2213-
get_status(mergeable_status.state),
2214-
"", # let's won't expose any urls from cloud
2215-
mergeable_status.description,
2216-
StatusNames.SYNC,
2206+
upstream_pr_number = int(
2207+
pr_info.head_ref.split("/pr/", maxsplit=1)[1]
22172208
)
2218-
trigger_mergeable_check(
2219-
upstream_commit,
2220-
get_commit_filtered_statuses(upstream_commit),
2221-
True,
2209+
update_upstream_sync_status(
2210+
upstream_pr_number, pr_info.number, gh, mergeable_status
22222211
)
2223-
22242212
prepared_events = prepare_tests_results_for_clickhouse(
22252213
pr_info,
22262214
[],
22272215
job_report.status,
22282216
0,
22292217
job_report.start_time,
2230-
f"https://github.com/ClickHouse/ClickHouse/pull/{pr_number}",
2218+
f"https://github.com/ClickHouse/ClickHouse/pull/{upstream_pr_number}",
22312219
StatusNames.SYNC,
22322220
)
22332221
prepared_events[0]["test_context_raw"] = args.job_name

tests/ci/commit_status_helper.py

Lines changed: 64 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,12 @@
1818
from github.Repository import Repository
1919

2020
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+
)
2227
from lambda_shared_package.lambda_shared.pr import Labels
2328
from pr_info import PRInfo
2429
from report import (
@@ -29,6 +34,7 @@
2934
StatusType,
3035
TestResult,
3136
TestResults,
37+
get_status,
3238
get_worst_status,
3339
)
3440
from s3_helper import S3Helper
@@ -500,3 +506,60 @@ def trigger_mergeable_check(
500506
return set_mergeable_check(commit, description, state, hide_url)
501507

502508
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

Comments
 (0)