Infer branch name from project name
All checks were successful
infra/updatebot/pipeline/head This commit looks good

Since `updatebot` now processes multiple projects in a single run, it no
longer makes sense to have the branch name specified as a command-line
argument.  A unique name is needed for each project, in order to create
separate pull requests for each.  Thus, we have to infer the branch name
from the project name.
This commit is contained in:
2024-09-08 10:43:15 -05:00
parent e138f25f3e
commit 6f3ceaba66

View File

@@ -268,7 +268,6 @@ class Config(pydantic.BaseModel):
class Arguments:
config: Path
branch_name: str
dry_run: bool
projects: list[str]
@@ -304,7 +303,6 @@ def parse_args() -> Arguments:
type=Path,
default=XDG_CONFIG_HOME / 'updatebot' / 'config.toml',
)
parser.add_argument('--branch-name', '-b', default='updatebot')
parser.add_argument('--dry-run', '-n', action='store_true', default=False)
parser.add_argument('projects', metavar='project', nargs='*', default=[])
return parser.parse_args(namespace=Arguments())
@@ -351,8 +349,9 @@ def main() -> None:
repo_url = config.repo.get_git_url()
repo = git.Repo.clone_from(repo_url, d, depth=1, b=config.repo.branch)
for project in config.projects:
log.debug('Checking out new branch: %s', args.branch_name)
repo.heads[0].checkout(force=True, B=args.branch_name)
branch_name = f'updatebot/{project.name}'
log.debug('Checking out new branch: %s', branch_name)
repo.heads[0].checkout(force=True, B=branch_name)
title = None
description = None
if project.name not in projects:
@@ -370,20 +369,20 @@ def main() -> None:
if not args.dry_run:
repo.head.reference.set_tracking_branch(
git.RemoteReference(
repo, f'refs/remotes/origin/{args.branch_name}'
repo, f'refs/remotes/origin/{branch_name}'
)
)
repo.remote().push(force=True)
config.repo.create_pr(
title,
args.branch_name,
branch_name,
config.repo.branch,
description,
)
else:
print(
'Would create PR',
f'{args.branch_name}{config.repo.branch}:',
f'{branch_name}{config.repo.branch}:',
title,
)
print(description or '')