mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-10 09:32:06 +00:00
Merge pull request #62488 from ClickHouse/ci_auto_sync_pr_merge
CI: merge sync pr on push to master
This commit is contained in:
commit
4a7450ed2e
4
.github/workflows/master.yml
vendored
4
.github/workflows/master.yml
vendored
@ -23,6 +23,10 @@ jobs:
|
||||
clear-repository: true # to ensure correct digests
|
||||
fetch-depth: 0 # to get version
|
||||
filter: tree:0
|
||||
- name: Check sync PR
|
||||
run: |
|
||||
cd "$GITHUB_WORKSPACE/tests/ci"
|
||||
python3 sync_pr.py || :
|
||||
- name: Python unit tests
|
||||
run: |
|
||||
cd "$GITHUB_WORKSPACE/tests/ci"
|
||||
|
@ -199,7 +199,6 @@ class PRInfo:
|
||||
EventType.MERGE_QUEUE in github_event
|
||||
): # pull request and other similar events
|
||||
self.event_type = EventType.MERGE_QUEUE
|
||||
# FIXME: need pr? we can parse it from ["head_ref": "refs/heads/gh-readonly-queue/test-merge-queue/pr-6751-4690229995a155e771c52e95fbd446d219c069bf"]
|
||||
self.number = 0
|
||||
self.sha = github_event[EventType.MERGE_QUEUE]["head_sha"]
|
||||
self.base_ref = github_event[EventType.MERGE_QUEUE]["base_ref"]
|
||||
@ -208,6 +207,8 @@ class PRInfo:
|
||||
self.base_name = github_event["repository"]["full_name"]
|
||||
# any_branch-name - the name of working branch name
|
||||
self.head_ref = github_event[EventType.MERGE_QUEUE]["head_ref"]
|
||||
# parse underlying pr from ["head_ref": "refs/heads/gh-readonly-queue/test-merge-queue/pr-6751-4690229995a155e771c52e95fbd446d219c069bf"]
|
||||
self.merged_pr = int(self.head_ref.split("/pr-")[-1].split("-")[0])
|
||||
# UserName/ClickHouse or ClickHouse/ClickHouse
|
||||
self.head_name = self.base_name
|
||||
self.user_login = github_event["sender"]["login"]
|
||||
@ -235,6 +236,8 @@ class PRInfo:
|
||||
if pull_request is None or pull_request["state"] == "closed":
|
||||
# it's merged PR to master
|
||||
self.number = 0
|
||||
if pull_request:
|
||||
self.merged_pr = pull_request["number"]
|
||||
self.labels = set()
|
||||
self.pr_html_url = f"{repo_prefix}/commits/{ref}"
|
||||
self.base_ref = ref
|
||||
|
46
tests/ci/sync_pr.py
Normal file
46
tests/ci/sync_pr.py
Normal file
@ -0,0 +1,46 @@
|
||||
#!/usr/bin/env python
|
||||
|
||||
"""Script for automatic sync PRs handling in private repos"""
|
||||
|
||||
import sys
|
||||
|
||||
from get_robot_token import get_best_robot_token
|
||||
from pr_info import PRInfo
|
||||
from github_helper import GitHub
|
||||
|
||||
|
||||
def main():
|
||||
gh = GitHub(get_best_robot_token())
|
||||
|
||||
pr_info = PRInfo()
|
||||
assert pr_info.merged_pr, "BUG. merged PR number could not been determined"
|
||||
|
||||
prs = gh.get_pulls_from_search(
|
||||
query=f"head:sync-upstream/pr/{pr_info.merged_pr} org:ClickHouse type:pr",
|
||||
repo="ClickHouse/clickhouse-private",
|
||||
)
|
||||
if len(prs) > 1:
|
||||
print(f"WARNING: More than one PR found [{prs}] - exiting")
|
||||
sys.exit(0)
|
||||
if len(prs) == 0:
|
||||
print("WARNING: No Sync PR found")
|
||||
sys.exit(0)
|
||||
|
||||
pr = prs[0]
|
||||
|
||||
if pr.state == "closed":
|
||||
print(f"Sync PR [{pr.number}] already closed - exiting")
|
||||
sys.exit(0)
|
||||
|
||||
if pr.state != "open":
|
||||
print(f"WARNING: Unknown Sync PR [{pr.number}] state [{pr.state}] - exiting")
|
||||
sys.exit(0)
|
||||
|
||||
print(f"Trying to merge Sync PR [{pr.number}]")
|
||||
if pr.draft:
|
||||
gh.toggle_pr_draft(pr)
|
||||
pr.merge()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
Loading…
Reference in New Issue
Block a user