@@ -917,26 +917,28 @@ jobs:
917917 async function ensureLabel(name) {
918918 try {
919919 await github.rest.issues.getLabel({ owner, repo, name });
920- return;
920+ return true ;
921921 } catch (err) {
922922 if (err.status !== 404) {
923923 core.warning(`Failed to look up label "${name}": ${err.message || err}`);
924- return;
924+ return false ;
925925 }
926926 }
927927 const meta = AREA_LABELS[name];
928- if (!meta) return;
928+ if (!meta) return false ;
929929 try {
930930 await github.rest.issues.createLabel({
931931 owner, repo, name, color: meta.color, description: meta.description,
932932 });
933933 core.info(`Created label "${name}".`);
934+ return true;
934935 } catch (err) {
935936 if (err.status === 422) {
936937 core.info(`Label "${name}" appeared concurrently; continuing.`);
937- return;
938+ return true ;
938939 }
939940 core.warning(`Failed to create label "${name}": ${err.message || err}`);
941+ return false;
940942 }
941943 }
942944
@@ -946,9 +948,9 @@ jobs:
946948 heuristicBody: areaHeuristicBody,
947949 labels,
948950 });
949- const areaLabelsToAdd = areaLabels.filter((name) => !labels.includes(name)) ;
950- for (const name of areaLabelsToAdd ) {
951- await ensureLabel(name);
951+ const areaLabelsToAdd = [] ;
952+ for (const name of areaLabels.filter((candidate) => !labels.includes(candidate)) ) {
953+ if ( await ensureLabel(name)) areaLabelsToAdd.push (name);
952954 }
953955 if (areaLabelsToAdd.length > 0) {
954956 try {
@@ -1132,7 +1134,9 @@ jobs:
11321134 if : github.event_name == 'workflow_dispatch' && inputs.backfill_open_areas == true
11331135 runs-on : ubuntu-latest
11341136 permissions :
1137+ # Read-only checkout of trusted scripts from the default branch.
11351138 contents : read
1139+ # Required to list open issues, create missing area labels, and apply them.
11361140 issues : write
11371141 steps :
11381142 - name : Checkout trusted workflow code
@@ -1182,23 +1186,25 @@ jobs:
11821186 async function ensureLabel(name) {
11831187 try {
11841188 await github.rest.issues.getLabel({ owner, repo, name });
1185- return;
1189+ return true ;
11861190 } catch (err) {
11871191 if (err.status !== 404) {
11881192 core.warning(`Failed to look up label "${name}": ${err.message || err}`);
1189- return;
1193+ return false ;
11901194 }
11911195 }
11921196 const meta = AREA_LABELS[name];
1193- if (!meta) return;
1197+ if (!meta) return false ;
11941198 try {
11951199 await github.rest.issues.createLabel({
11961200 owner, repo, name, color: meta.color, description: meta.description,
11971201 });
11981202 core.info(`Created label "${name}".`);
1203+ return true;
11991204 } catch (err) {
1200- if (err.status === 422) return;
1205+ if (err.status === 422) return true ;
12011206 core.warning(`Failed to create label "${name}": ${err.message || err}`);
1207+ return false;
12021208 }
12031209 }
12041210
@@ -1229,11 +1235,11 @@ jobs:
12291235 heuristicBody: areaHeuristicBody,
12301236 labels,
12311237 });
1232- const toAdd = areaLabels.filter((name) => !labels.includes(name));
1233- if (toAdd.length === 0) continue;
1234- for (const name of toAdd) {
1235- await ensureLabel(name);
1238+ const toAdd = [];
1239+ for (const name of areaLabels.filter((candidate) => !labels.includes(candidate))) {
1240+ if (await ensureLabel(name)) toAdd.push(name);
12361241 }
1242+ if (toAdd.length === 0) continue;
12371243 try {
12381244 await github.rest.issues.addLabels({
12391245 owner,
0 commit comments