Skip to content

Commit 5099986

Browse files
authored
fix: use GitHub Actions API for workflow re-runs (#327)
Replace Check Runs API with Actions API for re-running workflows after accepting repository invitations. The Check Runs API is designed for GitHub Apps while the Actions API properly re-runs GitHub Actions workflows. Changes: - Use /actions/runs endpoint to find failed workflows by head SHA - Use /actions/runs/{id}/rerun to trigger re-runs - Filter for failed status to only re-run relevant workflows
1 parent d204d0e commit 5099986

File tree

1 file changed

+20
-9
lines changed

1 file changed

+20
-9
lines changed

src/helpers/invitationProcessor.js

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -166,9 +166,10 @@ async function triggerDocumentationPRChecks(token, acceptedRepos) {
166166
}
167167
);
168168

169-
// Trigger workflow re-run by re-requesting check runs
170-
const checksResponse = await fetch(
171-
`${GITHUB_API_BASE}/repos/${DOCUMENTATION_REPO}/commits/${pr.head.sha}/check-runs`,
169+
// Trigger workflow re-run using GitHub Actions API
170+
// Find the most recent workflow run for this PR's head SHA
171+
const runsResponse = await fetch(
172+
`${GITHUB_API_BASE}/repos/${DOCUMENTATION_REPO}/actions/runs?head_sha=${pr.head.sha}&status=failure`,
172173
{
173174
headers: {
174175
Authorization: `Bearer ${token}`,
@@ -177,12 +178,12 @@ async function triggerDocumentationPRChecks(token, acceptedRepos) {
177178
}
178179
);
179180

180-
if (checksResponse.ok) {
181-
const checks = await checksResponse.json();
182-
for (const check of checks.check_runs || []) {
183-
// Re-run the check
184-
await fetch(
185-
`${GITHUB_API_BASE}/repos/${DOCUMENTATION_REPO}/check-runs/${check.id}/rerequest`,
181+
if (runsResponse.ok) {
182+
const runs = await runsResponse.json();
183+
for (const run of runs.workflow_runs || []) {
184+
// Re-run the failed workflow
185+
const rerunResponse = await fetch(
186+
`${GITHUB_API_BASE}/repos/${DOCUMENTATION_REPO}/actions/runs/${run.id}/rerun`,
186187
{
187188
method: 'POST',
188189
headers: {
@@ -191,6 +192,16 @@ async function triggerDocumentationPRChecks(token, acceptedRepos) {
191192
},
192193
}
193194
);
195+
196+
if (rerunResponse.ok || rerunResponse.status === 201) {
197+
console.log(
198+
`[Invitations] ✅ Re-triggered workflow run ${run.id} for PR #${pr.number}`
199+
);
200+
} else {
201+
console.error(
202+
`[Invitations] ❌ Failed to re-run workflow ${run.id}: ${rerunResponse.status}`
203+
);
204+
}
194205
}
195206
}
196207
}

0 commit comments

Comments
 (0)