From 8feeb5f1fae951332ea4b520e5618982109da570 Mon Sep 17 00:00:00 2001 From: Alan Rominger Date: Tue, 12 Sep 2023 15:47:12 -0400 Subject: [PATCH] Allow saving github creds in user folder (#14435) --- docs/release_process.md | 4 ++-- tools/scripts/get_next_release.py | 27 ++++++++++++++------------- 2 files changed, 16 insertions(+), 15 deletions(-) diff --git a/docs/release_process.md b/docs/release_process.md index af9a163f8d..1a767e7fe5 100644 --- a/docs/release_process.md +++ b/docs/release_process.md @@ -15,7 +15,7 @@ There are two methods you can use to get the next release version. The manual wa Log into your github account, under your user icon go to Settings => Developer Settings => Personal Access Tokens => Tokens (classic). Select the Generate new token => Generate new token (classic) Fill in the note, select no scopes select "Generate token". -Copy the token and create a file in your awx repo called `.github_creds`. Enter the token in this file. +Copy the token and create a file at `~/.github_creds` or in your awx repo as `.github_creds`. Enter the token in this file. Run `./tools/scripts/get_next_release.py` This will use your token to go query for the PRs in the release and scan their bodies to select X/Y/Z and suggest new versions and spit out notifications. @@ -149,7 +149,7 @@ Send notifications to the following groups: * AWX Mailing List * #social:ansible.com IRC (@newsbot for inclusion in bullhorn) * #awx:ansible.com (no @newsbot in this room) - * #ansible-controller slack channel + * #ansible-controller slack channel These messages are templated out for you in the output of `get_next_release.yml`. diff --git a/tools/scripts/get_next_release.py b/tools/scripts/get_next_release.py index 33e50a0566..0fa36592ab 100755 --- a/tools/scripts/get_next_release.py +++ b/tools/scripts/get_next_release.py @@ -3,17 +3,15 @@ missing_modules = [] try: import requests -except: +except ImportError: missing_modules.append('requests') import json import os -import re import sys -import time try: import semantic_version -except: +except ImportError: missing_modules.append('semantic_version') if len(missing_modules) > 0: @@ -55,7 +53,7 @@ def getNextReleases(): try: if a_pr['html_url'] in pr_votes: continue - except: + except KeyError: print("Unable to check on PR") print(json.dumps(a_pr, indent=4)) sys.exit(255) @@ -133,14 +131,17 @@ def getNextReleases(): # Load the users session information # session = requests.Session() -try: - print("Loading credentials") - with open(".github_creds", "r") as f: - password = f.read().strip() - session.headers.update({'Authorization': 'bearer {}'.format(password), 'Accept': 'application/vnd.github.v3+json'}) -except Exception: - print("Failed to load credentials from ./.github_creds") - sys.exit(255) + +print("Loading credentials") +CREDS_LOCATIONS = ('.github_creds', '~/.github_creds') +for creds_loc in CREDS_LOCATIONS: + if os.path.exists(os.path.expanduser(creds_loc)): + with open(os.path.expanduser(creds_loc), "r") as f: + password = f.read().strip() + session.headers.update({'Authorization': 'bearer {}'.format(password), 'Accept': 'application/vnd.github.v3+json'}) + break +else: + raise Exception(f'Could not location github token in locations {CREDS_LOCATIONS}') versions = { 'current': {},