mirror of
https://gitea.com/Lydanne/issues-helper.git
synced 2025-08-21 19:25:46 +08:00
perf: optimize duplicate (#24)
* perf: optimize mark duplicate * add * add * add * add * add
This commit is contained in:
@@ -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`
|
||||||
|
|
||||||
|
10
README.md
10
README.md
@@ -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'` 均可生效
|
||||||
|
|
||||||
⏫ [返回列表](#列-表)
|
⏫ [返回列表](#列-表)
|
||||||
|
|
||||||
|
@@ -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'
|
||||||
|
37
dist/index.js
vendored
37
dist/index.js
vendored
@@ -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'`);
|
||||||
}
|
}
|
||||||
@@ -6905,13 +6920,27 @@ function dealInput (para) {
|
|||||||
return arr;
|
return arr;
|
||||||
};
|
};
|
||||||
|
|
||||||
function matchKeyword(content, keywords) {
|
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,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@@ -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>
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
## `open-issue`
|
## `open-issue`
|
||||||
|
|
||||||
|
16
docs/base.md
16
docs/base.md
@@ -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>
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
## `open-issue`
|
## `open-issue`
|
||||||
|
|
||||||
|
@@ -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
BIN
public/duplicate.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 54 KiB |
21
src/base.js
21
src/base.js
@@ -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'`);
|
||||||
}
|
}
|
||||||
|
16
src/util.js
16
src/util.js
@@ -11,11 +11,25 @@ function dealInput (para) {
|
|||||||
return arr;
|
return arr;
|
||||||
};
|
};
|
||||||
|
|
||||||
function matchKeyword(content, keywords) {
|
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,
|
||||||
};
|
};
|
||||||
|
Reference in New Issue
Block a user