|
5 | 5 | import json |
6 | 6 | from typing import Any, Dict, List, Optional, Tuple, TypedDict |
7 | 7 |
|
8 | | -from github import Auth, Github |
| 8 | +from github import Auth, Github, Repository |
9 | 9 | from github.GithubException import GithubException |
10 | 10 |
|
11 | 11 | from . import Repo |
@@ -49,6 +49,20 @@ def get_pull_requests(self, repo: Repo) -> Tuple[int, int]: |
49 | 49 | print(f"Error fetching pull requests for {repo_name}: {exc}") |
50 | 50 | return -1, -1 |
51 | 51 |
|
| 52 | + def get_fork_pr_contributor_approval(self, repo: Repo) -> str: |
| 53 | + repo_name = repo["repoUrl"] |
| 54 | + gh_repo = self._safe_get_repo(repo_name) |
| 55 | + if gh_repo is None: |
| 56 | + return "Error" |
| 57 | + try: |
| 58 | + approval_policy = gh_repo.requester.requestJsonAndCheck( |
| 59 | + "GET", gh_repo.url + "/actions/permissions/fork-pr-contributor-approval" |
| 60 | + ) |
| 61 | + return approval_policy[1]["approval_policy"] |
| 62 | + except Exception as exc: # pylint: disable=broad-except |
| 63 | + print(f"Error fetching fork_pr_contributor_approval {repo_name}: {exc}") |
| 64 | + return "Error" |
| 65 | + |
52 | 66 | def get_dependabot_alerts(self, repo: Repo) -> Dict[str, int]: |
53 | 67 | repo_name = repo["repoUrl"] |
54 | 68 | gh_repo = self._safe_get_repo(repo_name) |
@@ -342,7 +356,7 @@ def get_text_file_from_repo(self, repo_name: str, path: str, ref: str) -> Option |
342 | 356 | print(f"Error fetching {path} for {repo_name}: {exc}") |
343 | 357 | return None |
344 | 358 |
|
345 | | - def _safe_get_repo(self, repo_name: str) -> Optional[Any]: |
| 359 | + def _safe_get_repo(self, repo_name: str) -> Optional[Repository.Repository]: |
346 | 360 | try: |
347 | 361 | return self.github.get_repo(repo_name) |
348 | 362 | except Exception as exc: # pylint: disable=broad-except |
|
0 commit comments