Update scripts (#12726)

This commit is contained in:
Ivan 2020-07-27 13:05:38 +03:00 committed by GitHub
parent 79a7c9c3f0
commit 1e10ce6bcf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 8 deletions

View File

@ -12,7 +12,7 @@ import sys
class Backport: class Backport:
def __init__(self, token, owner, name, team): def __init__(self, token, owner, name, team):
self._gh = RemoteRepo(token, owner=owner, name=name, team=team, max_page_size=30) self._gh = RemoteRepo(token, owner=owner, name=name, team=team, max_page_size=30, min_page_size=7)
self._token = token self._token = token
self.default_branch_name = self._gh.default_branch self.default_branch_name = self._gh.default_branch
self.ssh_url = self._gh.ssh_url self.ssh_url = self._gh.ssh_url
@ -39,12 +39,16 @@ class Backport:
RE_MUST_BACKPORT = re.compile(r'^v(\d+\.\d+)-must-backport$') RE_MUST_BACKPORT = re.compile(r'^v(\d+\.\d+)-must-backport$')
RE_NO_BACKPORT = re.compile(r'^v(\d+\.\d+)-no-backport$') RE_NO_BACKPORT = re.compile(r'^v(\d+\.\d+)-no-backport$')
RE_BACKPORTED = re.compile(r'^v(\d+\.\d+)-backported$')
# pull-requests are sorted by ancestry from the least recent. # pull-requests are sorted by ancestry from the least recent.
for pr in prs: for pr in prs:
while repo.comparator(branches[-1][1]) >= repo.comparator(pr['mergeCommit']['oid']): while repo.comparator(branches[-1][1]) >= repo.comparator(pr['mergeCommit']['oid']):
logging.info("PR #{} is already inside {}. Dropping this branch for futher PRs".format(pr['number'], branches[-1][0]))
branches.pop() branches.pop()
logging.info("Processing PR #{}".format(pr['number']))
assert len(branches) assert len(branches)
branch_set = set([branch[0] for branch in branches]) branch_set = set([branch[0] for branch in branches])
@ -65,14 +69,19 @@ class Backport:
if label['name'] == 'pr-no-backport' and pr['number'] in backport_map: if label['name'] == 'pr-no-backport' and pr['number'] in backport_map:
del backport_map[pr['number']] del backport_map[pr['number']]
break break
m = RE_NO_BACKPORT.match(label['name']) m1 = RE_NO_BACKPORT.match(label['name'])
if m and pr['number'] in backport_map and m.group(1) in backport_map[pr['number']]: m2 = RE_BACKPORTED.match(label['name'])
backport_map[pr['number']].remove(m.group(1)) if m1 and pr['number'] in backport_map and m1.group(1) in backport_map[pr['number']]:
backport_map[pr['number']].remove(m1.group(1))
logging.info('\tskipping %s because of forced no-backport', m1.group(1))
elif m2 and pr['number'] in backport_map and m2.group(1) in backport_map[pr['number']]:
backport_map[pr['number']].remove(m2.group(1))
logging.info('\tskipping %s because it\'s already backported manually', m2.group(1))
for pr, branches in backport_map.items(): for pr, branches in backport_map.items():
logging.info('PR #%s needs to be backported to:', pr) logging.info('PR #%s needs to be backported to:', pr)
for branch in branches: for branch in branches:
logging.info('\t%s %s', branch, run_cherrypick(self._token, pr, branch)) logging.info('\t%s, and the status is: %s', branch, run_cherrypick(self._token, pr, branch))
# print API costs # print API costs
logging.info('\nGitHub API total costs per query:') logging.info('\nGitHub API total costs per query:')

View File

@ -35,7 +35,9 @@ class CherryPick:
MERGED = 'backported' MERGED = 'backported'
def _run(self, args): def _run(self, args):
logging.info(subprocess.check_output(args)) out = subprocess.check_output(args).rstrip()
logging.debug(out)
return out
def __init__(self, token, owner, name, team, pr_number, target_branch): def __init__(self, token, owner, name, team, pr_number, target_branch):
self._gh = RemoteRepo(token, owner=owner, name=name, team=team) self._gh = RemoteRepo(token, owner=owner, name=name, team=team)
@ -117,8 +119,8 @@ class CherryPick:
self._run(git_prefix + ['checkout', '-f', self.backport_branch]) self._run(git_prefix + ['checkout', '-f', self.backport_branch])
self._run(git_prefix + ['pull', '--ff-only', 'origin', self.backport_branch]) self._run(git_prefix + ['pull', '--ff-only', 'origin', self.backport_branch])
self._run(git_prefix + ['reset', '--soft', self._run(git_prefix + ['merge-base', self.target_branch, self.backport_branch])]) self._run(git_prefix + ['reset', '--soft', self._run(git_prefix + ['merge-base', 'origin/' + self.target_branch, self.backport_branch])])
self._run(git_prefix + ['commit', '-a', '-m', pr_title]) self._run(git_prefix + ['commit', '-a', '--allow-empty', '-m', pr_title])
self._run(git_prefix + ['push', '-f', 'origin', '{branch}:{branch}'.format(branch=self.backport_branch)]) self._run(git_prefix + ['push', '-f', 'origin', '{branch}:{branch}'.format(branch=self.backport_branch)])
pr = self._gh.create_pull_request(source=self.backport_branch, target=self.target_branch, title=pr_title, pr = self._gh.create_pull_request(source=self.backport_branch, target=self.target_branch, title=pr_title,