Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Jul 4, 2025

This PR adds support for commenting on PRs from workflow_run triggered workflows, which is essential for handling PRs from external repositories (forks) where the action runs outside the PR context.

Problem

When using workflow_run to handle external PRs (as recommended in the README), the comment feature doesn't work because context.issue.number is not available in the workflow_run context. This prevents users from getting PR comments with test results for external contributions.

Solution

Added a new optional pr_id input parameter that allows explicitly specifying the PR number to comment on:

- name: Publish Test Report
  uses: mikepenz/action-junit-report@v5
  with:
    comment: true
    pr_id: ${{ github.event.workflow_run.pull_requests[0].number }}
    commit: ${{ github.event.workflow_run.head_sha }}
    report_paths: '**/build/test-results/test/TEST-*.xml'

Key Features

  • Backward Compatible: Existing workflows continue to work unchanged
  • Fallback Logic: Uses pr_id when provided, falls back to context.issue.number
  • Input Validation: Handles invalid pr_id values gracefully with helpful warnings
  • Robust: Trims whitespace and validates numeric input
  • Well Tested: Added comprehensive test suite covering all scenarios including edge cases

Changes Made

  • Added pr_id input parameter to action.yml
  • Modified attachComment() function to accept and use pr_id when context.issue.number is unavailable
  • Updated findPriorComment() to work with the provided issue number
  • Added comprehensive test coverage (8 new tests)
  • Updated README with parameter documentation and workflow_run example

Testing

All existing tests continue to pass (54 total), plus new tests covering:

  • Using pr_id when context.issue.number is unavailable
  • Fallback to context.issue.number when pr_id not provided
  • Invalid pr_id handling with appropriate warnings
  • Whitespace handling in pr_id input
  • Comment updating with pr_id parameter

Fixes #1378.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI changed the title [WIP] add comment to PR from workflow outside of PR Add pr_id parameter to support PR comments from workflow_run contexts Jul 4, 2025
Copilot AI requested a review from mikepenz July 4, 2025 09:53
@mikepenz mikepenz marked this pull request as ready for review July 4, 2025 10:25
@github-actions
Copy link

github-actions bot commented Jul 4, 2025

TestsPassed ☑️SkippedFailed ❌️
Example Pytest Report4 ran2 passed0 skipped2 failed
TestResult
Example Pytest Report
test_sample.test_which_succeeds✅ passed
test_sample.test_which_fails❌ failure
test_sample.test_with_error❌ failure
test_sample.test_with_flaky_success✅ passed

@github-actions
Copy link

github-actions bot commented Jul 4, 2025

TestsPassed ☑️SkippedFailed ❌️
Example Pytest Report4 ran2 passed0 skipped2 failed
TestResult
Example Pytest Report
test_sample.test_which_succeeds✅ passed
test_sample.test_which_fails❌ failure
test_sample.test_with_error❌ failure
test_sample.test_with_flaky_success✅ passed

@github-actions
Copy link

github-actions bot commented Jul 4, 2025

TestsPassed ☑️Skipped ⚠️Failed ❌️
Example Ungrouped Test Report | test_10.xml3 ran3 passed0 skipped0 failed
Example Ungrouped Test Report | test_11.xml3 ran2 passed0 skipped1 failed
Example Ungrouped Test Report | test_12.xml3 ran2 passed1 skipped0 failed

@github-actions
Copy link

github-actions bot commented Jul 4, 2025

TestsPassed ☑️Skipped ⚠️Failed ❌️
Example Ungrouped Test Report | test_10.xml3 ran3 passed0 skipped0 failed
Example Ungrouped Test Report | test_11.xml3 ran2 passed0 skipped1 failed
Example Ungrouped Test Report | test_12.xml3 ran2 passed1 skipped0 failed

@github-actions
Copy link

github-actions bot commented Jul 4, 2025

TestsPassed ✅SkippedFailed
Example Nested JUnit Test Report3 ran3 passed0 skipped0 failed
TestResult
Example Nested JUnit Test Report
ABC-0199: XMPP Ping
PingIntegrationTest.pingAsync (Normal)✅ passed
PingIntegrationTest.pingServer (Normal)✅ passed
ABC-0045: Multi-User Chat
MultiUserIntegrationTest.mucRoleTestForReceivingModerator (Normal)✅ passed

1 similar comment
@github-actions
Copy link

github-actions bot commented Jul 4, 2025

TestsPassed ✅SkippedFailed
Example Nested JUnit Test Report3 ran3 passed0 skipped0 failed
TestResult
Example Nested JUnit Test Report
ABC-0199: XMPP Ping
PingIntegrationTest.pingAsync (Normal)✅ passed
PingIntegrationTest.pingServer (Normal)✅ passed
ABC-0045: Multi-User Chat
MultiUserIntegrationTest.mucRoleTestForReceivingModerator (Normal)✅ passed

@mikepenz mikepenz merged commit d307350 into main Jul 4, 2025
11 of 17 checks passed
@mikepenz mikepenz deleted the copilot/fix-1378 branch July 4, 2025 10:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

add comment to PR from workflow outside of PR

2 participants