From a6c6e82280209afed0081747e178489328813a28 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=85=83=E5=87=9B?= Date: Fri, 23 Sep 2022 14:25:42 +0800 Subject: [PATCH] fix: remove no use label --- dist/index.js | 13 ++++++++++--- src/main.js | 13 ++++++++++--- 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/dist/index.js b/dist/index.js index 7943176..8185192 100644 --- a/dist/index.js +++ b/dist/index.js @@ -11304,7 +11304,7 @@ async function run() { const filterLabel = core.getInput('filter-label'); if (filterLabel) { let arr = []; - for await (let no of issues) { + for await (const no of issues) { const { data: { labels }, } = await octokit.issues.get({ @@ -11333,7 +11333,7 @@ async function run() { return false; } - for await (let issue of issues) { + for await (const issue of issues) { if (labels) { await octokit.issues.addLabels({ owner, @@ -11344,7 +11344,14 @@ async function run() { core.info(`Actions: [add-labels][${issue}][${labels}] success!`); } if (removeLabels && removeLabels.length) { - for (const label of removeLabels) { + const issueInfo = await octokit.issues.get({ + owner, + repo, + issue_number: issue, + }); + const baseLabels = issueInfo.data.labels.map(({ name }) => name); + const removes = baseLabels.filter(name => removeLabels.includes(name)); + for (const label of removes) { await octokit.issues.removeLabel({ owner, repo, diff --git a/src/main.js b/src/main.js index 5b1fea3..3dd1860 100644 --- a/src/main.js +++ b/src/main.js @@ -58,7 +58,7 @@ async function run() { const filterLabel = core.getInput('filter-label'); if (filterLabel) { let arr = []; - for await (let no of issues) { + for await (const no of issues) { const { data: { labels }, } = await octokit.issues.get({ @@ -87,7 +87,7 @@ async function run() { return false; } - for await (let issue of issues) { + for await (const issue of issues) { if (labels) { await octokit.issues.addLabels({ owner, @@ -98,7 +98,14 @@ async function run() { core.info(`Actions: [add-labels][${issue}][${labels}] success!`); } if (removeLabels && removeLabels.length) { - for (const label of removeLabels) { + const issueInfo = await octokit.issues.get({ + owner, + repo, + issue_number: issue, + }); + const baseLabels = issueInfo.data.labels.map(({ name }) => name); + const removes = baseLabels.filter(name => removeLabels.includes(name)); + for (const label of removes) { await octokit.issues.removeLabel({ owner, repo,