Skip to content

Commit fc67d02

Browse files
authored
Chore: [AEA-0000] - get fork pr contributor approval (#67)
## Summary - Routine Change ### Details - get fork pr contributor approval
1 parent 252ab0c commit fc67d02

2 files changed

Lines changed: 18 additions & 2 deletions

File tree

packages/get_repo_status/app/cli.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ def main(argv: List[str] | None = None) -> None:
5656
asdf_version = (client.get_asdf_version(repo),)
5757
devcontainer_details = client.get_devcontainer_details(repo)
5858
commits_since_last_release = client.get_commits_since_last_release(repo)
59+
fork_pr_contributor_approval = client.get_fork_pr_contributor_approval(repo)
5960

6061
results.append(
6162
{
@@ -101,6 +102,7 @@ def main(argv: List[str] | None = None) -> None:
101102
"devcontainer_image_version": devcontainer_details.get("IMAGE_VERSION"),
102103
"commits_since_last_release": commits_since_last_release,
103104
"main_branch": repo["mainBranch"],
105+
"fork_pr_contributor_approval": fork_pr_contributor_approval,
104106
}
105107
)
106108

packages/get_repo_status/app/github_client.py

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import json
66
from typing import Any, Dict, List, Optional, Tuple, TypedDict
77

8-
from github import Auth, Github
8+
from github import Auth, Github, Repository
99
from github.GithubException import GithubException
1010

1111
from . import Repo
@@ -49,6 +49,20 @@ def get_pull_requests(self, repo: Repo) -> Tuple[int, int]:
4949
print(f"Error fetching pull requests for {repo_name}: {exc}")
5050
return -1, -1
5151

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+
5266
def get_dependabot_alerts(self, repo: Repo) -> Dict[str, int]:
5367
repo_name = repo["repoUrl"]
5468
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
342356
print(f"Error fetching {path} for {repo_name}: {exc}")
343357
return None
344358

345-
def _safe_get_repo(self, repo_name: str) -> Optional[Any]:
359+
def _safe_get_repo(self, repo_name: str) -> Optional[Repository.Repository]:
346360
try:
347361
return self.github.get_repo(repo_name)
348362
except Exception as exc: # pylint: disable=broad-except

0 commit comments

Comments
 (0)