From cb94fd31c870384e13240d71ee487639e3360ee3 Mon Sep 17 00:00:00 2001 From: Bruno Oliveira Date: Wed, 14 Aug 2019 18:51:00 -0300 Subject: [PATCH] Use TRAVIS_REPO_SLUG instead of hard-coding pytest-dev/pytest I was doing final tests on the script today, and forgot to change the hardecoded "pytest-dev/pytest", which ended up publishing a `4.99.10` release to the main repository by mistake, as my token has access to both my fork and main repository. I deleted the tag immeditely just a few seconds later, so hopefully this won't cause major problems. This change makes it safer to test this in the future, never publishing to the main repository by mistake (as long as the tags are pushed to the right repositories of course). --- scripts/publish_gh_release_notes.py | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/scripts/publish_gh_release_notes.py b/scripts/publish_gh_release_notes.py index f6c956fad..23f7b40ad 100644 --- a/scripts/publish_gh_release_notes.py +++ b/scripts/publish_gh_release_notes.py @@ -25,9 +25,10 @@ import github3 import pypandoc -def publish_github_release(token, tag_name, body): +def publish_github_release(slug, token, tag_name, body): github = github3.login(token=token) - repo = github.repository("pytest-dev", "pytest") + owner, repo = slug.split("/") + repo = github.repository(owner, repo) return repo.create_release(tag_name=tag_name, body=body) @@ -71,14 +72,22 @@ def main(argv): print("GH_RELEASE_NOTES_TOKEN not set", file=sys.stderr) return 1 + slug = os.environ.get("TRAVIS_REPO_SLUG") + if not slug: + print("TRAVIS_REPO_SLUG not set", file=sys.stderr) + return 1 + rst_body = parse_changelog(tag_name) md_body = convert_rst_to_md(rst_body) - if not publish_github_release(token, tag_name, md_body): + if not publish_github_release(slug, token, tag_name, md_body): print("Could not publish release notes:", file=sys.stderr) print(md_body, file=sys.stderr) return 5 - print(f"Release notes for {tag_name} published successfully") + print() + print(f"Release notes for {tag_name} published successfully:") + print(f"https://github.com/{slug}/releases/tag/{tag_name}") + print() return 0