diff --git a/README.en-US.md b/README.en-US.md index 2ff330a..49770ef 100644 --- a/README.en-US.md +++ b/README.en-US.md @@ -360,14 +360,14 @@ jobs: #### `mark-duplicate` -Quickly mark duplicate questions, only for issue new comments. +Quickly mark duplicate questions, only for issue new comments or edit comments. ```yml name: Issue Mark Duplicate on: issue_comment: - types: [created] + types: [created, edited] jobs: mark-duplicate: diff --git a/README.md b/README.md index c7257dd..9986a06 100644 --- a/README.md +++ b/README.md @@ -360,14 +360,14 @@ jobs: #### `mark-duplicate` -快捷标记重复问题,仅作用于 issue 新增评论。 +快捷标记重复问题,仅作用于 issue 新增编辑评论。 ```yml name: Issue Mark Duplicate on: issue_comment: - types: [created] + types: [created, edited] jobs: mark-duplicate: diff --git a/dist/index.js b/dist/index.js index 1a1657d..8b92b91 100644 --- a/dist/index.js +++ b/dist/index.js @@ -8026,55 +8026,55 @@ async function doMarkDuplicate (owner, repo, labels) { core.info(`This actions only support on 'issue_comment'!`); return false; } - if (context.payload.action != 'created') { - core.info(`This actions only support on 'issue_comment' created!`); - return false; - } - const duplicateCommand = core.getInput("duplicate-command"); - const duplicateLabels = core.getInput("duplicate-labels"); - const removeLables = core.getInput("remove-labels"); - const closeIssue = core.getInput("close-issue"); + if (context.payload.action == 'created' || context.payload.action == 'edited') { + const duplicateCommand = core.getInput("duplicate-command"); + const duplicateLabels = core.getInput("duplicate-labels"); + const removeLables = core.getInput("remove-labels"); + const closeIssue = core.getInput("close-issue"); - const commentId = context.payload.comment.id; - const commentBody = context.payload.comment.body; - const issueNumber = context.payload.issue.number; + const commentId = context.payload.comment.id; + const commentBody = context.payload.comment.body; + const issueNumber = context.payload.issue.number; - const ifCommandInput = !!duplicateCommand; + const ifCommandInput = !!duplicateCommand; - if (!commentBody.includes('?') && ((ifCommandInput && commentBody.startsWith(duplicateCommand) && commentBody.split(' ')[0] == duplicateCommand) || testDuplicate(commentBody))) { - if (ifCommandInput) { - const nextBody = commentBody.replace(duplicateCommand, 'Duplicate of'); - await doUpdateComment(owner, repo, commentId, nextBody, 'replace', true); - } else if (contents) { - await doCreateCommentContent(owner, repo, commentId, dealStringToArr(contents)); - } + if (!commentBody.includes('?') && ((ifCommandInput && commentBody.startsWith(duplicateCommand) && commentBody.split(' ')[0] == duplicateCommand) || testDuplicate(commentBody))) { + if (ifCommandInput) { + const nextBody = commentBody.replace(duplicateCommand, 'Duplicate of'); + await doUpdateComment(owner, repo, commentId, nextBody, 'replace', true); + } else if (contents) { + await doCreateCommentContent(owner, repo, commentId, dealStringToArr(contents)); + } - const issue = await octokit.issues.get({ - owner, - repo, - issue_number: issueNumber - }); - let newLabels = []; - if (issue.data.labels.length > 0) { - newLabels = issue.data.labels.map(({ name }) => name).filter(name => !dealStringToArr(removeLables).includes(name)); - } - if (duplicateLabels) { - newLabels = [...newLabels, ...dealStringToArr(duplicateLabels)]; - } - if (labels) { - newLabels = dealStringToArr(labels); - } - if (newLabels.length > 0) { - await doSetLabels(owner, repo, issueNumber, newLabels.toString()); - core.info(`Actions: [mark-duplicate-labels][${newLabels}] success!`); - } + const issue = await octokit.issues.get({ + owner, + repo, + issue_number: issueNumber + }); + let newLabels = []; + if (issue.data.labels.length > 0) { + newLabels = issue.data.labels.map(({ name }) => name).filter(name => !dealStringToArr(removeLables).includes(name)); + } + if (duplicateLabels) { + newLabels = [...newLabels, ...dealStringToArr(duplicateLabels)]; + } + if (labels) { + newLabels = dealStringToArr(labels); + } + if (newLabels.length > 0) { + await doSetLabels(owner, repo, issueNumber, newLabels.toString()); + core.info(`Actions: [mark-duplicate-labels][${newLabels}] success!`); + } - if (closeIssue == 'true') { - await doCloseIssue(owner, repo, issueNumber); + if (closeIssue == 'true') { + await doCloseIssue(owner, repo, issueNumber); + } + } else { + core.info(`This comment body should start whith 'duplicate-command' or 'Duplicate of' and not include '?'`); } } else { - core.info(`This comment body should start whith 'duplicate-command' or 'Duplicate of' and not include '?'`); + core.info(`This actions only support on 'issue_comment' created or edited!`); } }; diff --git a/docs/base.en-US.md b/docs/base.en-US.md index 0f6a19b..3b9fe24 100644 --- a/docs/base.en-US.md +++ b/docs/base.en-US.md @@ -234,14 +234,14 @@ jobs: ## `mark-duplicate` -Quickly mark duplicate questions, only for issue new comments. +Quickly mark duplicate questions, only for issue new comments or edit comments. ```yml name: Issue Mark Duplicate on: issue_comment: - types: [created] + types: [created, edited] jobs: mark-duplicate: diff --git a/docs/base.md b/docs/base.md index cb7a545..0314c5b 100644 --- a/docs/base.md +++ b/docs/base.md @@ -234,14 +234,14 @@ jobs: ## `mark-duplicate` -快捷标记重复问题,仅作用于 issue 新增评论。 +快捷标记重复问题,仅作用于 issue 新增编辑评论。 ```yml name: Issue Mark Duplicate on: issue_comment: - types: [created] + types: [created, edited] jobs: mark-duplicate: diff --git a/src/base.js b/src/base.js index 2d2a1bc..aadd261 100644 --- a/src/base.js +++ b/src/base.js @@ -155,55 +155,55 @@ async function doMarkDuplicate (owner, repo, labels) { core.info(`This actions only support on 'issue_comment'!`); return false; } - if (context.payload.action != 'created') { - core.info(`This actions only support on 'issue_comment' created!`); - return false; - } - const duplicateCommand = core.getInput("duplicate-command"); - const duplicateLabels = core.getInput("duplicate-labels"); - const removeLables = core.getInput("remove-labels"); - const closeIssue = core.getInput("close-issue"); + if (context.payload.action == 'created' || context.payload.action == 'edited') { + const duplicateCommand = core.getInput("duplicate-command"); + const duplicateLabels = core.getInput("duplicate-labels"); + const removeLables = core.getInput("remove-labels"); + const closeIssue = core.getInput("close-issue"); - const commentId = context.payload.comment.id; - const commentBody = context.payload.comment.body; - const issueNumber = context.payload.issue.number; + const commentId = context.payload.comment.id; + const commentBody = context.payload.comment.body; + const issueNumber = context.payload.issue.number; - const ifCommandInput = !!duplicateCommand; + const ifCommandInput = !!duplicateCommand; - if (!commentBody.includes('?') && ((ifCommandInput && commentBody.startsWith(duplicateCommand) && commentBody.split(' ')[0] == duplicateCommand) || testDuplicate(commentBody))) { - if (ifCommandInput) { - const nextBody = commentBody.replace(duplicateCommand, 'Duplicate of'); - await doUpdateComment(owner, repo, commentId, nextBody, 'replace', true); - } else if (contents) { - await doCreateCommentContent(owner, repo, commentId, dealStringToArr(contents)); - } + if (!commentBody.includes('?') && ((ifCommandInput && commentBody.startsWith(duplicateCommand) && commentBody.split(' ')[0] == duplicateCommand) || testDuplicate(commentBody))) { + if (ifCommandInput) { + const nextBody = commentBody.replace(duplicateCommand, 'Duplicate of'); + await doUpdateComment(owner, repo, commentId, nextBody, 'replace', true); + } else if (contents) { + await doCreateCommentContent(owner, repo, commentId, dealStringToArr(contents)); + } - const issue = await octokit.issues.get({ - owner, - repo, - issue_number: issueNumber - }); - let newLabels = []; - if (issue.data.labels.length > 0) { - newLabels = issue.data.labels.map(({ name }) => name).filter(name => !dealStringToArr(removeLables).includes(name)); - } - if (duplicateLabels) { - newLabels = [...newLabels, ...dealStringToArr(duplicateLabels)]; - } - if (labels) { - newLabels = dealStringToArr(labels); - } - if (newLabels.length > 0) { - await doSetLabels(owner, repo, issueNumber, newLabels.toString()); - core.info(`Actions: [mark-duplicate-labels][${newLabels}] success!`); - } + const issue = await octokit.issues.get({ + owner, + repo, + issue_number: issueNumber + }); + let newLabels = []; + if (issue.data.labels.length > 0) { + newLabels = issue.data.labels.map(({ name }) => name).filter(name => !dealStringToArr(removeLables).includes(name)); + } + if (duplicateLabels) { + newLabels = [...newLabels, ...dealStringToArr(duplicateLabels)]; + } + if (labels) { + newLabels = dealStringToArr(labels); + } + if (newLabels.length > 0) { + await doSetLabels(owner, repo, issueNumber, newLabels.toString()); + core.info(`Actions: [mark-duplicate-labels][${newLabels}] success!`); + } - if (closeIssue == 'true') { - await doCloseIssue(owner, repo, issueNumber); + if (closeIssue == 'true') { + await doCloseIssue(owner, repo, issueNumber); + } + } else { + core.info(`This comment body should start whith 'duplicate-command' or 'Duplicate of' and not include '?'`); } } else { - core.info(`This comment body should start whith 'duplicate-command' or 'Duplicate of' and not include '?'`); + core.info(`This actions only support on 'issue_comment' created or edited!`); } };