From: John Mulligan Date: Wed, 29 Nov 2023 20:45:15 +0000 (-0500) Subject: script/build-integration-branch: support fetching github token from netrc X-Git-Tag: v19.3.0~368^2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=6e37d99eb14137bf4fa34dd89e92cdb98037875b;p=ceph.git script/build-integration-branch: support fetching github token from netrc I constantly forget to update the special place that this script wants to read the github token from. Other tools I use can read from the .netrc file. Try reading the token from netrc before falling back to this script's traditional location. Signed-off-by: John Mulligan --- diff --git a/src/script/build-integration-branch b/src/script/build-integration-branch index b5f53aa21017..c4e1d604f0c8 100755 --- a/src/script/build-integration-branch +++ b/src/script/build-integration-branch @@ -7,7 +7,12 @@ Builds integration branches. Something similar to > git pull b > done -Requires `~/.github_token`. +Requires either `~/.github_token` containing ONLY the token +OR adding an entry like the following to `~/.netrc`: + ``` + machine github.com + password ghp_E7ln0tAR34LtoK3nIsw34RyTve2moM3BvK + ``` Usage: @@ -24,6 +29,7 @@ import os import requests import sys import time +import netrc from subprocess import call, check_output from urllib.parse import urljoin @@ -52,9 +58,28 @@ except ImportError: assert len(sys.argv) == 2 branch = label + postfix - -with open(os.path.expanduser('~/.github_token')) as myfile: - token = myfile.readline().strip() +token = '' +try: + nrc = netrc.netrc() + nrauth = nrc.authenticators("api.github.com") + if nrauth: + token = nrauth[2] + if not token: + nrauth = nrc.authenticators("github.com") + if nrauth: + token = nrauth[2] +except FileNotFoundError: + pass +if not token: + try: + with open(os.path.expanduser('~/.github_token')) as myfile: + token = myfile.readline().strip() + except FileNotFoundError: + pass +if not token: + print('No github api access token found') + print(' Add a token to .netrc for [api.]github.com') + print(' OR add a token to $HOME/.github_token') # get prs baseurl = urljoin('https://api.github.com',