> 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:
import requests
import sys
import time
+import netrc
from subprocess import call, check_output
from urllib.parse import urljoin
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',