Skip to content

Commit b7abc06

Browse files
authored
Merge pull request #21 from alyssacgoins/gatekeeper-workflow
Issue triage workflow.
2 parents 3eb41a4 + be9ac4a commit b7abc06

3 files changed

Lines changed: 75 additions & 1 deletion

File tree

.github/scripts/verify-pr-ready.py

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
#!/usr/bin/env python3
2+
import os
3+
import re
4+
import sys
5+
6+
from github import Auth, Github
7+
8+
def clean_pr_body(body: str) -> str:
9+
if not body:
10+
return ""
11+
clean_text = re.sub(r'<!--.*?-->', '', body, flags=re.DOTALL)
12+
return clean_text.strip()
13+
14+
15+
def main() -> int:
16+
token = os.getenv("GITHUB_TOKEN")
17+
pr_num = int(os.getenv("PR_NUMBER"))
18+
#TODO: GITHUB_REPOSITORY var necessary for testing purposes and can ultimately be removed.
19+
#todo: is repo_name actually being passed in?
20+
repo_name = os.getenv("GITHUB_REPOSITORY")
21+
print(f"Verifying linked issues for PR #{pr_num} in {repo_name}")
22+
23+
g = Github(auth=Auth.Token(token))
24+
repo = g.get_repo(repo_name)
25+
pr = repo.get_pull(pr_num)
26+
27+
# 1. Parse PR body for linked issues (e.g., #123 or Fixes #123)
28+
pr_body_original = pr.body or ""
29+
pr_body = clean_pr_body(pr_body_original)
30+
31+
issue_numbers = re.findall(r"(?:#|issues\/)(\d+)", pr_body)
32+
print(f"Found issue numbers: {issue_numbers}")
33+
34+
if not issue_numbers:
35+
print('ERROR: No linked issues found in the PR description.')
36+
return 1
37+
38+
#2: Check each linked issue for the "ready" command.
39+
# If there is more than one issue linked, each issue must be marked /ready
40+
found_ready = False
41+
for issue_num in issue_numbers:
42+
issue = repo.get_issue(int(issue_num))
43+
comments = issue.get_comments()
44+
45+
# Check if the issue contains a comment with /ready command
46+
for comment in comments:
47+
if "/ready" in comment.body:
48+
print(f"Found '/ready' command in issue #{issue_num}")
49+
found_ready = True
50+
break
51+
if found_ready: break
52+
53+
if not found_ready:
54+
print("ERROR: The linked issue(s) must have a '/ready' command.")
55+
return 1
56+
57+
print(f'Successfully verified linked issues: {issue_numbers}')
58+
return 0
59+
60+
if __name__ == "__main__":
61+
sys.exit(main())

.github/workflows/issue-triage.yml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Triage issues upon opening.
2+
name: issue-triage.yml
3+
4+
on:
5+
issues:
6+
types: [opened]
7+
8+
jobs:
9+
on-issue-opened:
10+
runs-on: ubuntu-latest
11+
steps:
12+
- name: Welcome message
13+
run: echo "A new issue was created!"

.github/workflows/pr-gatekeeper.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ jobs:
3333
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
3434
PR_NUMBER: ${{ github.event.pull_request.number }}
3535
run: |
36-
python3 .github/scripts/verify-linked-issue.py
36+
python3 .github/scripts/verify-pr-ready.py
3737
3838
- name: Retrieve Workflow IDs if Validation Failed
3939
id: workflow-list

0 commit comments

Comments
 (0)