Skip to content

Commit

Permalink
[scripts] add an explicit error message on failures in new-release
Browse files Browse the repository at this point in the history
  • Loading branch information
hugsy committed Apr 16, 2023
1 parent 18e2c9c commit 5040cbe
Showing 1 changed file with 18 additions and 3 deletions.
21 changes: 18 additions & 3 deletions scripts/new-release.py
Expand Up @@ -30,6 +30,7 @@
GITHUB_TOKEN = os.getenv("GITHUB_REPO_TOKEN")
DEBUG = False
OUTPUT_FILE = pathlib.Path( tempfile.gettempdir() ) / "CHANGELOG.md"
GITHUB_NEW_TOKEN_URL = "https://github.com/settings/personal-access-tokens/new"


def dbg(x: str):
Expand Down Expand Up @@ -122,6 +123,15 @@ def generate_changelog(args: argparse.Namespace) -> bool:
return True


def test_token(args) -> bool:
url = f"https://api.github.com/repos/{args.repository}/issues"
req = requests.get(url, headers={"Authorization": f"token {args.token}"})
if req.status_code != 200:
print(f"test_token(): return HTTP code {req.status_code}")
print(f"Get a token from {GITHUB_NEW_TOKEN_URL} with 'Read-Only' privilege on Issues for the {args.repository} repository")
return req.status_code == 200


if __name__ == "__main__":
parser = argparse.ArgumentParser(usage = __usage__, description = __desc__, prog = __file__)
parser.add_argument("--debug", action="store_true", default=DEBUG,
Expand All @@ -139,7 +149,12 @@ def generate_changelog(args: argparse.Namespace) -> bool:
parser.add_argument("--push-release", action="store_true", default=False,
help="Create the new tag and publish the release on Github")

x = parser.parse_args()
DEBUG = x.debug
generate_changelog(x)
args = parser.parse_args()
DEBUG = args.debug

if not test_token(args):
dbg(f"The GITHUB_TOKEN is not valid")
exit(1)

generate_changelog(args)
exit(0)

0 comments on commit 5040cbe

Please sign in to comment.