From a8de6dab1c6a0ea2ac1388cb7015eca7f353ab23 Mon Sep 17 00:00:00 2001 From: Miro Hrončok Date: Oct 14 2020 14:04:28 +0000 Subject: [PATCH 1/2] distgit-branch-unused: When another name is used, keep checking Signed-off-by: Miro Hrončok --- diff --git a/scripts/distgit-branch-unused.py b/scripts/distgit-branch-unused.py index 9065ff9..4aa4fc8 100755 --- a/scripts/distgit-branch-unused.py +++ b/scripts/distgit-branch-unused.py @@ -81,7 +81,13 @@ def find_hash(build): def list_builds(package, opts): session, koji = koji_session(opts) - pkg = session.getPackageID(package, strict=True) + try: + pkg = session.getPackageID(package, strict=True) + except koji.GenericError as e: + if 'Invalid package name' in str(e): + return {} + else: + raise builds = session.listBuilds(packageID=pkg, state=koji.BUILD_STATES['COMPLETE']) with session.multicall(strict=True) as msession: @@ -187,7 +193,7 @@ def branch_is_reachable(opts): return 0 print('Branch has commits not found anywhere else. Looking for builds.') - builds = list_builds(opts.package, opts) + builds = {opts.package: list_builds(opts.package, opts)} for n, commit in enumerate(repo.walk(branch.target, pygit2.GIT_SORT_TOPOLOGICAL)): subj = commit.message.splitlines()[0][:60] @@ -208,16 +214,17 @@ def branch_is_reachable(opts): real_name = name_in_spec_file(commit, opts.package) except UnicodeDecodeError: return 1 - if real_name is not None and real_name != opts.package: - print(f"Sorry, {commit.hex} has Name: {real_name}, refusing to continue.") - return 1 - - built = builds.get(commit.hex, None) - if built: - print(f"Sorry, {commit.hex} built as {built['nvr']}.") - koji_link = f"https://koji.fedoraproject.org/koji/taskinfo?taskID={built['task_id']}" - print(f"See {koji_link}.") - return 1 + if real_name is not None and real_name not in builds: + print(f"{commit.hex} has Name: {real_name}. Looking for builds.") + builds[real_name] = list_builds(real_name, opts) + + for name in builds: + built = builds[name].get(commit.hex, None) + if built: + print(f"Sorry, {commit.hex} built as {built['nvr']}.") + koji_link = f"https://koji.fedoraproject.org/koji/taskinfo?taskID={built['task_id']}" + print(f"See {koji_link}.") + return 1 print('No builds found, seems OK to delete.') return 0 From 395fed9c4feeba9f32fd2d6046c7b9e31746a995 Mon Sep 17 00:00:00 2001 From: Miro Hrončok Date: Oct 14 2020 14:04:28 +0000 Subject: [PATCH 2/2] distgit-branch-unused: Also consider other spec files See for example https://pagure.io/releng/issue/7523 Signed-off-by: Miro Hrončok --- diff --git a/scripts/distgit-branch-unused.py b/scripts/distgit-branch-unused.py index 4aa4fc8..c5ff4e4 100755 --- a/scripts/distgit-branch-unused.py +++ b/scripts/distgit-branch-unused.py @@ -134,8 +134,19 @@ def name_in_spec_file(commit, package): try: spec = (commit.tree / f'{package}.spec').data except KeyError: - print(f"Commit {commit.hex} doesn't have '{package}.spec', assuming package is unbuildable.") - return None + print(f"Commit {commit.hex} doesn't have '{package}.spec', looking for other specs.") + specs = set() + for candidate in commit.tree: + if candidate.name.endswith(".spec"): + specs.add(candidate) + print(f"Found '{candidate.name}'.") + if not specs: + print(f"Commit {commit.hex} doesn't have '*.spec', assuming package is unbuildable.") + return None + if len(specs) > 1: + msg = f"Commit {commit.hex} has multiple '*.spec' files, aborting." + raise NotImplementedError(msg) + spec = specs.pop().data # We don't try to decode the whole spec file here, to reduce the chances of trouble. # Just any interesting lines.