Skip to content

Commit

Permalink
Don't request metadata uselessly
Browse files Browse the repository at this point in the history
  • Loading branch information
fcollonval committed Sep 18, 2023
1 parent b6b9d60 commit 6dc07a2
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 18 deletions.
1 change: 0 additions & 1 deletion jupyter_releaser/changelog.py
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,6 @@ def remove_placeholder_entries(

version = _extract_version(changelog[start + len(START_SILENT_MARKER) : end])
release = gh.repos.get_release_by_tag(owner=owner, repo=repo_name, tag=f"v{version}")
print(release)
if not release.draft:
changelog_text = mdformat.text(release.body)
changelog = changelog[:start] + f"\n\n{changelog_text}\n\n" + changelog[end + 1 :]
Expand Down
8 changes: 6 additions & 2 deletions jupyter_releaser/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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()
Expand All @@ -561,6 +563,7 @@ def populate_release(
release_url,
post_version_spec,
post_version_message,
silent,
assets,
):
"""Populate a release."""
Expand All @@ -577,6 +580,7 @@ def populate_release(
post_version_spec,
post_version_message,
assets,
silent,
)


Expand Down
14 changes: 2 additions & 12 deletions jupyter_releaser/lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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:]}")
Expand Down Expand Up @@ -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
Expand All @@ -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)

Expand Down
4 changes: 1 addition & 3 deletions jupyter_releaser/mock_github.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down

0 comments on commit 6dc07a2

Please sign in to comment.