Skip to content

Commit 46bc982

Browse files
committed
Move gh token env var to function
We don't always need to use the GITHUB_TOKEN during tests, so let's make it an explicit call if we need it
1 parent 29bde6f commit 46bc982

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

_conferences/__main__.py

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,19 @@
99
from github.Issue import Issue
1010
from github.PaginatedList import PaginatedList
1111

12-
TOKEN = os.getenv("GITHUB_TOKEN", "")
1312
ROOT = Path(__file__).parent.parent
1413
conferences_path = ROOT / "_data/conferences.yml"
1514

16-
auth = Auth.Token(TOKEN)
17-
g = Github(auth=auth)
1815

16+
def create_github_client():
17+
gh_token = os.getenv("GITHUB_TOKEN", "")
18+
auth = Auth.Token(gh_token)
19+
g = Github(auth=auth)
20+
return g
1921

20-
def get_open_issues() -> PaginatedList[Issue]:
21-
repo = g.get_repo("BlackPythonDevs/blackpythondevs.github.io")
22+
23+
def get_open_issues(gh: Github) -> PaginatedList[Issue]:
24+
repo = gh.get_repo("BlackPythonDevs/blackpythondevs.github.io")
2225
issues = repo.get_issues(state="open", labels=["conference"])
2326
return issues
2427

@@ -98,8 +101,11 @@ def write_conferences_to_file(confs: list[dict]):
98101
if __name__ == "__main__":
99102
conferences = []
100103

104+
# Create Github client object
105+
gh_client = create_github_client()
106+
101107
# Get open issues from repo
102-
open_issues: PaginatedList[Issue] = get_open_issues()
108+
open_issues: PaginatedList[Issue] = get_open_issues(gh_client)
103109

104110
# Parse each conference issue so long as it has the "conference" label
105111
for issue in open_issues:

0 commit comments

Comments
 (0)