Skip to content

Commit 242c11a

Browse files
committed
Add support for user.token
1 parent 74b4e46 commit 242c11a

File tree

1 file changed

+19
-4
lines changed

1 file changed

+19
-4
lines changed

webdiff/github_fetcher.py

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,23 @@ def simple_fallback(message=None):
3636
k, v = line.split(': ', 1)
3737
kvs[k] = v
3838

39-
if not kvs.get('user.login'):
39+
login = kvs.get('user.login')
40+
if not login:
4041
return simple_fallback('.githubrc missing user.login. Using anonymous API access.')
41-
if not kvs.get('user.password'):
42-
return simple_fallback('.githubrc missing user.password. Using anonymous API access.')
43-
return Github(kvs['user.login'], kvs['user.password'])
42+
43+
password = kvs.get('user.password')
44+
token = kvs.get('user.token')
45+
46+
if password and token:
47+
raise OnlyPasswordOrToken('Only specify user.token or user.password '
48+
'in your .githubrc file (got both)')
49+
50+
auth = token or password
51+
52+
if not auth:
53+
return simple_fallback('.githubrc has neither user.password nor user.token.'
54+
'Using anonymous API access.')
55+
return Github(login, auth)
4456
else:
4557
return Github()
4658

@@ -51,6 +63,9 @@ class NoRemoteError(Exception):
5163
class UnknownPullRequestError(Exception):
5264
pass
5365

66+
class OnlyPasswordOrToken(Exception):
67+
pass
68+
5469

5570
def get_pr_repo(num):
5671
"""Returns (owner, repo, num) for the PR number for this git repo.

0 commit comments

Comments
 (0)