Skip to content
Closed
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion .github/workflows/commit-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: Commit Check

on:
pull_request:
branches: 'main'
branches: [ 'main' ]
workflow_dispatch:

jobs:
Expand All @@ -17,6 +17,7 @@ jobs:
ref: ${{ github.event.pull_request.head.sha }} # checkout PR HEAD commit
fetch-depth: 0 # fetch all history for all branches and tags
- uses: ./ # self test
id: commit-check
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # use GITHUB_TOKEN because of use pr-comments
with:
Expand All @@ -29,3 +30,12 @@ jobs:
imperative: true
job-summary: true
pr-comments: ${{ github.event_name == 'pull_request' }}

- name: Save PR comments to pr-comments.txt
run: echo "${{ steps.commit-check.outputs.pr_comments }}" > pr-comments.txt

- name: Upload pr-comments.txt
uses: actions/upload-artifact@v4
with:
name: commit-check-pr-comments
path: pr-comments.txt
8 changes: 7 additions & 1 deletion action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ inputs:
runs:
using: "composite"
steps:
- name: Install dependencies and run commit-check
- id: run
name: Install dependencies and run commit-check
shell: bash
run: |
if [[ "$RUNNER_OS" == "Linux" ]]; then
Expand Down Expand Up @@ -84,3 +85,8 @@ runs:
DRY_RUN: ${{ inputs.dry-run }}
JOB_SUMMARY: ${{ inputs.job-summary }}
PR_COMMENTS: ${{ inputs.pr-comments }}

outputs:
pr_comments:
description: The formatted PR comment body containing commit-check results
value: ${{ steps.run.outputs.pr_comments }}
4 changes: 4 additions & 0 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,10 @@ def add_pr_comments() -> int:
print(f"Creating a new comment on PR #{pr_number}.")
pull_request.create_comment(body=pr_comments)

# output pr_comments to $GITHUB_OUTPUT
with open(os.environ["GITHUB_OUTPUT"], "a", encoding="utf-8") as output_file:
output_file.write(f"pr_comments={pr_comments}\n")
Copy link
Preview

Copilot AI Aug 19, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The pr_comments variable could contain newlines or special characters that might break the GitHub Actions output format. Consider escaping or encoding the content to ensure proper parsing.

Suggested change
output_file.write(f"pr_comments={pr_comments}\n")
def escape_github_output(value: str) -> str:
"""Escape value for GitHub Actions output."""
return value.replace("%", "%25").replace("\r", "%0D").replace("\n", "%0A")
with open(os.environ["GITHUB_OUTPUT"], "a", encoding="utf-8") as output_file:
output_file.write(f"pr_comments={escape_github_output(pr_comments)}\n")

Copilot uses AI. Check for mistakes.


Copy link
Preview

Copilot AI Aug 19, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The code assumes GITHUB_OUTPUT environment variable exists without checking. This could raise a KeyError if the environment variable is not set. Consider using os.environ.get("GITHUB_OUTPUT") with appropriate error handling.

Suggested change
github_output = os.environ.get("GITHUB_OUTPUT")
if github_output is None:
raise EnvironmentError("GITHUB_OUTPUT environment variable is not set")
with open(github_output, "a", encoding="utf-8") as output_file:
output_file.write(f"pr_comments={pr_comments}\n")

Copilot uses AI. Check for mistakes.

return 0 if result_text is None else 1
except Exception as e:
print(f"Error posting PR comment: {e}", file=sys.stderr)
Expand Down