|
16 | 16 | """ |
17 | 17 |
|
18 | 18 | # NB: This exact commit message is used to find commits for reverting during backports. |
19 | | -# Changing it requires a transition period where both old and new versions are supported. |
| 19 | +# Changing it requires a transition period where both old and new versions are supported. |
20 | 20 | BACKPORT_COMMIT_MESSAGE = 'Update version and changelog for v' |
21 | 21 |
|
22 | 22 | # Name of the remote |
23 | 23 | ORIGIN = 'origin' |
24 | 24 |
|
| 25 | +# Environment variables to check for a GitHub API token. |
| 26 | +TOKEN_ENVIRONMENT_VARIABLES = ('GH_TOKEN', 'GITHUB_TOKEN') |
| 27 | + |
| 28 | +# Gets a GitHub API token from one of the supported environment variables. |
| 29 | +def get_github_token(): |
| 30 | + for variable_name in TOKEN_ENVIRONMENT_VARIABLES: |
| 31 | + token = os.environ.get(variable_name, '').strip() |
| 32 | + if token: |
| 33 | + return token |
| 34 | + raise Exception('Missing GitHub token. Set GITHUB_TOKEN or GH_TOKEN.') |
| 35 | + |
25 | 36 | # Runs git with the given args and returns the stdout. |
26 | 37 | # Raises an error if git does not exit successfully (unless passed |
27 | 38 | # allow_non_zero_exit_code=True). |
@@ -270,12 +281,6 @@ def update_changelog(version): |
270 | 281 | def main(): |
271 | 282 | parser = argparse.ArgumentParser('update-release-branch.py') |
272 | 283 |
|
273 | | - parser.add_argument( |
274 | | - '--github-token', |
275 | | - type=str, |
276 | | - required=True, |
277 | | - help='GitHub token, typically from GitHub Actions.' |
278 | | - ) |
279 | 284 | parser.add_argument( |
280 | 285 | '--repository-nwo', |
281 | 286 | type=str, |
@@ -313,7 +318,7 @@ def main(): |
313 | 318 | target_branch = args.target_branch |
314 | 319 | is_primary_release = args.is_primary_release |
315 | 320 |
|
316 | | - repo = Github(args.github_token).get_repo(args.repository_nwo) |
| 321 | + repo = Github(get_github_token()).get_repo(args.repository_nwo) |
317 | 322 |
|
318 | 323 | # the target branch will be of the form releases/vN, where N is the major version number |
319 | 324 | target_branch_major_version = target_branch.strip('releases/v') |
|
0 commit comments