From 3636a1a243149a2cd7d9713f959d6e8a5d256e1f Mon Sep 17 00:00:00 2001 From: Cal Leung Date: Wed, 25 Oct 2023 21:01:45 -0700 Subject: [PATCH] No need to remove label that doesn't exist --- .github/scripts/apply-e2e-label.ts | 39 +++++++++++++++++++----------- 1 file changed, 25 insertions(+), 14 deletions(-) diff --git a/.github/scripts/apply-e2e-label.ts b/.github/scripts/apply-e2e-label.ts index 230d1d06b67..dd8b92c7c15 100644 --- a/.github/scripts/apply-e2e-label.ts +++ b/.github/scripts/apply-e2e-label.ts @@ -30,20 +30,31 @@ async function main(): Promise { const octokit: InstanceType = getOctokit(githubToken); // Remove the label - const removeLabelResponse = await octokit.rest.issues.removeLabel({ - owner: owner, - repo: repo, - issue_number: issue_number, - name: e2eLabel, - }); - - if (removeLabelResponse.status === 200) { - console.log(`Removed (${e2eLabel}) label from PR ${pullRequestLink}`); - } else { - core.setFailed( - `Failed to remove (${e2eLabel}) label from ${pullRequestLink}`, - ); - process.exit(1); + try { + const removeLabelResponse = await octokit.rest.issues.removeLabel({ + owner: owner, + repo: repo, + issue_number: issue_number, + name: e2eLabel, + }); + + if (removeLabelResponse.status === 200) { + console.log(`Removed (${e2eLabel}) label from PR ${pullRequestLink}`); + } else { + core.setFailed( + `Failed to remove (${e2eLabel}) label from ${pullRequestLink}`, + ); + process.exit(1); + } + } catch (error) { + if (error.message.includes('Label does not exist')) { + console.log(`(${e2eLabel}) label does not exist on ${pullRequestLink}, no need to remove`) + } else { + core.setFailed( + `An error occured when attempting to remove (${e2eLabel}) label from ${pullRequestLink}: ${error}`, + ); + process.exit(1); + } } // Reapply the label