-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapi_calls.py
More file actions
35 lines (24 loc) · 984 Bytes
/
Copy pathapi_calls.py
File metadata and controls
35 lines (24 loc) · 984 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import requests
def get_repo_issues(repo: str, state="all"):
### Get all issues from repo in given state
# REST API endpoint for issues in a repo.
# repo has form owner/repo
url = f"https://api.github.com/repos/{repo}/issues"
# Accessing GitHub requires authorisation
kwargs = get_auth_headers()
# Filter based on chosen state
kwargs["params"] = {"state": state}
return requests.get(url, **kwargs)
def get_github_token(secrets_file):
### Get github token from secrets file
github_token = ""
import yaml
from pathlib import Path
with Path(secrets_file).open() as f:
file_contents = yaml.safe_load(f)
if "github_token" in file_contents.keys():
return file_contents["github_token"]
def get_auth_headers():
### Get the authorisation headers required for GitHub access
headers = {"Authorization": f"Bearer {get_github_token('secrets.yml')}"}
return {"headers": headers}