Skip to content

Commit 3aa68b9

Browse files
Copilotpranaygp
andcommitted
Fix API response handling and improve existing PR detection
Co-authored-by: pranaygp <[email protected]>
1 parent 4caf872 commit 3aa68b9

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

.github/workflows/trigger-ci.yml

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -144,14 +144,15 @@ _This PR was last updated in response to the \`/run-ci\` command in #${prDetails
144144
});
145145
} else {
146146
// Existing PR found but it's not labeled as a CI test PR
147-
// Treat it as a new PR scenario
148-
isNewPR = true;
147+
// Use the first one and add the labels
148+
ciPR = existingPRs.data[0];
149+
isNewPR = true; // Treat as new to ensure labels are added
149150
}
150151
}
151152

152-
if (isNewPR || existingPRs.data.length === 0) {
153+
if (!ciPR) {
153154
// Create a new draft PR
154-
ciPR = await github.rest.pulls.create({
155+
const newPR = await github.rest.pulls.create({
155156
owner: context.repo.owner,
156157
repo: context.repo.repo,
157158
title: `[CI Test] ${prDetails.title}`,
@@ -172,11 +173,12 @@ This is an automated PR created to run CI tests for PR #${prDetails.number} by @
172173
_This PR was created in response to the \`/run-ci\` command in #${prDetails.number}_`,
173174
draft: true
174175
});
176+
ciPR = newPR.data;
175177
isNewPR = true;
176178
}
177179

178180
// Ensure labels are present on the CI PR (handles both new and existing PRs)
179-
const currentLabels = ciPR.labels?.map(l => l.name) || [];
181+
const currentLabels = ciPR.labels?.map(l => typeof l === 'string' ? l : l.name) || [];
180182
const requiredLabels = ['ci-test', 'automated'];
181183
const missingLabels = requiredLabels.filter(label => !currentLabels.includes(label));
182184

0 commit comments

Comments
 (0)