Add owner and repo_name properties to Actions object (#656)

Co-authored-by: UltralyticsAssistant <[email protected]>
This commit is contained in:
Glenn Jocher
2025-11-16 14:44:35 +01:00
committed by GitHub
co-authored by UltralyticsAssistant
parent 4d8565d037
commit 65e6445fbe
3 changed files with 10 additions and 14 deletions
+2 -3
View File
@@ -39,8 +39,7 @@ SKIP_PATTERN_STRINGS = [
]
SKIP_PATTERNS = tuple(re.compile(pattern) for pattern in SKIP_PATTERN_STRINGS)
MAX_CONTEXT_FILE_CHARS = 5000
MAX_REVIEW_COMMENTS = 10
TARGET_REVIEW_COMMENTS = 5
MAX_REVIEW_COMMENTS = 8
SEVERITY_RANK = {"CRITICAL": 0, "HIGH": 1, "MEDIUM": 2, "LOW": 3, "SUGGESTION": 4, None: 5}
@@ -188,7 +187,7 @@ def generate_pr_review(
"- Extract line numbers from R#### or L#### prefixes in the diff\n"
"- Exact paths (no ./), 'side' field must match R (RIGHT) or L (LEFT) prefix\n"
"- Severity: CRITICAL, HIGH, MEDIUM, LOW, SUGGESTION\n"
f"- Keep feedback concise: {TARGET_REVIEW_COMMENTS} issues max (less is better) with hard cap at {MAX_REVIEW_COMMENTS}\n"
f"- Keep feedback concise: less issues is better with hard cap at {MAX_REVIEW_COMMENTS}\n"
f"- Files changed: {len(file_list)} ({', '.join(file_list[:30])}{'...' if len(file_list) > 30 else ''})\n"
f"- Lines changed: {lines_changed}\n"
)
+3 -2
View File
@@ -139,8 +139,9 @@ def remove_html_comments(body: str) -> str:
def clean_url(url):
"""Remove extra characters from URL strings."""
for _ in range(3):
url = str(url).strip('"').strip("'").rstrip(".,:;!?`\\").replace(".git@main", "").replace("git+", "")
url = str(url).strip('"').strip("'").rstrip(".,:;!?`\\").replace(".git@main", "").replace("git+", "")
# Second pass for nested quotes/punctuation
url = url.strip('"').strip("'").rstrip(".,:;!?`\\")
return url
+5 -9
View File
@@ -114,12 +114,12 @@ class Action:
self.event_data = event_data or self._load_event_data(os.getenv("GITHUB_EVENT_PATH"))
self.pr = self.event_data.get("pull_request", {})
self.repository = self.event_data.get("repository", {}).get("full_name")
self.owner, self.repo_name = self.repository.split("/") if self.repository else (None, None)
self.headers = {"Authorization": f"Bearer {self.token}", "Accept": "application/vnd.github+json"}
self.headers_diff = {"Authorization": f"Bearer {self.token}", "Accept": "application/vnd.github.v3.diff"}
self.verbose = verbose
self.eyes_reaction_id = None
self._pr_diff_cache = None
self._pr_summary_cache = None
self._username_cache = None
self._default_status = {
"get": [200, 204],
@@ -195,7 +195,7 @@ class Action:
def is_org_member(self, username: str) -> bool:
"""Checks if a user is a member of the organization."""
return self.get(f"{GITHUB_API_URL}/orgs/{self.repository.split('/')[0]}/members/{username}").status_code == 204
return self.get(f"{GITHUB_API_URL}/orgs/{self.owner}/members/{username}").status_code == 204
def should_skip_pr_author(self) -> bool:
"""Checks if PR should be skipped based on author (self-authored or bot PRs)."""
@@ -296,12 +296,10 @@ class Action:
updated_description = (description.rstrip() + "\n\n" + new_summary) if description.strip() else new_summary
self.patch(url, json={"body": updated_description})
self._pr_summary_cache = new_summary
def get_label_ids(self, labels: list[str]) -> list[str]:
"""Retrieves GitHub label IDs for a list of label names using the GraphQL API."""
owner, repo = self.repository.split("/")
result = self.graphql_request(GRAPHQL_REPO_LABELS, variables={"owner": owner, "name": repo})
result = self.graphql_request(GRAPHQL_REPO_LABELS, variables={"owner": self.owner, "name": self.repo_name})
if "data" in result and "repository" in result["data"]:
all_labels = result["data"]["repository"]["labels"]["nodes"]
label_map = {label["name"].lower(): label["id"] for label in all_labels}
@@ -378,8 +376,7 @@ class Action:
def block_user(self, username: str):
"""Blocks a user from the organization."""
url = f"{GITHUB_API_URL}/orgs/{self.repository.split('/')[0]}/blocks/{username}"
self.put(url)
self.put(f"{GITHUB_API_URL}/orgs/{self.owner}/blocks/{username}")
def handle_alert(self, number: int, node_id: str, issue_type: str, username: str, block: bool = False):
"""Handles content flagged as alert: updates content, locks, optionally closes and blocks user."""
@@ -402,8 +399,7 @@ Thank you 🙏
def get_pr_contributors(self) -> tuple[str | None, dict]:
"""Gets PR contributors and closing issues, returns (pr_credit_string, pr_data)."""
owner, repo = self.repository.split("/")
variables = {"owner": owner, "repo": repo, "pr_number": self.pr["number"]}
variables = {"owner": self.owner, "repo": self.repo_name, "pr_number": self.pr["number"]}
response = self.post(GITHUB_GRAPHQL_URL, json={"query": GRAPHQL_PR_CONTRIBUTORS, "variables": variables})
if response.status_code != 200:
return None, {}