Skip to content

Commit bb741df

Browse files
authored
Merge pull request #7 from alyssacgoins/gh-actions-pr-check
GH actions verify PR.
2 parents 3c68726 + beb9423 commit bb741df

2 files changed

Lines changed: 96 additions & 0 deletions

File tree

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
#!/usr/bin/env python3
2+
import os
3+
import re
4+
import sys
5+
6+
from github import Github
7+
8+
def main() -> int:
9+
# Retrieve env vars provided by GH Action workflow
10+
token = os.getenv("GITHUB_TOKEN")
11+
pr_num = int(os.getenv("PR_NUMBER"))
12+
13+
g = Github(token)
14+
#todo: what is the func expecting for input formatting?
15+
repo = g.get_repo("kubeflow/pipelines")
16+
pr = repo.get_pull(pr_num)
17+
18+
# 1. Parse PR body for linked issues (e.g., #123 or Fixes #123)
19+
pr_body = pr.body or ""
20+
issue_numbers = re.findall(r"(?:#|issues\/)(\d+)", pr_body)
21+
22+
if not issue_numbers:
23+
print('ERROR: No linked issues found in the PR description.')
24+
return 1
25+
26+
#2: Check each linked issue for the "ready" command.
27+
# If there is more than one issue linked, each issue must be marked /ready
28+
found_ready = False
29+
for issue_num in issue_numbers:
30+
#todo: case in which issue_num cannot be converted into an int?
31+
issue = repo.get_issue(int(issue_num))
32+
comments = issue.get_comments()
33+
34+
# Check if the issue contains a comment with /ready command
35+
for comment in comments:
36+
if "/ready" in comment.body:
37+
print(f"Found '/ready' command in issue #{issue_num}")
38+
found_ready = True
39+
break
40+
#todo: is there ever a case in which "/ready" is canceled out by a later comment? (ie do not exit here)
41+
if found_ready: break
42+
43+
if not found_ready:
44+
print("ERROR: The linked issue(s) must have a '/ready' command.")
45+
return 1
46+
47+
#todo: add successful return message.
48+
print()
49+
return 0
50+
51+
if __name__ == "__main__":
52+
sys.exit(main())
53+
54+

.github/workflows/verify-pr.yml

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# Validate
2+
name: Verify PR
3+
4+
on:
5+
pull_request:
6+
types: [opened, edited, synchronize, reopened]
7+
8+
jobs:
9+
# JOB 1: Performs the check for non-members
10+
check-issue:
11+
# if: |
12+
# github.event.pull_request.author_association != 'MEMBER' &&
13+
# github.event.pull_request.author_association != 'OWNER'
14+
runs-on: ubuntu-latest
15+
steps:
16+
#todo: I do not believe we need checkout code action, as we use only PR body
17+
- name: Set up Python
18+
uses: actions/setup-python@v4
19+
with:
20+
#todo: verify this version
21+
python-version: "3.10"
22+
23+
- name: Install Dependencies
24+
run: |
25+
pip install ruamel.yaml
26+
27+
- name: Verify Linked Issue is Valid
28+
run: |
29+
python3 .github/scripts/verify-linked-issue.py
30+
31+
# JOB 2: Posts a comment only if the author IS a member
32+
skip-notification:
33+
if: |
34+
github.event.pull_request.author_association == 'MEMBER' ||
35+
github.event.pull_request.author_association == 'OWNER'
36+
runs-on: ubuntu-latest
37+
steps:
38+
- name: Post skip message
39+
uses: thollander/actions-comment-pull-request@v3
40+
with:
41+
message: |
42+
👋 Hello! Since you are a member of the Kubeflow organization, the "Linked Issue" check has been automatically bypassed for this PR.

0 commit comments

Comments
 (0)