perf: optimize duplicate (#24)

* perf: optimize mark duplicate

* add

* add

* add

* add

* add
This commit is contained in:
xrkffgg
2020-12-30 15:17:26 +08:00
committed by GitHub
parent 1cf278b531
commit da1f8da3d4
10 changed files with 114 additions and 26 deletions

View File

@@ -297,14 +297,14 @@ jobs:
#### `mark-duplicate` #### `mark-duplicate`
Quickly mark duplicate issue. Quickly mark duplicate questions, only for issue new comments.
```yml ```yml
name: Issue Mark Duplicate name: Issue Mark Duplicate
on: on:
issue_comment: issue_comment:
types: [created, edited] types: [created]
jobs: jobs:
mark-duplicate: mark-duplicate:
@@ -321,12 +321,16 @@ jobs:
| -- | -- | -- | -- | -- | | -- | -- | -- | -- | -- |
| actions | Action type | string | ✔ | v1.5 | | actions | Action type | string | ✔ | v1.5 |
| token | [Token explain](#token) | 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 | | duplicate-labels | Add additional labels to this issue | string | ✖ | v1.5 |
| labels | Replace the labels of the 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 | | 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` #### `open-issue`

View File

@@ -297,14 +297,14 @@ jobs:
#### `mark-duplicate` #### `mark-duplicate`
快捷标记重复问题。 快捷标记重复问题,仅作用于 issue 新增评论
```yml ```yml
name: Issue Mark Duplicate name: Issue Mark Duplicate
on: on:
issue_comment: issue_comment:
types: [created, edited] types: [created]
jobs: jobs:
mark-duplicate: mark-duplicate:
@@ -321,10 +321,14 @@ jobs:
| -- | -- | -- | -- | -- | | -- | -- | -- | -- | -- |
| actions | 操作类型 | string | ✔ | v1.5 | | actions | 操作类型 | string | ✔ | v1.5 |
| token | [token 说明](#token) | 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 | | duplicate-labels | 为该 issue 额外增加 labels | string | ✖ | v1.5 |
| labels | 替换该 issue 的 labels | string | ✖ | v1.5 | | labels | 替换该 issue 的 labels | string | ✖ | v1.5 |
| contents | 为该评论的增加 [reaction](#reactions-types) | string | ✖ | v1.5 | | contents | 为该评论的增加 [reaction](#reactions-types) | string | ✖ | v1.5 |
| close-issue | 是否同时关闭该 issue | string | ✖ | v1.6 |
- `duplicate-command`:当设置简洁命令时,同时仍支持原有 `Duplicate of`
- `close-issue``true``'true'` 均可生效
⏫ [返回列表](#列-表) ⏫ [返回列表](#列-表)

View File

@@ -56,6 +56,8 @@ inputs:
description: 'For mark-duplicate' description: 'For mark-duplicate'
duplicate-labels: duplicate-labels:
description: 'For mark-duplicate add labels' description: 'For mark-duplicate add labels'
close-issue:
description: 'For mark-duplicate'
outputs: outputs:
issue-number: issue-number:
description: 'Create Issue Number' description: 'Create Issue Number'

35
dist/index.js vendored
View File

@@ -6278,7 +6278,7 @@ const ALLREACTIONS = [
"eyes", "eyes",
]; ];
const { dealInput } = __webpack_require__(6254); const { dealInput, testDuplicate } = __webpack_require__(6254);
const token = core.getInput('token'); const token = core.getInput('token');
const octokit = new Octokit({ auth: `token ${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'!`); core.info(`This actions only support on 'issue_comment'!`);
return false; 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 duplicateLabels = core.getInput("duplicate-labels");
const closeIssue = core.getInput("close-issue");
const commentId = context.payload.comment.id; const commentId = context.payload.comment.id;
const commentBody = context.payload.comment.body; const commentBody = context.payload.comment.body;
const issueNumber = context.payload.issue.number; const issueNumber = context.payload.issue.number;
if (commentBody.startsWith(duplicateCommand) && commentBody.split(' ')[0] == duplicateCommand) { const ifCommandInput = !!duplicateCommand;
if ((ifCommandInput && commentBody.startsWith(duplicateCommand) && commentBody.split(' ')[0] == duplicateCommand) || testDuplicate(commentBody)) {
if (ifCommandInput) {
const nextBody = commentBody.replace(duplicateCommand, 'Duplicate of'); const nextBody = commentBody.replace(duplicateCommand, 'Duplicate of');
await doUpdateComment(owner, repo, commentId, nextBody, 'replace', true); await doUpdateComment(owner, repo, commentId, nextBody, 'replace', true);
} else if (contents) {
await doCreateCommentContent(owner, repo, commentId, dealInput(contents));
}
if (duplicateLabels) { if (duplicateLabels) {
await doAddLabels(owner, repo, issueNumber, duplicateLabels); await doAddLabels(owner, repo, issueNumber, duplicateLabels);
} }
if (labels) { if (labels) {
await doSetLabels(owner, repo, issueNumber, labels); await doSetLabels(owner, repo, issueNumber, labels);
} }
if (closeIssue == 'true') {
await doCloseIssue(owner, repo, issueNumber);
}
} else { } else {
core.info(`This comment body should start whith 'duplicate-command'`); core.info(`This comment body should start whith 'duplicate-command'`);
} }
@@ -6909,9 +6924,23 @@ function matchKeyword(content, keywords) {
return keywords.find(item => content.toLowerCase().includes(item)); 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 = { module.exports = {
dealInput, dealInput,
matchKeyword, matchKeyword,
testDuplicate,
}; };

View File

@@ -231,14 +231,14 @@ jobs:
## `mark-duplicate` ## `mark-duplicate`
Quickly mark duplicate issue. Quickly mark duplicate questions, only for issue new comments.
```yml ```yml
name: Issue Mark Duplicate name: Issue Mark Duplicate
on: on:
issue_comment: issue_comment:
types: [created, edited] types: [created]
jobs: jobs:
mark-duplicate: mark-duplicate:
@@ -255,10 +255,20 @@ jobs:
| -- | -- | -- | -- | -- | | -- | -- | -- | -- | -- |
| actions | Action type | string | ✔ | v1.5 | | actions | Action type | string | ✔ | v1.5 |
| token | [Token explain](/en-US/guide/ref#-token) | 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 | | duplicate-labels | Add additional labels to this issue | string | ✖ | v1.5 |
| labels | Replace the labels of the 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 | | 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
<Alert>
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.
</Alert>
![](../public/duplicate.png)
## `open-issue` ## `open-issue`

View File

@@ -231,14 +231,14 @@ jobs:
## `mark-duplicate` ## `mark-duplicate`
快捷标记重复问题。 快捷标记重复问题,仅作用于 issue 新增评论
```yml ```yml
name: Issue Mark Duplicate name: Issue Mark Duplicate
on: on:
issue_comment: issue_comment:
types: [created, edited] types: [created]
jobs: jobs:
mark-duplicate: mark-duplicate:
@@ -255,10 +255,20 @@ jobs:
| -- | -- | -- | -- | -- | | -- | -- | -- | -- | -- |
| actions | 操作类型 | string | ✔ | v1.5 | | actions | 操作类型 | string | ✔ | v1.5 |
| token | [token 说明](/guide/ref#-token-说明) | 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 | | duplicate-labels | 为该 issue 额外增加 labels | string | ✖ | v1.5 |
| labels | 替换该 issue 的 labels | string | ✖ | v1.5 | | labels | 替换该 issue 的 labels | string | ✖ | v1.5 |
| contents | 为该评论的增加 [reaction](/guide/ref#-reactions-类型) | 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'` 均可生效
<Alert>
注意:使用简洁命令创建的 Duplicate 不显示下图红框内容。但其实这个没有任何影响的。
</Alert>
![](../public/duplicate.png)
## `open-issue` ## `open-issue`

View File

@@ -1,6 +1,6 @@
{ {
"name": "issue-helper", "name": "issue-helper",
"version": "1.5.0", "version": "1.6.0",
"private": true, "private": true,
"description": "Some operations on issue.", "description": "Some operations on issue.",
"main": "src/main.js", "main": "src/main.js",

BIN
public/duplicate.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 54 KiB

View File

@@ -16,7 +16,7 @@ const ALLREACTIONS = [
"eyes", "eyes",
]; ];
const { dealInput } = require('./util.js'); const { dealInput, testDuplicate } = require('./util.js');
const token = core.getInput('token'); const token = core.getInput('token');
const octokit = new Octokit({ auth: `token ${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'!`); core.info(`This actions only support on 'issue_comment'!`);
return false; 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 duplicateLabels = core.getInput("duplicate-labels");
const closeIssue = core.getInput("close-issue");
const commentId = context.payload.comment.id; const commentId = context.payload.comment.id;
const commentBody = context.payload.comment.body; const commentBody = context.payload.comment.body;
const issueNumber = context.payload.issue.number; const issueNumber = context.payload.issue.number;
if (commentBody.startsWith(duplicateCommand) && commentBody.split(' ')[0] == duplicateCommand) { const ifCommandInput = !!duplicateCommand;
if ((ifCommandInput && commentBody.startsWith(duplicateCommand) && commentBody.split(' ')[0] == duplicateCommand) || testDuplicate(commentBody)) {
if (ifCommandInput) {
const nextBody = commentBody.replace(duplicateCommand, 'Duplicate of'); const nextBody = commentBody.replace(duplicateCommand, 'Duplicate of');
await doUpdateComment(owner, repo, commentId, nextBody, 'replace', true); await doUpdateComment(owner, repo, commentId, nextBody, 'replace', true);
} else if (contents) {
await doCreateCommentContent(owner, repo, commentId, dealInput(contents));
}
if (duplicateLabels) { if (duplicateLabels) {
await doAddLabels(owner, repo, issueNumber, duplicateLabels); await doAddLabels(owner, repo, issueNumber, duplicateLabels);
} }
if (labels) { if (labels) {
await doSetLabels(owner, repo, issueNumber, labels); await doSetLabels(owner, repo, issueNumber, labels);
} }
if (closeIssue == 'true') {
await doCloseIssue(owner, repo, issueNumber);
}
} else { } else {
core.info(`This comment body should start whith 'duplicate-command'`); core.info(`This comment body should start whith 'duplicate-command'`);
} }

View File

@@ -15,7 +15,21 @@ function matchKeyword(content, keywords) {
return keywords.find(item => content.toLowerCase().includes(item)); 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 = { module.exports = {
dealInput, dealInput,
matchKeyword, matchKeyword,
testDuplicate,
}; };