66their metrics to a markdown file.
77
88Functions:
9- get_env_vars() -> tuple[str, str] : Get the environment variables for use
9+ get_env_vars() -> EnvVars : Get the environment variables for use
1010 in the script.
1111 search_issues(search_query: str, github_connection: github3.GitHub)
1212 -> github3.structs.SearchIterator:
2121 main(): Run the issue-metrics script.
2222"""
2323
24- import os
2524from os .path import dirname , join
2625import sys
2726from typing import List , Union
4241 get_stats_time_to_first_response ,
4342 measure_time_to_first_response ,
4443)
45-
46-
47- def get_env_vars () -> tuple [str , str , List [str ]]:
48- """
49- Get the environment variables for use in the script.
50-
51- Returns:
52- str: the search query used to filter issues, prs, and discussions
53- str: the github token used to authenticate to github.com
54- List[str]: a list of users to ignore when calculating metrics
55- """
56- search_query = os .getenv ("SEARCH_QUERY" )
57- if not search_query :
58- raise ValueError ("SEARCH_QUERY environment variable not set" )
59-
60- token = os .getenv ("GH_TOKEN" )
61- if not token :
62- raise ValueError ("GITHUB_TOKEN environment variable not set" )
63-
64- ignore_users = os .getenv ("IGNORE_USERS" )
65- if ignore_users :
66- ignore_users = ignore_users .split ("," )
67- else :
68- ignore_users = []
69-
70- return search_query , token , ignore_users
44+ from config import get_env_vars
7145
7246
7347def search_issues (
@@ -123,17 +97,16 @@ def auth_to_github() -> github3.GitHub:
12397 Returns:
12498 github3.GitHub: A github api connection.
12599 """
126- if token := os .getenv ("GH_TOKEN" ):
127- if not os .getenv ("GITHUB_SERVER_URL" ):
128- github_connection = github3 .login (token = token )
129- elif os .getenv ("GITHUB_SERVER_URL" ) == "https://github.com" :
130- github_connection = github3 .login (token = token )
131- else :
132- github_connection = github3 .GitHubEnterprise (
133- os .getenv ("GITHUB_SERVER_URL" ), token = token
134- )
100+ env_vars = get_env_vars ()
101+ token = env_vars .gh_token
102+ github_server_url = env_vars .github_server_url
103+
104+ if github_server_url and github_server_url != "https://github.com" :
105+ github_connection = github3 .GitHubEnterprise (
106+ github_server_url , token = token
107+ )
135108 else :
136- raise ValueError ( "GH_TOKEN environment variable not set" )
109+ github_connection = github3 . login ( token = token )
137110
138111 return github_connection # type: ignore
139112
@@ -269,9 +242,9 @@ def main():
269242
270243 # Get the environment variables for use in the script
271244 env_vars = get_env_vars ()
272- search_query = env_vars [ 0 ]
273- token = env_vars [ 1 ]
274- ignore_users = env_vars [ 2 ]
245+ search_query = env_vars . search_query
246+ token = env_vars . gh_token
247+ ignore_users = env_vars . ignore_users
275248
276249 # Get the repository owner and name from the search query
277250 owner = get_owner (search_query )
@@ -284,7 +257,7 @@ def main():
284257 )
285258
286259 # Determine if there are label to measure
287- labels = os . environ . get ( "LABELS_TO_MEASURE" )
260+ labels = env_vars . labels_to_measure
288261 if labels :
289262 labels = labels .split ("," )
290263 else :
0 commit comments