Skip to content

Commit

Permalink
Merge pull request #154 from gisce/improve_github_token_exceptions
Browse files Browse the repository at this point in the history
Raise explicit errors on github token not provided or expired
  • Loading branch information
ecarreras authored Jul 19, 2024
2 parents 8ed0e84 + cbf791f commit 03d83e8
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion apply_pr/fabfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,25 @@
output[k] = False


def is_github_token_valid(token):
headers = {'Authorization': 'token {token}'.format(token=token)}
url = "https://api.github.com/user"

r = requests.get(url, headers=headers)

return r.status_code == 200


def github_config(**config):
return config_from_environment('GITHUB', ['token'], **config)
def validate(_config):
if 'token' not in _config or not _config['token']:
raise EnvironmentError("GITHUB_TOKEN variable not provided")
if not is_github_token_valid(_config['token']):
raise EnvironmentError("GITHUB_TOKEN not valid or expired")

res = config_from_environment('GITHUB', ['token'], **config)
validate(res)
return res


def apply_pr_config(**config):
Expand Down

0 comments on commit 03d83e8

Please sign in to comment.