Merge pull request #23363 from abyss7/backport-by-label

Use 'release' label from PRs
This commit is contained in:
alexey-milovidov 2021-04-21 16:17:13 +03:00 committed by GitHub
commit 3604aa92f8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -25,24 +25,23 @@ class Backport:
def getPullRequests(self, from_commit): def getPullRequests(self, from_commit):
return self._gh.get_pull_requests(from_commit) return self._gh.get_pull_requests(from_commit)
def getBranchesWithLTS(self): def getBranchesWithRelease(self):
branches = [] branches = set()
for pull_request in self._gh.find_pull_requests("release-lts"): for pull_request in self._gh.find_pull_requests("release"):
if not pull_request['merged'] and not pull_request['closed']: if not pull_request['merged'] and not pull_request['closed']:
branches.append(pull_request['headRefName']) branches.add(pull_request['headRefName'])
return branches return branches
def execute(self, repo, upstream, until_commit, number, run_cherrypick, find_lts=False): def execute(self, repo, upstream, until_commit, run_cherrypick):
repo = LocalRepo(repo, upstream, self.default_branch_name) repo = LocalRepo(repo, upstream, self.default_branch_name)
all_branches = repo.get_release_branches() # [(branch_name, base_commit)] all_branches = repo.get_release_branches() # [(branch_name, base_commit)]
last_branches = set([branch[0] for branch in all_branches[-number:]]) release_branches = self.getBranchesWithRelease()
lts_branches = set(self.getBranchesWithLTS() if find_lts else [])
branches = [] branches = []
# iterate over all branches to preserve their precedence. # iterate over all branches to preserve their precedence.
for branch in all_branches: for branch in all_branches:
if branch[0] in last_branches or branch[0] in lts_branches: if branch[0] in release_branches:
branches.append(branch) branches.append(branch)
if not branches: if not branches:
@ -115,8 +114,6 @@ if __name__ == "__main__":
parser.add_argument('--token', type=str, required=True, help='token for Github access') parser.add_argument('--token', type=str, required=True, help='token for Github access')
parser.add_argument('--repo', type=str, required=True, help='path to full repository', metavar='PATH') parser.add_argument('--repo', type=str, required=True, help='path to full repository', metavar='PATH')
parser.add_argument('--til', type=str, help='check PRs from HEAD til this commit', metavar='COMMIT') parser.add_argument('--til', type=str, help='check PRs from HEAD til this commit', metavar='COMMIT')
parser.add_argument('-n', type=int, dest='number', help='number of last release branches to consider')
parser.add_argument('--lts', action='store_true', help='consider branches with LTS')
parser.add_argument('--dry-run', action='store_true', help='do not create or merge any PRs', default=False) parser.add_argument('--dry-run', action='store_true', help='do not create or merge any PRs', default=False)
parser.add_argument('--verbose', '-v', action='store_true', help='more verbose output', default=False) parser.add_argument('--verbose', '-v', action='store_true', help='more verbose output', default=False)
parser.add_argument('--upstream', '-u', type=str, help='remote name of upstream in repository', default='origin') parser.add_argument('--upstream', '-u', type=str, help='remote name of upstream in repository', default='origin')
@ -129,4 +126,4 @@ if __name__ == "__main__":
cherrypick_run = lambda token, pr, branch: CherryPick(token, 'ClickHouse', 'ClickHouse', 'core', pr, branch).execute(args.repo, args.dry_run) cherrypick_run = lambda token, pr, branch: CherryPick(token, 'ClickHouse', 'ClickHouse', 'core', pr, branch).execute(args.repo, args.dry_run)
bp = Backport(args.token, 'ClickHouse', 'ClickHouse', 'core') bp = Backport(args.token, 'ClickHouse', 'ClickHouse', 'core')
bp.execute(args.repo, args.upstream, args.til, args.number, cherrypick_run, args.lts) bp.execute(args.repo, args.upstream, args.til, cherrypick_run)