Skip to content

Commit

Permalink
./github/scripts/auto-backport.py: use scylladbbot fork for backpor…
Browse files Browse the repository at this point in the history
…t PRs

It seems that we can't push branches to the developer's fork due to permission issues (I managed to get it working during my verification, but maybe it was because I was testing it under my user)

Since all Dev team members in Github have Triage permissions, they can't update branches under the scylladb organization, Instead, I have added write permission on `scyllaadbbot` fork to provide access to all dev
This will allow everyone to update the backport branches directly when conflicts apply and in general

(cherry picked from commit f6c5d28)
  • Loading branch information
yaronkaikov committed Nov 24, 2024
1 parent 1c24567 commit 0e60457
Showing 1 changed file with 13 additions and 27 deletions.
40 changes: 13 additions & 27 deletions .github/scripts/auto-backport.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,18 +37,17 @@ def create_pull_request(repo, new_branch_name, base_branch_name, pr, backport_pr
for commit in commits:
pr_body += f'- (cherry picked from commit {commit})\n\n'
pr_body += f'Parent PR: #{pr.number}'
if is_draft:
new_branch_name = f'{pr.user.login}:{new_branch_name}'
try:
backport_pr = repo.create_pull(
title=backport_pr_title,
body=pr_body,
head=new_branch_name,
head=f'scylladbbot:{new_branch_name}',
base=base_branch_name,
draft=is_draft
)
logging.info(f"Pull request created: {backport_pr.html_url}")
backport_pr.add_to_assignees(pr.user)
backport_pr.add_to_labels("conflicts") if is_draft else None
logging.info(f"Assigned PR to original author: {pr.user}")
return backport_pr
except GithubException as e:
Expand Down Expand Up @@ -88,28 +87,25 @@ def get_pr_commits(repo, pr, stable_branch, start_commit=None):
return commits


def backport(repo, pr, version, commits, backport_base_branch, user):
def backport(repo, pr, version, commits, backport_base_branch):
new_branch_name = f'backport/{pr.number}/to-{version}'
backport_pr_title = f'[Backport {version}] {pr.title}'
repo_url = f'https://scylladbbot:{github_token}@github.com/{repo.full_name}.git'
fork_repo = f'https://scylladbbot:{github_token}@github.com/scylladbbot/{repo.name}.git'
with (tempfile.TemporaryDirectory() as local_repo_path):
try:
new_branch_name = f'backport/{pr.number}/to-{version}'
backport_pr_title = f'[Backport {version}] {pr.title}'
repo_local = Repo.clone_from(f'https://{user.login}:{github_token}@github.com/{repo.full_name}.git', local_repo_path, branch=backport_base_branch)
repo_local = Repo.clone_from(repo_url, local_repo_path, branch=backport_base_branch)
repo_local.git.checkout(b=new_branch_name)
fork_repo = pr.user.get_repo(repo.full_name.split('/')[1])
fork_repo_url = f'https://{user.login}:{github_token}@github.com/{fork_repo.full_name}.git'
repo_local.create_remote('fork', fork_repo_url)
remote = 'origin'
is_draft = False
for commit in commits:
try:
repo_local.git.cherry_pick(commit, '-m1', '-x')
except GitCommandError as e:
logging.warning(f'Cherry-pick conflict on commit {commit}: {e}')
remote = 'fork'
is_draft = True
repo_local.git.add(A=True)
repo_local.git.cherry_pick('--continue')
repo_local.git.push(remote, new_branch_name, force=True)
repo_local.git.push(fork_repo, new_branch_name, force=True)
create_pull_request(repo, new_branch_name, backport_base_branch, pr, backport_pr_title, commits,
is_draft=is_draft)
except GitCommandError as e:
Expand All @@ -121,25 +117,15 @@ def main():
base_branch = args.base_branch.split('/')[2]
promoted_label = 'promoted-to-master'
repo_name = args.repo
if 'scylla-enterprise' in args.repo:
if 'scylla-enterprise-machine-image' in args.repo:
promoted_label = 'promoted-to-enterprise'
if args.repo in ('scylladb/scylla', 'scylladb/scylla-enterprise'):
stable_branch = base_branch
backport_branch = 'branch-'
else:
backport_branch = 'next-'
if base_branch in ('master', 'next'):
stable_branch = 'master'
elif base_branch in ('enterprise', 'next-enterprise'):
stable_branch = 'enterprise'
else:
stable_branch = base_branch.replace('next', 'branch')

backport_branch = 'next-'
stable_branch = 'master' if base_branch == 'next' else 'enterprise' if base_branch == 'next-enterprise' else base_branch.replace('next', 'branch')
backport_label_pattern = re.compile(r'backport/\d+\.\d+$')

g = Github(github_token)
repo = g.get_repo(repo_name)
user = g.get_user()
closed_prs = []
start_commit = None

Expand Down Expand Up @@ -168,7 +154,7 @@ def main():
for backport_label in backport_labels:
version = backport_label.replace('backport/', '')
backport_base_branch = backport_label.replace('backport/', backport_branch)
backport(repo, pr, version, commits, backport_base_branch, user)
backport(repo, pr, version, commits, backport_base_branch)


if __name__ == "__main__":
Expand Down

0 comments on commit 0e60457

Please sign in to comment.