From ae9de8d13d538b0fd108f1f4e9e81356e088ed1b Mon Sep 17 00:00:00 2001 From: Habil Date: Sat, 3 May 2025 17:28:44 -0400 Subject: [PATCH 1/4] Create main.yml --- .github/workflows/main.yml | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 .github/workflows/main.yml diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml new file mode 100644 index 0000000..0233b96 --- /dev/null +++ b/.github/workflows/main.yml @@ -0,0 +1,23 @@ +name: Extract PR Comment and Files + +on: + issue_comment: + types: [created] + +jobs: + extract: + runs-on: ubuntu-latest + if: github.event.issue.pull_request != null + steps: + - uses: actions/checkout@v4 + - name: Set up Python + uses: actions/setup-python@v5 + with: + python-version: '3.11' + - name: Install dependencies + run: pip install PyGithub + - name: Extract PR comment and files + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: | + python .github/scripts/extract_pr_comment.py From 7c36495260f67f03fd4eb85681b1f0c6776cd4a1 Mon Sep 17 00:00:00 2001 From: Habil Date: Sat, 3 May 2025 17:33:05 -0400 Subject: [PATCH 2/4] Create extract_comment.py --- .github/extract_comment.py | 40 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 .github/extract_comment.py diff --git a/.github/extract_comment.py b/.github/extract_comment.py new file mode 100644 index 0000000..34d76e4 --- /dev/null +++ b/.github/extract_comment.py @@ -0,0 +1,40 @@ +import os +import json +import base64 +from github import Github + +# Path to the GitHub Actions event payload +event_path = os.environ.get("GITHUB_EVENT_PATH") +if not event_path or not os.path.exists(event_path): + print("No event payload found.") + exit(1) + +with open(event_path, "r") as f: + event = json.load(f) + +# Only proceed if this is a PR comment event +if "pull_request" not in event.get("issue", {}): + print("Not a PR comment event.") + exit(0) + +pr_number = event["issue"]["number"] +comment_body = event["comment"]["body"] +repo_full_name = event["repository"]["full_name"] +token = os.environ.get("GITHUB_TOKEN") + +if not token: + print("No GITHUB_TOKEN found in environment.") + exit(1) + +gh = Github(token) +repo = gh.get_repo(repo_full_name) +pr = repo.get_pull(pr_number) + +print(f"Comment: {comment_body}") +print("Changed files and their contents:") + +for file in pr.get_files(): + print(f"\n=== {file.filename} ===") + cf = repo.get_contents(file.filename, ref=pr.head.sha) + content = base64.b64decode(cf.content).decode("utf-8") + print(content) From f628f5bd7c8398dd90004684cc327b716a19d590 Mon Sep 17 00:00:00 2001 From: Habil Date: Sat, 3 May 2025 17:34:23 -0400 Subject: [PATCH 3/4] Update main.yml --- .github/workflows/main.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 0233b96..7743a52 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -20,4 +20,4 @@ jobs: env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} run: | - python .github/scripts/extract_pr_comment.py + python .github/extract_pr_comment.py From b5208fe1dfcee721e118f24a23b4991d8fb736c9 Mon Sep 17 00:00:00 2001 From: Habil Date: Sat, 3 May 2025 17:40:36 -0400 Subject: [PATCH 4/4] Update main.yml --- .github/workflows/main.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 7743a52..0e26de0 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -20,4 +20,4 @@ jobs: env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} run: | - python .github/extract_pr_comment.py + python .github/extract_comment.py