From 74254def447c1ac088a3f752ab87e70170d8dcde Mon Sep 17 00:00:00 2001 From: Jeremy Tuloup Date: Fri, 30 Apr 2021 12:34:57 +0200 Subject: [PATCH 1/3] Allow Check Release to be Run on Fork PRs --- .github/actions/check-release/action.yml | 36 ++------ .github/actions/draft-changelog/action.yml | 1 + .github/actions/draft-release/action.yml | 1 + .github/workflows/check-release.yml | 6 +- jupyter_releaser/actions/publish_release.py | 6 +- jupyter_releaser/changelog.py | 22 +++-- jupyter_releaser/cli.py | 54 +++++++----- jupyter_releaser/lib.py | 97 ++++++++++++--------- jupyter_releaser/tests/test_cli.py | 47 ++++++---- jupyter_releaser/tests/test_functions.py | 23 ++++- 10 files changed, 170 insertions(+), 123 deletions(-) diff --git a/.github/actions/check-release/action.yml b/.github/actions/check-release/action.yml index c0d0995d..32b1e85c 100644 --- a/.github/actions/check-release/action.yml +++ b/.github/actions/check-release/action.yml @@ -23,9 +23,11 @@ runs: export RH_POST_VERSION_SPEC=0.1.0.dev0 export RH_CHANGELOG=${{ inputs.changelog }} export RH_DRY_RUN=true - if [ ! -z ${GITHUB_HEAD_REF} ]; then - echo "Using GITHUB_HEAD_REF: ${GITHUB_HEAD_REF}" - export RH_BRANCH=${GITHUB_HEAD_REF} + export RH_REF=${GITHUB_REF} + + if [ ! -z ${GITHUB_BASE_REF} ]; then + echo "Using GITHUB_BASE_REF: ${GITHUB_BASE_REF}" + export RH_BRANCH=${GITHUB_BASE_REF} else # e.g refs/head/foo or refs/tag/bar echo "Using GITHUB_REF: ${GITHUB_REF}" @@ -35,9 +37,6 @@ runs: # Install Jupyter Releaser from git unless we are testing Releaser itself export repo_name=$(echo ${GITHUB_REPOSITORY} | cut -d'/' -f 2) echo "repo name: ${repo_name}" - if [ ${repo_name} != "jupyter_releaser" ]; then - pip install git+https://github.com/jupyter-server/jupyter_releaser.git - fi # Draft Changelog python -m jupyter_releaser.actions.draft_changelog @@ -45,26 +44,5 @@ runs: # Draft Release python -m jupyter_releaser.actions.draft_release - - shell: bash - id: publish-release - run: | - set -eux - - # Set up env variables - export release_url=${{ steps.draft-release.outputs.release_url }} - export GITHUB_ACCESS_TOKEN=${{ inputs.token }} - export RH_DRY_RUN=true - - # Publish Release - python -m jupyter_releaser.actions.publish_release ${release_url} - - - shell: bash - run: | - set -eux - - # Set up env variables - export GITHUB_ACCESS_TOKEN=${{ inputs.token }} - export release_url=${{ steps.publish-release.outputs.release_url }} - - # Delete Draft Release - jupyter-releaser delete-release ${release_url} + # Publish Assets + jupyter-releaser publish-assets --use-checkout-dir diff --git a/.github/actions/draft-changelog/action.yml b/.github/actions/draft-changelog/action.yml index ffe2f2f0..31caf692 100644 --- a/.github/actions/draft-changelog/action.yml +++ b/.github/actions/draft-changelog/action.yml @@ -42,6 +42,7 @@ runs: export RH_VERSION_SPEC=${{ inputs.version_spec }} export RH_CHANGELOG=${{ inputs.changelog }} export RH_DRY_RUN=${{ inputs.dry_run }} + export RH_REF=${GITHUB_REF} # Draft Changelog pip install -q jupyter-releaser diff --git a/.github/actions/draft-release/action.yml b/.github/actions/draft-release/action.yml index a99a25bf..02790443 100644 --- a/.github/actions/draft-release/action.yml +++ b/.github/actions/draft-release/action.yml @@ -42,6 +42,7 @@ runs: if [ ! -z ${{ inputs.branch }} ]; then export RH_BRANCH=${{ inputs.branch }} fi + export RH_REF=${GITHUB_REF} export RH_VERSION_SPEC=${{ inputs.version_spec }} export RH_CHANGELOG=${{ inputs.changelog }} export RH_POST_VERSION_SPEC=${{ inputs.post_version_spec }} diff --git a/.github/workflows/check-release.yml b/.github/workflows/check-release.yml index 5b34b876..4206ae64 100644 --- a/.github/workflows/check-release.yml +++ b/.github/workflows/check-release.yml @@ -2,12 +2,12 @@ name: Check Release on: push: branches: ["*"] + pull_request: + branches: ["*"] jobs: check_release: runs-on: ubuntu-latest - permissions: - contents: write steps: - name: Checkout uses: actions/checkout@v2 @@ -35,6 +35,8 @@ jobs: key: ${{ runner.os }}-linkcheck-${{ hashFiles('**/.md') }}-md-links restore-keys: | ${{ runner.os }}-linkcheck- + - name: Print env + run: env - name: Upgrade packaging dependencies run: | pip install --upgrade pip setuptools wheel --user diff --git a/jupyter_releaser/actions/publish_release.py b/jupyter_releaser/actions/publish_release.py index d3a6d98a..5a76d5e2 100644 --- a/jupyter_releaser/actions/publish_release.py +++ b/jupyter_releaser/actions/publish_release.py @@ -1,15 +1,11 @@ # Copyright (c) Jupyter Development Team. # Distributed under the terms of the Modified BSD License. -import atexit import os -from subprocess import Popen -from tempfile import TemporaryDirectory -from jupyter_releaser.util import CHECKOUT_NAME from jupyter_releaser.util import run -os.environ.setdefault("TWINE_USERNAME", "__token__") release_url = os.environ["release_url"] run(f"jupyter-releaser extract-release {release_url}") run(f"jupyter-releaser forwardport-changelog {release_url}") +run("jupyter-releaser publish-assets") run(f"jupyter-releaser publish-release {release_url}") diff --git a/jupyter_releaser/changelog.py b/jupyter_releaser/changelog.py index af1c8e49..1ad1f554 100644 --- a/jupyter_releaser/changelog.py +++ b/jupyter_releaser/changelog.py @@ -69,8 +69,17 @@ def get_version_entry(branch, repo, version, *, auth=None, resolve_backports=Fal branch = branch.split("/")[-1] util.log(f"Getting changes to {repo} since {since} on branch {branch}...") + until = util.run(f'git --no-pager log -n 1 origin/{branch} --pretty=format:"%H"') + until = until.replace("%", "") + md = generate_activity_md( - repo, since=since, kind="pr", heading_level=2, auth=auth, branch=branch + repo, + since=since, + until=until, + kind="pr", + heading_level=2, + auth=auth, + branch=branch, ) if not md: @@ -113,8 +122,8 @@ def get_version_entry(branch, repo, version, *, auth=None, resolve_backports=Fal def build_entry(branch, repo, auth, changelog_path, resolve_backports): """Build a python version entry""" - repo = repo or util.get_repo() branch = branch or util.get_branch() + repo = repo or util.get_repo() # Get the new version version = util.get_version() @@ -129,7 +138,7 @@ def build_entry(branch, repo, auth, changelog_path, resolve_backports): raise ValueError("Insert marker appears more than once in changelog") # Get changelog entry - + # for a pull request, use the target branch entry = get_version_entry( f"origin/{branch}", repo, @@ -178,9 +187,9 @@ def format(changelog): return re.sub(r"\n\n+$", r"\n", changelog) -def check_entry(branch, repo, auth, changelog_path, resolve_backports, output): +def check_entry(ref, repo, auth, changelog_path, resolve_backports, output): """Check changelog entry""" - branch = branch or util.get_branch() + ref = ref or util.get_branch() # Get the new version version = util.get_version() @@ -200,8 +209,9 @@ def check_entry(branch, repo, auth, changelog_path, resolve_backports, output): final_entry = changelog[start + len(START_MARKER) : end] repo = repo or util.get_repo() + raw_entry = get_version_entry( - f"origin/{branch}", + f"origin/{ref}", repo, version, auth=auth, diff --git a/jupyter_releaser/cli.py b/jupyter_releaser/cli.py index 0a6a7b83..699b7c34 100644 --- a/jupyter_releaser/cli.py +++ b/jupyter_releaser/cli.py @@ -125,7 +125,9 @@ def main(): ) ] + branch_options = [ + click.option("--ref", envvar="RH_REF", help="The source reference"), click.option("--branch", envvar="RH_BRANCH", help="The target branch"), click.option("--repo", envvar="RH_REPOSITORY", help="The git repo"), ] @@ -216,9 +218,9 @@ def list_envvars(): @add_options(auth_options) @add_options(username_options) @add_options(git_url_options) -def prep_git(branch, repo, auth, username, git_url): +def prep_git(ref, branch, repo, auth, username, git_url): """Prep git and env variables and bump version""" - lib.prep_git(branch, repo, auth, username, git_url) + lib.prep_git(ref, branch, repo, auth, username, git_url) @main.command() @@ -233,7 +235,7 @@ def bump_version(version_spec, version_cmd): @main.command() @add_options(changelog_options) @use_checkout_dir() -def build_changelog(branch, repo, auth, changelog_path, resolve_backports): +def build_changelog(ref, branch, repo, auth, changelog_path, resolve_backports): """Build changelog entry""" changelog.build_entry(branch, repo, auth, changelog_path, resolve_backports) @@ -244,7 +246,7 @@ def build_changelog(branch, repo, auth, changelog_path, resolve_backports): @add_options(auth_options) @add_options(dry_run_options) @use_checkout_dir() -def draft_changelog(version_spec, branch, repo, auth, dry_run): +def draft_changelog(version_spec, ref, branch, repo, auth, dry_run): """Create a changelog entry PR""" lib.draft_changelog(version_spec, branch, repo, auth, dry_run) @@ -255,7 +257,7 @@ def draft_changelog(version_spec, branch, repo, auth, dry_run): "--output", envvar="RH_CHANGELOG_OUTPUT", help="The output file for changelog entry" ) @use_checkout_dir() -def check_changelog(branch, repo, auth, changelog_path, resolve_backports, output): +def check_changelog(ref, branch, repo, auth, changelog_path, resolve_backports, output): """Check changelog entry""" changelog.check_entry(branch, repo, auth, changelog_path, resolve_backports, output) @@ -357,7 +359,6 @@ def check_links(ignore_glob, ignore_links, cache_file, links_expire): @main.command() -@add_options(branch_options) @add_options(dist_dir_options) @click.option( "--no-git-tag-workspace", @@ -365,9 +366,9 @@ def check_links(ignore_glob, ignore_links, cache_file, links_expire): help="Whether to skip tagging npm workspace packages", ) @use_checkout_dir() -def tag_release(branch, repo, dist_dir, no_git_tag_workspace): +def tag_release(dist_dir, no_git_tag_workspace): """Create release commit and tag""" - lib.tag_release(branch, repo, dist_dir, no_git_tag_workspace) + lib.tag_release(dist_dir, no_git_tag_workspace) @main.command() @@ -385,6 +386,7 @@ def tag_release(branch, repo, dist_dir, no_git_tag_workspace): @click.argument("assets", nargs=-1) @use_checkout_dir() def draft_release( + ref, branch, repo, auth, @@ -397,6 +399,7 @@ def draft_release( ): """Publish Draft GitHub release""" lib.draft_release( + ref, branch, repo, auth, @@ -421,39 +424,44 @@ def delete_release(auth, release_url): @add_options(auth_options) @add_options(dist_dir_options) @add_options(dry_run_options) -@click.argument("release_url", nargs=1) +@click.argument("release-url", nargs=1) def extract_release(auth, dist_dir, dry_run, release_url): """Download and verify assets from a draft GitHub release""" lib.extract_release(auth, dist_dir, dry_run, release_url) @main.command() -@add_options(auth_options) @add_options(dist_dir_options) -@click.option("--npm_token", help="A token for the npm release", envvar="NPM_TOKEN") +@click.option("--npm-token", help="A token for the npm release", envvar="NPM_TOKEN") @click.option( - "--npm_cmd", + "--npm-cmd", help="The command to run for npm release", envvar="RH_NPM_COMMAND", default="npm publish", ) @click.option( - "--twine_cmd", + "--twine-cmd", help="The twine to run for Python release", envvar="TWINE_COMMAND", default="twine upload", ) +@click.option("--use-checkout-dir", help="Use the checkout directory", is_flag=True) @add_options(dry_run_options) -@click.argument("release_url", nargs=1) -def publish_release( - auth, dist_dir, npm_token, npm_cmd, twine_cmd, dry_run, release_url -): - """Publish release asset(s) and finalize GitHub release""" - lib.publish_release( - auth, dist_dir, npm_token, npm_cmd, twine_cmd, dry_run, release_url +def publish_assets(dist_dir, npm_token, npm_cmd, twine_cmd, dry_run, use_checkout_dir): + """Publish release asset(s)""" + lib.publish_assets( + dist_dir, npm_token, npm_cmd, twine_cmd, dry_run, use_checkout_dir ) +@main.command() +@add_options(auth_options) +@click.argument("release-url", nargs=1) +def publish_release(auth, release_url): + """Publish GitHub release""" + lib.publish_release(auth, release_url) + + @main.command() @add_options(auth_options) @add_options(branch_options) @@ -461,13 +469,13 @@ def publish_release( @add_options(changelog_path_options) @add_options(dry_run_options) @add_options(git_url_options) -@click.argument("release_url") +@click.argument("release-url") def forwardport_changelog( - auth, branch, repo, username, changelog_path, dry_run, git_url, release_url + auth, ref, branch, repo, username, changelog_path, dry_run, git_url, release_url ): """Forwardport Changelog Entries to the Default Branch""" lib.forwardport_changelog( - auth, branch, repo, username, changelog_path, dry_run, git_url, release_url + auth, ref, branch, repo, username, changelog_path, dry_run, git_url, release_url ) diff --git a/jupyter_releaser/lib.py b/jupyter_releaser/lib.py index 9b63e4eb..0753e70e 100644 --- a/jupyter_releaser/lib.py +++ b/jupyter_releaser/lib.py @@ -157,14 +157,11 @@ def make_changelog_pr(auth, branch, repo, title, commit_message, body, dry_run=F util.actions_output("pr_url", pull.html_url) -def tag_release(branch, repo, dist_dir, no_git_tag_workspace): +def tag_release(dist_dir, no_git_tag_workspace): """Create release commit and tag""" # Get the new version version = util.get_version() - # Get the branch - branch = branch or util.get_branch() - # Create the release commit util.create_release_commit(version, dist_dir) @@ -178,6 +175,7 @@ def tag_release(branch, repo, dist_dir, no_git_tag_workspace): def draft_release( + ref, branch, repo, auth, @@ -191,12 +189,20 @@ def draft_release( """Publish Draft GitHub release and handle post version bump""" branch = branch or util.get_branch() repo = repo or util.get_repo() - assets = assets or glob(f"{dist_dir}/*") - version = util.get_version() - body = changelog.extract_current(changelog_path) + prerelease = util.is_prerelease(version) + + # Bump to post version if given + if post_version_spec: + post_version = bump_version(post_version_spec, version_cmd) + + util.log(f"Bumped version to {post_version}") + util.run(f'git commit -a -m "Bump to {post_version}"') + + if dry_run: + return owner, repo_name = repo.split("/") gh = GhApi(owner=owner, repo=repo_name, token=auth) @@ -212,20 +218,9 @@ def draft_release( if delta.days > 0: gh.repos.delete_release(release.id) - # Create a draft release - prerelease = util.is_prerelease(version) - - # Bump to post version if given - if post_version_spec: - post_version = bump_version(post_version_spec, version_cmd) - - util.log(f"Bumped version to {post_version}") - util.run(f'git commit -a -m "Bump to {post_version}"') - - if not dry_run: - remote_url = util.run("git config --get remote.origin.url") - if not os.path.exists(remote_url): - util.run(f"git push origin HEAD:{branch} --follow-tags --tags") + remote_url = util.run("git config --get remote.origin.url") + if not os.path.exists(remote_url): + util.run(f"git push origin HEAD:{branch} --follow-tags --tags") util.log(f"Creating release for {version}") util.log(f"With assets: {assets}") @@ -331,9 +326,6 @@ def extract_release(auth, dist_dir, dry_run, release_url): util.log("Mismatched sha!") if not valid: # pragma: no cover - import pdb - - pdb.set_trace() raise ValueError(f"Invalid file {asset.name}") @@ -346,11 +338,12 @@ def parse_release_url(release_url): return match -def publish_release( - auth, dist_dir, npm_token, npm_cmd, twine_cmd, dry_run, release_url -): - """Publish release asset(s) and finalize GitHub release""" - util.log(f"Publishing {release_url} in with dry run: {dry_run}") +def publish_assets(dist_dir, npm_token, npm_cmd, twine_cmd, dry_run, use_checkout_dir): + """Publish release asset(s)""" + if use_checkout_dir: + if not osp.exists(util.CHECKOUT_NAME): + raise ValueError("Please run prep-git first") + os.chdir(util.CHECKOUT_NAME) if dry_run: # Start local pypi server with no auth, allowing overwrites, @@ -371,8 +364,6 @@ def publish_release( os.environ["TWINE_PASSWORD"] = "bar" npm_cmd = "npm publish --dry-run" - match = parse_release_url(release_url) - if npm_token: npm.handle_auth_token(npm_token) @@ -392,6 +383,13 @@ def publish_release( if not found: # pragma: no cover raise ValueError("No assets published, refusing to finalize release") + +def publish_release(auth, release_url): + """Publish GitHub release""" + util.log(f"Publishing {release_url}") + + match = parse_release_url(release_url) + # Take the release out of draft gh = GhApi(owner=match["owner"], repo=match["repo"], token=auth) release = util.release_for_url(gh, release_url) @@ -402,7 +400,7 @@ def publish_release( release.target_commitish, release.name, release.body, - dry_run, + False, release.prerelease, ) @@ -410,7 +408,7 @@ def publish_release( util.actions_output("release_url", release.html_url) -def prep_git(branch, repo, auth, username, url, install=True): +def prep_git(ref, branch, repo, auth, username, url, install=True): """Set up git""" repo = repo or util.get_repo() @@ -454,13 +452,34 @@ def prep_git(branch, repo, auth, username, url, install=True): util.run(f"git remote add origin {url}") branch = branch or util.get_default_branch() - - util.run(f"git fetch origin {branch}") + ref = ref or "" # Make sure we have *all* tags util.run("git fetch origin --tags") - util.run(f"git checkout {branch}") + # Handle the ref + if ref.startswith("refs/pull/"): + pull = ref[len("refs/pull/") :] + ref_alias = f"refs/pull/{pull}" + else: + ref = None + + # Reuse existing branch if possible + if ref: + util.run(f"git fetch origin +{ref}:{ref_alias}") + util.run(f"git fetch origin {ref}") + checkout_cmd = f"git checkout -B {branch} {ref_alias}" + else: + util.run(f"git fetch origin {branch}") + checkout_cmd = f"git checkout {branch}" + + if checkout_exists: + try: + util.run(f"git checkout {branch}") + except Exception: + util.run(checkout_cmd) + else: + util.run(checkout_cmd) # Install the package with test deps if util.SETUP_PY.exists() and install: @@ -472,7 +491,7 @@ def prep_git(branch, repo, auth, username, url, install=True): def forwardport_changelog( - auth, branch, repo, username, changelog_path, dry_run, git_url, release_url + auth, ref, branch, repo, username, changelog_path, dry_run, git_url, release_url ): """Forwardport Changelog Entries to the Default Branch""" # Set up the git repo with the branch @@ -485,7 +504,7 @@ def forwardport_changelog( # We want to target the main branch orig_dir = os.getcwd() - branch = prep_git(None, repo, auth, username, git_url, install=False) + branch = prep_git(None, None, repo, auth, username, git_url, install=False) os.chdir(util.CHECKOUT_NAME) # Bail if the tag has been merged to the branch @@ -543,7 +562,7 @@ def forwardport_changelog( body = title pr = make_changelog_pr( - auth, branch, repo, title, commit_message, body, dry_run=dry_run + auth, ref, branch, repo, title, commit_message, body, dry_run=dry_run ) # Clean up after ourselves diff --git a/jupyter_releaser/tests/test_cli.py b/jupyter_releaser/tests/test_cli.py index 531a7ab4..5ae6e1d5 100644 --- a/jupyter_releaser/tests/test_cli.py +++ b/jupyter_releaser/tests/test_cli.py @@ -56,6 +56,7 @@ def test_prep_git_full(py_package, tmp_path, mocker, runner): """Full GitHub Actions simulation (Push)""" env = dict( + RH_REF="refs/pull/42", RH_BRANCH="foo", GITHUB_ACTIONS="true", RH_REPOSITORY="baz/bar", @@ -78,9 +79,10 @@ def test_prep_git_full(py_package, tmp_path, mocker, runner): call('git config --global user.name "GitHub Action"'), call("git init .jupyter_releaser_checkout"), call("git remote add origin https://snuffy:abc123@github.com/baz/bar.git"), - call("git fetch origin foo"), call("git fetch origin --tags"), - call("git checkout foo"), + call("git fetch origin +refs/pull/42:refs/pull/42"), + call("git fetch origin refs/pull/42"), + call("git checkout -B foo refs/pull/42"), ] ) @@ -124,6 +126,7 @@ def test_list_envvars(runner): npm-token: NPM_TOKEN output: RH_CHANGELOG_OUTPUT post-version-spec: RH_POST_VERSION_SPEC +ref: RH_REF repo: RH_REPOSITORY resolve-backports: RH_RESOLVE_BACKPORTS test-cmd: RH_NPM_TEST_COMMAND @@ -329,7 +332,7 @@ def test_tag_release(py_package, runner, build_mock, git_prep): def test_draft_release_dry_run(py_dist, mocker, runner, open_mock, git_prep): # Publish the release - dry run runner(["draft-release", "--dry-run", "--post-version-spec", "1.1.0.dev0"]) - assert len(open_mock.call_args) == 2 + open_mock.assert_not_called() def test_draft_release_final(npm_dist, runner, mocker, open_mock, git_prep): @@ -361,7 +364,7 @@ def test_delete_release(npm_dist, runner, mocker, open_mock, git_prep): MockHTTPResponse(), MockHTTPResponse(), ] - result = runner(["draft-release", "--dry-run"]) + result = runner(["draft-release"]) assert len(open_mock.call_args) == 2 url = "" @@ -467,9 +470,7 @@ def helper(path, **kwargs): @pytest.mark.skipif( os.name == "nt", reason="pypiserver does not start properly on Windows" ) -def test_publish_release_py(py_package, runner, mocker, open_mock, git_prep): - open_mock.side_effect = [MockHTTPResponse([REPO_DATA]), MockHTTPResponse()] - +def test_publish_assets_py(py_package, runner, mocker, git_prep): # Create the dist files changelog_entry = mock_changelog_entry(py_package, runner, mocker) run("python -m build .", cwd=util.CHECKOUT_NAME) @@ -486,26 +487,42 @@ def wrapped(cmd, **kwargs): mock_run = mocker.patch("jupyter_releaser.util.run", wraps=wrapped) dist_dir = py_package / util.CHECKOUT_NAME / "dist" - runner(["publish-release", HTML_URL, "--dist-dir", dist_dir, "--dry-run"]) - assert len(open_mock.call_args) == 2 + runner(["publish-assets", "--dist-dir", dist_dir, "--dry-run"]) assert called == 2, called -def test_publish_release_npm(npm_dist, runner, mocker, open_mock): - open_mock.side_effect = [MockHTTPResponse([REPO_DATA]), MockHTTPResponse()] +def test_publish_assets_npm(npm_dist, runner, mocker): dist_dir = npm_dist / util.CHECKOUT_NAME / "dist" + orig_run = util.run + called = 0 + + def wrapped(cmd, **kwargs): + nonlocal called + if cmd.startswith("npm publish --dry-run"): + called += 1 + return orig_run(cmd, **kwargs) + + mock_run = mocker.patch("jupyter_releaser.util.run", wraps=wrapped) + runner( [ - "publish-release", - HTML_URL, - "--npm_token", + "publish-assets", + "--npm-token", "abc", - "--npm_cmd", + "--npm-cmd", "npm publish --dry-run", "--dist-dir", dist_dir, ] ) + + assert called == 3, called + + +def test_publish_release(npm_dist, runner, mocker, open_mock): + open_mock.side_effect = [MockHTTPResponse([REPO_DATA]), MockHTTPResponse()] + dist_dir = npm_dist / util.CHECKOUT_NAME / "dist" + runner(["publish-release", HTML_URL]) assert len(open_mock.call_args) == 2 diff --git a/jupyter_releaser/tests/test_functions.py b/jupyter_releaser/tests/test_functions.py index 37df7763..5358fd78 100644 --- a/jupyter_releaser/tests/test_functions.py +++ b/jupyter_releaser/tests/test_functions.py @@ -51,9 +51,18 @@ def test_get_changelog_version_entry(py_package, mocker): mocked_gen = mocker.patch("jupyter_releaser.changelog.generate_activity_md") mocked_gen.return_value = testutil.CHANGELOG_ENTRY - resp = changelog.get_version_entry("foo", "bar/baz", version) + branch = "foo" + resp = changelog.get_version_entry(branch, "bar/baz", version) + until = util.run(f'git --no-pager log -n 1 origin/{branch} --pretty=format:"%H"') + until = until.replace("%", "") mocked_gen.assert_called_with( - "bar/baz", since="v0.0.1", kind="pr", branch="foo", heading_level=2, auth=None + "bar/baz", + since="v0.0.1", + kind="pr", + branch=branch, + heading_level=2, + auth=None, + until=until, ) assert f"## {version}" in resp @@ -61,10 +70,16 @@ def test_get_changelog_version_entry(py_package, mocker): mocked_gen.return_value = testutil.CHANGELOG_ENTRY resp = changelog.get_version_entry( - "foo", "bar/baz", version, resolve_backports=True, auth="bizz" + branch, "bar/baz", version, resolve_backports=True, auth="bizz" ) mocked_gen.assert_called_with( - "bar/baz", since="v0.0.1", kind="pr", branch="foo", heading_level=2, auth="bizz" + "bar/baz", + since="v0.0.1", + until=until, + kind="pr", + branch=branch, + heading_level=2, + auth="bizz", ) assert f"## {version}" in resp From 455563d6268182180e93de529dacb7b065b12312 Mon Sep 17 00:00:00 2001 From: Jeremy Tuloup Date: Fri, 30 Apr 2021 12:44:07 +0200 Subject: [PATCH 2/3] ref -> branch --- jupyter_releaser/changelog.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/jupyter_releaser/changelog.py b/jupyter_releaser/changelog.py index 1ad1f554..2088c473 100644 --- a/jupyter_releaser/changelog.py +++ b/jupyter_releaser/changelog.py @@ -187,9 +187,9 @@ def format(changelog): return re.sub(r"\n\n+$", r"\n", changelog) -def check_entry(ref, repo, auth, changelog_path, resolve_backports, output): +def check_entry(branch, repo, auth, changelog_path, resolve_backports, output): """Check changelog entry""" - ref = ref or util.get_branch() + branch = branch or util.get_branch() # Get the new version version = util.get_version() @@ -211,7 +211,7 @@ def check_entry(ref, repo, auth, changelog_path, resolve_backports, output): repo = repo or util.get_repo() raw_entry = get_version_entry( - f"origin/{ref}", + f"origin/{branch}", repo, version, auth=auth, From b9dd00083ff4dbcdc64996c1f78fae2269b0050b Mon Sep 17 00:00:00 2001 From: Jeremy Tuloup Date: Fri, 30 Apr 2021 12:44:49 +0200 Subject: [PATCH 3/3] Remove extraneous comment --- jupyter_releaser/changelog.py | 1 - 1 file changed, 1 deletion(-) diff --git a/jupyter_releaser/changelog.py b/jupyter_releaser/changelog.py index 2088c473..152252fa 100644 --- a/jupyter_releaser/changelog.py +++ b/jupyter_releaser/changelog.py @@ -138,7 +138,6 @@ def build_entry(branch, repo, auth, changelog_path, resolve_backports): raise ValueError("Insert marker appears more than once in changelog") # Get changelog entry - # for a pull request, use the target branch entry = get_version_entry( f"origin/{branch}", repo,