|  | 
| 11 | 11 |     search_issues(search_query: str, github_connection: github3.GitHub) | 
| 12 | 12 |         -> github3.structs.SearchIterator: | 
| 13 | 13 |         Searches for issues in a GitHub repository that match the given search query. | 
| 14 |  | -    auth_to_github() -> github3.GitHub: Connect to GitHub API with token authentication. | 
| 15 | 14 |     get_per_issue_metrics(issues: Union[List[dict], List[github3.issues.Issue]], | 
| 16 | 15 |         discussions: bool = False), labels: Union[List[str], None] = None, | 
| 17 | 16 |         ignore_users: List[str] = [] -> tuple[List, int, int]: | 
|  | 
| 25 | 24 | from typing import List, Union | 
| 26 | 25 | 
 | 
| 27 | 26 | import github3 | 
|  | 27 | +from auth import auth_to_github, get_github_app_installation_token | 
| 28 | 28 | from classes import IssueWithMetrics | 
| 29 | 29 | from config import EnvVars, get_env_vars | 
| 30 | 30 | from discussions import get_discussions | 
| @@ -92,38 +92,6 @@ def search_issues( | 
| 92 | 92 |     return issues | 
| 93 | 93 | 
 | 
| 94 | 94 | 
 | 
| 95 |  | -def auth_to_github( | 
| 96 |  | -    gh_app_id: str, | 
| 97 |  | -    gh_app_installation_id: int, | 
| 98 |  | -    gh_app_private_key_bytes: bytes, | 
| 99 |  | -    token: str, | 
| 100 |  | -    ghe: str, | 
| 101 |  | -) -> github3.GitHub: | 
| 102 |  | -    """ | 
| 103 |  | -    Connect to GitHub.com or GitHub Enterprise, depending on env variables. | 
| 104 |  | -
 | 
| 105 |  | -    Returns: | 
| 106 |  | -        github3.GitHub: A github api connection. | 
| 107 |  | -    """ | 
| 108 |  | - | 
| 109 |  | -    if gh_app_id and gh_app_private_key_bytes and gh_app_installation_id: | 
| 110 |  | -        gh = github3.github.GitHub() | 
| 111 |  | -        gh.login_as_app_installation( | 
| 112 |  | -            gh_app_private_key_bytes, gh_app_id, gh_app_installation_id | 
| 113 |  | -        ) | 
| 114 |  | -        github_connection = gh | 
| 115 |  | -    elif ghe and token: | 
| 116 |  | -        github_connection = github3.github.GitHubEnterprise(ghe, token=token) | 
| 117 |  | -    elif token: | 
| 118 |  | -        github_connection = github3.login(token=token) | 
| 119 |  | -    else: | 
| 120 |  | -        raise ValueError( | 
| 121 |  | -            "GH_TOKEN or the set of [GH_APP_ID, GH_APP_INSTALLATION_ID, GH_APP_PRIVATE_KEY] environment variables are not set" | 
| 122 |  | -        ) | 
| 123 |  | - | 
| 124 |  | -    return github_connection  # type: ignore | 
| 125 |  | - | 
| 126 |  | - | 
| 127 | 95 | def get_per_issue_metrics( | 
| 128 | 96 |     issues: Union[List[dict], List[github3.search.IssueSearchResult]],  # type: ignore | 
| 129 | 97 |     env_vars: EnvVars, | 
| @@ -175,9 +143,9 @@ def get_per_issue_metrics( | 
| 175 | 143 |                 issue_with_metrics.mentor_activity = count_comments_per_user( | 
| 176 | 144 |                     None, | 
| 177 | 145 |                     issue, | 
| 178 |  | -                    ignore_users, | 
| 179 | 146 |                     None, | 
| 180 | 147 |                     None, | 
|  | 148 | +                    ignore_users, | 
| 181 | 149 |                     max_comments_to_eval, | 
| 182 | 150 |                     heavily_involved, | 
| 183 | 151 |                 ) | 
| @@ -289,11 +257,20 @@ def main(): | 
| 289 | 257 |     token = env_vars.gh_token | 
| 290 | 258 |     ignore_users = env_vars.ignore_users | 
| 291 | 259 | 
 | 
|  | 260 | +    gh_app_id = env_vars.gh_app_id | 
|  | 261 | +    gh_app_installation_id = env_vars.gh_app_installation_id | 
|  | 262 | +    gh_app_private_key_bytes = env_vars.gh_app_private_key_bytes | 
|  | 263 | + | 
|  | 264 | +    if not token and gh_app_id and gh_app_installation_id and gh_app_private_key_bytes: | 
|  | 265 | +        token = get_github_app_installation_token( | 
|  | 266 | +            gh_app_id, gh_app_private_key_bytes, gh_app_installation_id | 
|  | 267 | +        ) | 
|  | 268 | + | 
| 292 | 269 |     # Auth to GitHub.com | 
| 293 | 270 |     github_connection = auth_to_github( | 
| 294 |  | -        env_vars.gh_app_id, | 
| 295 |  | -        env_vars.gh_app_installation_id, | 
| 296 |  | -        env_vars.gh_app_private_key_bytes, | 
|  | 271 | +        gh_app_id, | 
|  | 272 | +        gh_app_installation_id, | 
|  | 273 | +        gh_app_private_key_bytes, | 
| 297 | 274 |         token, | 
| 298 | 275 |         env_vars.ghe, | 
| 299 | 276 |     ) | 
|  | 
0 commit comments