From e412a780fc62e7ae4c20d66eb36cc1e0d3f03f59 Mon Sep 17 00:00:00 2001 From: Maxwell G Date: Jul 10 2022 04:01:01 +0000 Subject: [PATCH 1/6] Fix typo in the README --- diff --git a/README.md b/README.md index 5117ae5..042eaec 100644 --- a/README.md +++ b/README.md @@ -9,7 +9,7 @@ Add your dist-git and Anitya to the configuration file in `~/.config/fedora-sig- ``` [api] dist_git_token = YOUR_DIST_GIT_TOKEN_HERE -anitya_token = YOUR_ANITYA_TOKEN_HERE +antiya_token = YOUR_ANITYA_TOKEN_HERE ``` To onboard a package: From 833bdccbf8ee1620a073fcf8d6bb9b542bbd95b1 Mon Sep 17 00:00:00 2001 From: Maxwell G Date: Jul 10 2022 04:04:38 +0000 Subject: [PATCH 2/6] Add installation instructions This adds instructions to install the package via pip, in addition to fixing an `import` and missing dependency that currently prevent that from happening. --- diff --git a/README.md b/README.md index 042eaec..a7e5321 100644 --- a/README.md +++ b/README.md @@ -2,6 +2,11 @@ `fedora-sig-onboard` is a simple tool to onboard a Fedora package onto the relevant SIG. It will attempt to add the SIG to the package ACL, update the bugzilla assignee and add the package to [Anitya](https://release-monitoring.org). Rust and Golang packages are currently supported, and will be respectively onboarded onto the [Rust SIG](https://fedoraproject.org/wiki/SIGs/Rust) and the [Go SIG](https://fedoraproject.org/wiki/SIGs/Go). +# Installation +``` console +pip install 'git+https://pagure.io/fedora-sig-onboard.git' +``` + ## Usage Add your dist-git and Anitya to the configuration file in `~/.config/fedora-sig-onboard/fedora-sig-onboard.conf`: diff --git a/fedora_sig_onboard/cli.py b/fedora_sig_onboard/cli.py index 305bf62..48193a1 100755 --- a/fedora_sig_onboard/cli.py +++ b/fedora_sig_onboard/cli.py @@ -9,7 +9,7 @@ import sys import click from xdg import BaseDirectory -from onboarder import Onboarder +from .onboarder import Onboarder def fail(msg, retcode=1): diff --git a/setup.cfg b/setup.cfg index 7a4d4c9..ed5b5cb 100644 --- a/setup.cfg +++ b/setup.cfg @@ -16,6 +16,7 @@ classifiers = install_requires = click pyxdg + requests python_requires = >=3.9 [options.entry_points] From 71de7ca361d44f77d032631c3f54d343303ce619 Mon Sep 17 00:00:00 2001 From: Maxwell G Date: Jul 10 2022 04:19:27 +0000 Subject: [PATCH 3/6] Remove shebang and executable bit from cli.py Use `python3 -m fedora_sig_onboard.cli` or `pip install -e .`, instead of executing the file. Removing the shebang allows venv installs to work properly and makes it easier to package this in Fedora (if you ever decide to do that). The relative import added in the previous commit doesn't work properly when invoked directly, anyways. --- diff --git a/fedora_sig_onboard/cli.py b/fedora_sig_onboard/cli.py old mode 100755 new mode 100644 index 48193a1..bfae5aa --- a/fedora_sig_onboard/cli.py +++ b/fedora_sig_onboard/cli.py @@ -1,5 +1,3 @@ -#!/usr/bin/env python3 -# # SPDX-License-Identifier: MIT from pathlib import Path From b02bbdf78aea1c97cd0535d68e812317463ee4c5 Mon Sep 17 00:00:00 2001 From: Maxwell G Date: Jul 10 2022 04:39:43 +0000 Subject: [PATCH 4/6] Raise ClickException's instead of generic ones ClickException prints a clean error message instead of flooding users' terminals with tracebacks --- diff --git a/fedora_sig_onboard/onboarder.py b/fedora_sig_onboard/onboarder.py index b1787bc..2a5678d 100644 --- a/fedora_sig_onboard/onboarder.py +++ b/fedora_sig_onboard/onboarder.py @@ -2,6 +2,9 @@ from pathlib import Path import configparser + +from click import ClickException + import requests DIST_GIT = "src.fedoraproject.org" @@ -11,7 +14,7 @@ BZOVERRIDES_URL = f"https://{DIST_GIT}/_dg/bzoverrides/" ANITYA_URL = "https://release-monitoring.org/api/v2/" -class OnboarderException(Exception): +class OnboarderException(ClickException): pass From 2ecda93a527426e977217f04fac040eb2e1a813a Mon Sep 17 00:00:00 2001 From: Maxwell G Date: Jul 10 2022 04:39:47 +0000 Subject: [PATCH 5/6] Add --acl option. --- diff --git a/fedora_sig_onboard/cli.py b/fedora_sig_onboard/cli.py index bfae5aa..a8cd43c 100644 --- a/fedora_sig_onboard/cli.py +++ b/fedora_sig_onboard/cli.py @@ -42,9 +42,16 @@ pass_onboarder = click.make_pass_decorator(Onboarder, ensure=True) @cli.command() @click.option("-g", "--group", help="Group ACL to add") +@click.option( + "-a", + "--acl", + help="Which ACL to give the SIG's group", + default="commit", + type=click.Choice(["commit", "admin"]), +) @click.argument("package", required=False, nargs=-1) @pass_onboarder -def onboard(onboarder, group, package): +def onboard(onboarder, group, acl, package): if not package: package = [Path(os.getcwd()).name] @@ -62,7 +69,7 @@ def onboard(onboarder, group, package): fail(f"Could not determine group for {p}") click.echo(f"[{p}] updating ACL") - onboarder.add_package_acl(p, group, "commit") + onboarder.add_package_acl(p, group, acl) click.echo(f"[{p}] updating bugzilla assignees") onboarder.set_bugzilla_assignee(p, group) click.echo(f"[{p}] adding to anitya") From a4945088d78e0b8db9d937cf5a741bca8100341b Mon Sep 17 00:00:00 2001 From: Maxwell G Date: Jul 10 2022 04:47:38 +0000 Subject: [PATCH 6/6] Onboarder: Import better error handling and fallback This commit includes some better error handling so that the script fails more cleanly if configuration keys are missing. It also adds the ability to fallback to fedpkg's config file for the distgit API token. For users who use `fedpkg fork` or other fedpkg features that require a distgit API token, it's helpful not to have to copy the token to two different places. --- diff --git a/fedora_sig_onboard/onboarder.py b/fedora_sig_onboard/onboarder.py index 2a5678d..8a753da 100644 --- a/fedora_sig_onboard/onboarder.py +++ b/fedora_sig_onboard/onboarder.py @@ -3,7 +3,7 @@ from pathlib import Path import configparser -from click import ClickException +from click import ClickException, echo import requests @@ -26,21 +26,32 @@ class Onboarder: else: raise OnboarderException(f"Invalid or missing config: {config}") - self.dist_git_token = None - self.anitya_token = None - for section in self.config.sections(): - if section == "api": - options = self.config[section] - if "dist_git_token" in options: - self.dist_git_token = options["dist_git_token"] - if "anitya_token" in options: - self.anitya_token = options["anitya_token"] - - if self.dist_git_token == None: - raise OnboarderException(f"dist_git_token not defined in {config}") - - if self.anitya_token == None: - raise OnboarderException(f"anitya_token not defined in {config}") + try: + api_config = self.config["api"] + self.antiya_token = api_config["antiya_token"] + self.dist_git_token = api_config.get("dist_git_token", None) + except KeyError: + raise OnboarderException(f"anitya_token not defined in {config}") from None + + # Fallback to fedpkg_config is dist_git_token is not defined in the config. + fedpkg_config_path = Path.home() / ".config/rpkg/fedpkg.conf" + if self.dist_git_token is None and fedpkg_config_path.exists(): + try: + echo( + f"api.dist_git_token is not defined in {config}. " + + "Falling back to fedpkg config file" + ) + self.fedpkg_config = configparser.ConfigParser() + self.fedpkg_config.read(fedpkg_config_path) + self.dist_git_token = self.fedpkg_config.get("fedpkg.distgit", "token") + except (configparser.NoSectionError, configparser.NoOptionError): + raise OnboarderException( + f"A distgit token was not found in {config} or {fedpkg_config_path}" + ) from None + + # Fail if dist_git_token was not defined in either of the two places + if getattr(self, "dist_git_token", None) is None: + raise OnboarderException(f"api.dist_git_token not defined in {config}") def get_anitya_project(self, package, ecosystem=None): project = package