From 68c420004071bc6666867dad118bc2138abe4df9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Collonval?= Date: Mon, 18 Sep 2023 16:13:18 +0200 Subject: [PATCH] Don't request metadata uselessly --- jupyter_releaser/cli.py | 8 ++++++-- jupyter_releaser/lib.py | 14 ++------------ jupyter_releaser/mock_github.py | 4 +--- 3 files changed, 9 insertions(+), 17 deletions(-) diff --git a/jupyter_releaser/cli.py b/jupyter_releaser/cli.py index ed8c1d0a..f97d8615 100644 --- a/jupyter_releaser/cli.py +++ b/jupyter_releaser/cli.py @@ -379,10 +379,11 @@ def bump_version(version_spec, version_cmd, changelog_path, python_packages): @add_options(auth_options) @add_options(changelog_path_options) @add_options(release_url_options) +@add_options(silent_option) @use_checkout_dir() -def extract_changelog(dry_run, auth, changelog_path, release_url): +def extract_changelog(dry_run, auth, changelog_path, release_url, silent): """Extract the changelog entry.""" - lib.extract_changelog(dry_run, auth, changelog_path, release_url) + lib.extract_changelog(dry_run, auth, changelog_path, release_url, silent) @main.command() @@ -546,6 +547,7 @@ def tag_release(dist_dir, release_message, tag_format, tag_message, no_git_tag_w @add_options(dist_dir_options) @add_options(dry_run_options) @add_options(release_url_options) +@add_options(silent_option) @add_options(post_version_spec_options) @click.argument("assets", nargs=-1) @use_checkout_dir() @@ -561,6 +563,7 @@ def populate_release( release_url, post_version_spec, post_version_message, + silent, assets, ): """Populate a release.""" @@ -577,6 +580,7 @@ def populate_release( post_version_spec, post_version_message, assets, + silent, ) diff --git a/jupyter_releaser/lib.py b/jupyter_releaser/lib.py index 9819bd7b..e61c5830 100644 --- a/jupyter_releaser/lib.py +++ b/jupyter_releaser/lib.py @@ -231,6 +231,7 @@ def populate_release( post_version_spec, post_version_message, assets, + silent=False, ): """Populate release assets and push tags and commits""" branch = branch or util.get_branch() @@ -251,13 +252,6 @@ def populate_release( release = util.release_for_url(gh, release_url) # if the release is silent, the changelog source of truth is the GitHub release - util.log(f"Assets {assets}") - silent = False - for asset in assets: - asset_path = Path(asset) - if asset_path.name == util.METADATA_JSON.name: - metadata = json.loads(asset_path.read_text(encoding="utf-8")) - silent = metadata.get("silent", False) body = release.body if silent else changelog.extract_current(changelog_path) util.log(f"release is silent: {silent}") util.log(f"populate-release release.body: {release.body[100:]}") @@ -550,7 +544,7 @@ def prep_git(ref, branch, repo, auth, username, url): # noqa return branch -def extract_changelog(dry_run, auth, changelog_path, release_url): +def extract_changelog(dry_run, auth, changelog_path, release_url, silent=False): """Extract the changelog from the draft GH release body and update it. > If the release must is silent, the changelog entry will be replaced by @@ -560,10 +554,6 @@ def extract_changelog(dry_run, auth, changelog_path, release_url): gh = util.get_gh_object(dry_run=dry_run, owner=match["owner"], repo=match["repo"], token=auth) release = util.release_for_url(gh, release_url) - # Check for silent status here to avoid request to often the GitHub API - metadata = util.extract_metadata_from_release_url(gh, release.html_url, auth) - silent = metadata.get("silent", False) - changelog_text = mdformat.text(release.body) changelog.update_changelog(changelog_path, changelog_text, silent=silent) diff --git a/jupyter_releaser/mock_github.py b/jupyter_releaser/mock_github.py index 07f17674..6a0e7ca2 100644 --- a/jupyter_releaser/mock_github.py +++ b/jupyter_releaser/mock_github.py @@ -148,9 +148,7 @@ def list_releases(owner: str, repo: str) -> List[Release]: @app.get("/repos/{owner}/{repo}/releases/tags/{tag}") def get_release_by_tag(owner: str, repo: str, tag: str) -> Release: """https://docs.github.com/en/rest/releases/releases#get-a-release-by-tag-name""" - r = next(filter(lambda r: r.tag_name == tag, releases.values())) - print(r) - return r + return next(filter(lambda r: r.tag_name == tag, releases.values())) @app.post("/repos/{owner}/{repo}/releases")