Approve GitHub Actions workflow runs on /ok-to-test#612
Conversation
✅ Deploy Preview for k8s-prow ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
|
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: cblecker The full list of commands accepted by this bot can be found here. The pull request process is described here DetailsNeeds approval from an approver in each of these files:
Approvers can indicate their approval by writing |
Add automatic approval of pending GitHub Actions workflow runs when /ok-to-test is issued by a trusted user with TriggerGitHubWorkflows enabled. Changes: - Add GetPendingApprovalActionRuns and ApproveGitHubWorkflowRun methods to GitHub client - Update trigger plugin interface to include new methods - Add approval logic in generic-comment handler for /ok-to-test command - Implement fake client methods for testing - Add comprehensive unit tests for all new functionality The approval: - Only triggers on /ok-to-test (not /test all or /retest) - Only approves pull_request and pull_request_target triggered workflows - Handles errors gracefully (403/404 logged at info level) - Logs SHA for debugging PR head sync issues - Uses goroutines for non-blocking approval Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
0cb79d4 to
0f2446a
Compare
|
/lgtm |
|
@cblecker would this be implemented for a net-new project by adding an entry to |
|
@stevehipwell Yup, that should be all it takes. No side effects that I've seen so far. |
|
@cblecker for clarity, I meant what (if any) are the side effects of adding a repo to triggers not specifically the GitHub automation setting. |
|
@cblecker I'm just checking that by adding repos ( |
|
@stevehipwell No, I am not aware of any side effects. That doesn't mean you might not find any as we're all just humans working with code, but to the best of my knowledge and experience, this is pretty straight forward. If you do find anything strange, feel free to open an issue. 😄 |
Summary
When
/ok-to-testis issued by a trusted user andTriggerGitHubWorkflowsis enabled, automatically approve any pending GitHub Actions workflow runs for the PR. This enables a unified workflow where/ok-to-testboth triggers Prow jobs AND approves GitHub Actions workflows from fork PRs.Changes
GitHub Client (
pkg/github/client.go)GetPendingApprovalActionRunsmethod to retrieve workflow runs withstatus=action_requiredfor a PR's head SHAApproveGitHubWorkflowRunmethod to approve pending workflow runs via GitHub APIClientinterface to include both new methodsTrigger Plugin (
pkg/plugins/trigger/)generic-comment.gothat triggers on/ok-to-testwhenTriggerGitHubWorkflows=trueapproveGitHubActionsWorkflowRunshelper function that:githubClientinterface intrigger.goto include new methodsFake Client (
pkg/github/fakegithub/fakegithub.go)PendingApprovalRunsfield to track pending runs by "org/repo/branch/sha"ApprovedWorkflowRunsfield to track approval attemptsTests
GitHub Client Tests (
pkg/github/client_test.go):TestGetPendingApprovalActionRuns- Verifies API calls with correct query parameters (status=action_required, event filters)TestApproveGitHubWorkflowRun- Tests successful approval and error cases (201, 403, 404)Trigger Plugin Tests (
pkg/plugins/trigger/generic-comment_test.go):TestApproveGitHubActionsWorkflowRuns- Comprehensive test covering:/ok-to-testwithTriggerGitHubWorkflows=true✓TriggerGitHubWorkflows=false✓/test allor/retest✓IgnoreOkToTest=true✓Behavior
When approval is triggered:
/ok-to-testcommand (not/test allor/retest)TriggerGitHubWorkflowsconfiguration flag is enabledpull_requestandpull_request_targettriggered workflowsError handling:
/ok-to-testcommand from proceedingDesign rationale:
TriggerGitHubWorkflowsflag (semantic expansion - existing users automatically get this behavior)/ok-to-testfunctionality isn't impacted by approval failuresTesting
All tests pass:
No regressions in existing test suites: