From 6f37d9cf54015aea96ac01c26604d9464fc21963 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=85=83=E5=87=9B?= Date: Fri, 29 Oct 2021 15:23:00 +0800 Subject: [PATCH] fix: add remove --- README.md | 3 +++ dist/index.js | 13 +++++++++++++ src/main.ts | 15 +++++++++++++++ 3 files changed, 31 insertions(+) diff --git a/README.md b/README.md index 8e1a747..4b16462 100644 --- a/README.md +++ b/README.md @@ -37,6 +37,9 @@ jobs: | format | PR label format. Default `pr(${type})` | string | ✖ | | extra | Extra replacement | string | ✖ | +- `${type}` will replace the real PR title type. +- `pr-${type}-${type}` is not support. + ## ⚡ Feedback You are very welcome to try it out and put forward your comments. You can use the following methods: diff --git a/dist/index.js b/dist/index.js index 12780e3..60d7139 100644 --- a/dist/index.js +++ b/dist/index.js @@ -9777,6 +9777,19 @@ function run() { core.info(`[AC] 🎁 This PR already has ${needLabel}.`); } else { + const [b, e] = format.split('${type}'); + const removeLabels = prLabels.filter(name => name.startsWith(b) && name.endsWith(e)); + if (removeLabels.length) { + for (const label of removeLabels) { + yield octokit.issues.removeLabel({ + owner, + repo, + issue_number: number, + name: label, + }); + core.info(`[AC] 🔔 This PR remove ${label} success.`); + } + } yield octokit.issues.addLabels({ owner, repo, diff --git a/src/main.ts b/src/main.ts index 002b339..e483a76 100644 --- a/src/main.ts +++ b/src/main.ts @@ -52,6 +52,21 @@ async function run(): Promise { if (prLabels.indexOf(needLabel) > -1) { core.info(`[AC] 🎁 This PR already has ${needLabel}.`); } else { + const [b, e] = format.split('${type}'); + const removeLabels = prLabels.filter(name => name.startsWith(b) && name.endsWith(e)); + + if (removeLabels.length) { + for (const label of removeLabels) { + await octokit.issues.removeLabel({ + owner, + repo, + issue_number: number, + name: label, + }); + core.info(`[AC] 🔔 This PR remove ${label} success.`); + } + } + await octokit.issues.addLabels({ owner, repo,