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