diff --git a/README.en-US.md b/README.en-US.md
index 421fb16..ddd549c 100644
--- a/README.en-US.md
+++ b/README.en-US.md
@@ -297,14 +297,14 @@ jobs:
#### `mark-duplicate`
-Quickly mark duplicate issue.
+Quickly mark duplicate questions, only for issue new comments.
```yml
name: Issue Mark Duplicate
on:
issue_comment:
- types: [created, edited]
+ types: [created]
jobs:
mark-duplicate:
@@ -321,12 +321,16 @@ jobs:
| -- | -- | -- | -- | -- |
| actions | Action type | string | ✔ | v1.5 |
| token | [Token explain](#token) | string | ✔ | v1.5 |
-| duplicate-command | Operation command, default is `/d` | string | ✖ | v1.5 |
+| duplicate-command | Simple commands can be set, such as: `/d` | string | ✖ | v1.6 |
| duplicate-labels | Add additional labels to this issue | string | ✖ | v1.5 |
| labels | Replace the labels of the issue | string | ✖ | v1.5 |
| contents | Add [reaction](#reactions-types) for this comment | string | ✖ | v1.5 |
+| close-issue | Whether to close the issue at the same time | string | ✖ | v1.6 |
-⏫ [返回列表](#列-表)
+- `duplicate-command`: When setting concise commands, while still supporting the original `Duplicate of`
+- `close-issue`: Both `true` or `'true'` can take effect
+
+⏫ [Back to list](#List)
#### `open-issue`
diff --git a/README.md b/README.md
index 19d2f62..5b23ec6 100644
--- a/README.md
+++ b/README.md
@@ -297,14 +297,14 @@ jobs:
#### `mark-duplicate`
-快捷标记重复问题。
+快捷标记重复问题,仅作用于 issue 新增评论。
```yml
name: Issue Mark Duplicate
on:
issue_comment:
- types: [created, edited]
+ types: [created]
jobs:
mark-duplicate:
@@ -321,10 +321,14 @@ jobs:
| -- | -- | -- | -- | -- |
| actions | 操作类型 | string | ✔ | v1.5 |
| token | [token 说明](#token) | string | ✔ | v1.5 |
-| duplicate-command | 操作命令,默认为 `/d` | string | ✖ | v1.5 |
+| duplicate-command | 可设置简洁命令,如:`/d` | string | ✖ | v1.6 |
| duplicate-labels | 为该 issue 额外增加 labels | string | ✖ | v1.5 |
| labels | 替换该 issue 的 labels | string | ✖ | v1.5 |
| contents | 为该评论的增加 [reaction](#reactions-types) | string | ✖ | v1.5 |
+| close-issue | 是否同时关闭该 issue | string | ✖ | v1.6 |
+
+- `duplicate-command`:当设置简洁命令时,同时仍支持原有 `Duplicate of`
+- `close-issue`:`true` 或 `'true'` 均可生效
⏫ [返回列表](#列-表)
diff --git a/action.yml b/action.yml
index caa3064..beabd1e 100644
--- a/action.yml
+++ b/action.yml
@@ -56,6 +56,8 @@ inputs:
description: 'For mark-duplicate'
duplicate-labels:
description: 'For mark-duplicate add labels'
+ close-issue:
+ description: 'For mark-duplicate'
outputs:
issue-number:
description: 'Create Issue Number'
diff --git a/dist/index.js b/dist/index.js
index 3634a65..dea8933 100644
--- a/dist/index.js
+++ b/dist/index.js
@@ -6278,7 +6278,7 @@ const ALLREACTIONS = [
"eyes",
];
-const { dealInput } = __webpack_require__(6254);
+const { dealInput, testDuplicate } = __webpack_require__(6254);
const token = core.getInput('token');
const octokit = new Octokit({ auth: `token ${token}` });
@@ -6407,22 +6407,37 @@ async function doMarkDuplicate (owner, repo, labels) {
core.info(`This actions only support on 'issue_comment'!`);
return false;
}
- const duplicateCommand = core.getInput("duplicate-command") || '/d';
+ 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 closeIssue = core.getInput("close-issue");
const commentId = context.payload.comment.id;
const commentBody = context.payload.comment.body;
const issueNumber = context.payload.issue.number;
- if (commentBody.startsWith(duplicateCommand) && commentBody.split(' ')[0] == duplicateCommand) {
- const nextBody = commentBody.replace(duplicateCommand, 'Duplicate of');
- await doUpdateComment(owner, repo, commentId, nextBody, 'replace', true);
+ const ifCommandInput = !!duplicateCommand;
+
+ if ((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, dealInput(contents));
+ }
if (duplicateLabels) {
await doAddLabels(owner, repo, issueNumber, duplicateLabels);
}
if (labels) {
await doSetLabels(owner, repo, issueNumber, labels);
}
+ if (closeIssue == 'true') {
+ await doCloseIssue(owner, repo, issueNumber);
+ }
} else {
core.info(`This comment body should start whith 'duplicate-command'`);
}
@@ -6905,13 +6920,27 @@ function dealInput (para) {
return arr;
};
-function matchKeyword(content, keywords) {
+function matchKeyword (content, keywords) {
return keywords.find(item => content.toLowerCase().includes(item));
};
+function testDuplicate(body) {
+ if (!body || !body.startsWith('Duplicate of')) {
+ return false
+ }
+
+ let arr = body.split(' ');
+ if (arr[0] == 'Duplicate' && arr[1] == 'of') {
+ return true;
+ } else {
+ return false;
+ }
+};
+
module.exports = {
dealInput,
matchKeyword,
+ testDuplicate,
};
diff --git a/docs/base.en-US.md b/docs/base.en-US.md
index 4a8b096..06a7962 100644
--- a/docs/base.en-US.md
+++ b/docs/base.en-US.md
@@ -231,14 +231,14 @@ jobs:
## `mark-duplicate`
-Quickly mark duplicate issue.
+Quickly mark duplicate questions, only for issue new comments.
```yml
name: Issue Mark Duplicate
on:
issue_comment:
- types: [created, edited]
+ types: [created]
jobs:
mark-duplicate:
@@ -255,10 +255,20 @@ jobs:
| -- | -- | -- | -- | -- |
| actions | Action type | string | ✔ | v1.5 |
| token | [Token explain](/en-US/guide/ref#-token) | string | ✔ | v1.5 |
-| duplicate-command | Operation command, default is `/d` | string | ✖ | v1.5 |
+| duplicate-command | Simple commands can be set, such as: `/d` | string | ✖ | v1.6 |
| duplicate-labels | Add additional labels to this issue | string | ✖ | v1.5 |
| labels | Replace the labels of the issue | string | ✖ | v1.5 |
| contents | Add [reaction](/en-US/guide/ref#-reactions-type) for this comment | string | ✖ | v1.5 |
+| close-issue | Whether to close the issue at the same time | string | ✖ | v1.6 |
+
+- `duplicate-command`: When setting concise commands, while still supporting the original `Duplicate of`
+- `close-issue`: Both `true` or `'true'` can take effect
+
+
+Note: Duplicate created with the concise command does not display the content of the red box in the figure below. But in fact this has no effect.
+
+
+
## `open-issue`
diff --git a/docs/base.md b/docs/base.md
index af49fe4..32b1faf 100644
--- a/docs/base.md
+++ b/docs/base.md
@@ -231,14 +231,14 @@ jobs:
## `mark-duplicate`
-快捷标记重复问题。
+快捷标记重复问题,仅作用于 issue 新增评论。
```yml
name: Issue Mark Duplicate
on:
issue_comment:
- types: [created, edited]
+ types: [created]
jobs:
mark-duplicate:
@@ -255,10 +255,20 @@ jobs:
| -- | -- | -- | -- | -- |
| actions | 操作类型 | string | ✔ | v1.5 |
| token | [token 说明](/guide/ref#-token-说明) | string | ✔ | v1.5 |
-| duplicate-command | 操作命令,默认为 `/d` | string | ✖ | v1.5 |
+| duplicate-command | 可设置简洁命令,如:`/d` | string | ✖ | v1.6 |
| duplicate-labels | 为该 issue 额外增加 labels | string | ✖ | v1.5 |
| labels | 替换该 issue 的 labels | string | ✖ | v1.5 |
| contents | 为该评论的增加 [reaction](/guide/ref#-reactions-类型) | string | ✖ | v1.5 |
+| close-issue | 是否同时关闭该 issue | string | ✖ | v1.6 |
+
+- `duplicate-command`:当设置简洁命令时,同时仍支持原有 `Duplicate of`
+- `close-issue`:`true` 或 `'true'` 均可生效
+
+
+注意:使用简洁命令创建的 Duplicate 不显示下图红框内容。但其实这个没有任何影响的。
+
+
+
## `open-issue`
diff --git a/package.json b/package.json
index ceb0d4f..9409545 100644
--- a/package.json
+++ b/package.json
@@ -1,6 +1,6 @@
{
"name": "issue-helper",
- "version": "1.5.0",
+ "version": "1.6.0",
"private": true,
"description": "Some operations on issue.",
"main": "src/main.js",
diff --git a/public/duplicate.png b/public/duplicate.png
new file mode 100644
index 0000000..df34d57
Binary files /dev/null and b/public/duplicate.png differ
diff --git a/src/base.js b/src/base.js
index 094bada..d57701d 100644
--- a/src/base.js
+++ b/src/base.js
@@ -16,7 +16,7 @@ const ALLREACTIONS = [
"eyes",
];
-const { dealInput } = require('./util.js');
+const { dealInput, testDuplicate } = require('./util.js');
const token = core.getInput('token');
const octokit = new Octokit({ auth: `token ${token}` });
@@ -145,22 +145,37 @@ async function doMarkDuplicate (owner, repo, labels) {
core.info(`This actions only support on 'issue_comment'!`);
return false;
}
- const duplicateCommand = core.getInput("duplicate-command") || '/d';
+ 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 closeIssue = core.getInput("close-issue");
const commentId = context.payload.comment.id;
const commentBody = context.payload.comment.body;
const issueNumber = context.payload.issue.number;
- if (commentBody.startsWith(duplicateCommand) && commentBody.split(' ')[0] == duplicateCommand) {
- const nextBody = commentBody.replace(duplicateCommand, 'Duplicate of');
- await doUpdateComment(owner, repo, commentId, nextBody, 'replace', true);
+ const ifCommandInput = !!duplicateCommand;
+
+ if ((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, dealInput(contents));
+ }
if (duplicateLabels) {
await doAddLabels(owner, repo, issueNumber, duplicateLabels);
}
if (labels) {
await doSetLabels(owner, repo, issueNumber, labels);
}
+ if (closeIssue == 'true') {
+ await doCloseIssue(owner, repo, issueNumber);
+ }
} else {
core.info(`This comment body should start whith 'duplicate-command'`);
}
diff --git a/src/util.js b/src/util.js
index 8600c56..e90c4f3 100644
--- a/src/util.js
+++ b/src/util.js
@@ -11,11 +11,25 @@ function dealInput (para) {
return arr;
};
-function matchKeyword(content, keywords) {
+function matchKeyword (content, keywords) {
return keywords.find(item => content.toLowerCase().includes(item));
};
+function testDuplicate(body) {
+ if (!body || !body.startsWith('Duplicate of')) {
+ return false
+ }
+
+ let arr = body.split(' ');
+ if (arr[0] == 'Duplicate' && arr[1] == 'of') {
+ return true;
+ } else {
+ return false;
+ }
+};
+
module.exports = {
dealInput,
matchKeyword,
+ testDuplicate,
};