Compare commits

..

6 Commits
v1.4 ... v1.6

Author SHA1 Message Date
xrkffgg
44240d2ab3 docs: update changelog 2020-12-30 15:25:03 +08:00
xrkffgg
da1f8da3d4 perf: optimize duplicate (#24)
* perf: optimize mark duplicate

* add

* add

* add

* add

* add
2020-12-30 15:17:26 +08:00
xrkffgg
1cf278b531 Rename changelog.md to CHANGELOG.md 2020-12-30 13:52:03 +08:00
xrkffgg
09b55c2859 chore: update name 2020-12-30 13:51:10 +08:00
xrkffgg
c81901f651 feat: add mark-duplicate (#23)
* feat: add mark-duplicate

* add

* add

* add

* add

* add

* add

* add

* change

* update
2020-12-30 13:48:38 +08:00
xrkffgg
a2273a4c3b Create check-dist.yml 2020-12-30 09:22:40 +08:00
15 changed files with 348 additions and 13 deletions

27
.github/workflows/check-dist.yml vendored Normal file
View File

@@ -0,0 +1,27 @@
name: Update dist
on:
push:
branches: [ main ]
jobs:
check-dist:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@master
- name: install
run: yarn
- name: package
run: yarn package
- name: Commit and push if changed
run: |-
git diff
git config --global user.email "xrkffgg@vip.qq.com"
git config --global user.name "xrkffgg"
git pull
git add -A
git commit -m "🤖 auto: updated dist" || exit 0
git push

View File

@@ -1,3 +1,15 @@
## v1.6
`2020.12.30`
- perf: optimize duplicate. [#24](https://github.com/actions-cool/issues-helper/pull/24)
## v1.5
`2020.12.30`
- feat: add `mark-duplicate`. [#23](https://github.com/actions-cool/issues-helper/pull/23)
## v1.4
`2020.12.29`

View File

@@ -12,7 +12,7 @@
A GitHub Action that easily helps you automatically manage issues
[Online documentation](https://actions-cool.github.io/issues-helper) | [Changelog](https://github.com/actions-cool/issues-helper/blob/main/docs/log.md)
[Online documentation](https://actions-cool.github.io/issues-helper) | [Changelog](https://github.com/actions-cool/issues-helper/blob/main/CHANGELOG.md)
## 😎 Why use GitHub Action?
@@ -34,6 +34,7 @@ When the following list does not have the features you want, you can submit it i
- [`create-issue`](#create-issue)
- [`delete-comment`](#delete-comment)
- [`lock-issue`](#lock-issue)
- [`mark-duplicate`](#mark-duplicate)
- [`open-issue`](#open-issue)
- [`remove-assignees`](#remove-assignees)
- [`remove-labels`](#remove-labels)
@@ -294,6 +295,43 @@ jobs:
⏫ [Back to list](#List)
#### `mark-duplicate`
Quickly mark duplicate questions, only for issue new comments.
```yml
name: Issue Mark Duplicate
on:
issue_comment:
types: [created]
jobs:
mark-duplicate:
runs-on: ubuntu-latest
steps:
- name: mark-duplicate
uses: actions-cool/issues-helper@v1.5
with:
actions: 'mark-duplicate'
token: ${{ secrets.GITHUB_TOKEN }}
```
| Param | Desc | Type | Required | Version |
| -- | -- | -- | -- | -- |
| actions | Action type | string | ✔ | v1.5 |
| token | [Token explain](#token) | 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`
Open the specified issue.

View File

@@ -12,7 +12,7 @@
一个轻松帮你自动管理 issues 的 GitHub Action
[在线文档](https://actions-cool.github.io/issues-helper/) | [更新日志](https://github.com/actions-cool/issues-helper/blob/main/docs/log.md)
[在线文档](https://actions-cool.github.io/issues-helper/) | [更新日志](https://github.com/actions-cool/issues-helper/blob/main/CHANGELOG.md)
## 😎 为什么用 GitHub Action
@@ -34,6 +34,7 @@
- [`create-issue`](#create-issue)
- [`delete-comment`](#delete-comment)
- [`lock-issue`](#lock-issue)
- [`mark-duplicate`](#mark-duplicate)
- [`open-issue`](#open-issue)
- [`remove-assignees`](#remove-assignees)
- [`remove-labels`](#remove-labels)
@@ -294,6 +295,43 @@ jobs:
⏫ [返回列表](#列-表)
#### `mark-duplicate`
快捷标记重复问题,仅作用于 issue 新增评论。
```yml
name: Issue Mark Duplicate
on:
issue_comment:
types: [created]
jobs:
mark-duplicate:
runs-on: ubuntu-latest
steps:
- name: mark-duplicate
uses: actions-cool/issues-helper@v1.5
with:
actions: 'mark-duplicate'
token: ${{ secrets.GITHUB_TOKEN }}
```
| 参数 | 描述 | 类型 | 必填 | 版本 |
| -- | -- | -- | -- | -- |
| actions | 操作类型 | string | ✔ | v1.5 |
| token | [token 说明](#token) | 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'` 均可生效
⏫ [返回列表](#列-表)
#### `open-issue`
打开指定 issue。

View File

@@ -52,6 +52,12 @@ inputs:
description: 'Query use'
inactive-label:
description: 'Issue label set use'
duplicate-command:
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'

74
dist/index.js vendored
View File

@@ -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}` });
@@ -6286,6 +6286,8 @@ const octokit = new Octokit({ auth: `token ${token}` });
const contents = core.getInput("contents");
const issueContents = core.getInput("issue-contents");
const context = github.context;
async function doAddAssignees (owner, repo, issueNumber, assignees) {
await octokit.issues.addAssignees({
owner,
@@ -6400,6 +6402,47 @@ async function doLockIssue (owner, repo, issueNumber) {
core.info(`Actions: [lock-issue][${issueNumber}] success!`);
};
async function doMarkDuplicate (owner, repo, labels) {
if (context.eventName != 'issue_comment') {
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 closeIssue = core.getInput("close-issue");
const commentId = context.payload.comment.id;
const commentBody = context.payload.comment.body;
const issueNumber = context.payload.issue.number;
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'`);
}
};
async function doOpenIssue (owner, repo, issueNumber) {
await octokit.issues.update({
owner,
@@ -6466,7 +6509,8 @@ async function doUpdateComment (
repo,
commentId,
body,
updateMode
updateMode,
ifUpdateBody,
) {
const comment = await octokit.issues.getComment({
owner,
@@ -6481,7 +6525,7 @@ async function doUpdateComment (
comment_id: commentId
};
if (core.getInput("body")) {
if (core.getInput("body") || ifUpdateBody) {
if (updateMode === 'append') {
params.body = `${comment_body}\n${body}`;
} else {
@@ -6617,6 +6661,7 @@ module.exports = {
doCreateIssue,
doCreateIssueContent,
doDeleteComment,
doMarkDuplicate,
doLockIssue,
doOpenIssue,
doRemoveAssignees,
@@ -6646,6 +6691,7 @@ const {
doCreateIssue,
doCreateIssueContent,
doDeleteComment,
doMarkDuplicate,
doLockIssue,
doOpenIssue,
doRemoveAssignees,
@@ -6674,6 +6720,7 @@ const ALLACTIONS = [
'create-issue',
'delete-comment',
'lock-issue',
'mark-duplicate',
'open-issue',
'remove-assignees',
'remove-labels',
@@ -6715,7 +6762,9 @@ async function main() {
updateMode = 'replace';
}
// actions
const actions = core.getInput("actions", { required: true });
const actionsArr = actions.split(',');
actionsArr.forEach(item => {
testActions(item.trim());
@@ -6753,6 +6802,9 @@ async function main() {
case 'lock-issue':
await doLockIssue(owner, repo, issueNumber);
break;
case 'mark-duplicate':
await doMarkDuplicate(owner, repo, labels);
break;
case 'open-issue':
await doOpenIssue(owner, repo, issueNumber);
break;
@@ -6868,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,
};

View File

@@ -229,6 +229,47 @@ jobs:
| token | [Token explain](/en-US/guide/ref#-token) | string | ✔ | v1 |
| issue-number | The number of issue | number | ✔ | v1 |
## `mark-duplicate`
Quickly mark duplicate questions, only for issue new comments.
```yml
name: Issue Mark Duplicate
on:
issue_comment:
types: [created]
jobs:
mark-duplicate:
runs-on: ubuntu-latest
steps:
- name: mark-duplicate
uses: actions-cool/issues-helper@v1.5
with:
actions: 'mark-duplicate'
token: ${{ secrets.GITHUB_TOKEN }}
```
| Param | Desc | Type | Required | Version |
| -- | -- | -- | -- | -- |
| actions | Action type | string | ✔ | v1.5 |
| token | [Token explain](/en-US/guide/ref#-token) | 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
<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 the specified issue.

View File

@@ -229,6 +229,47 @@ jobs:
| token | [token 说明](/guide/ref#-token-说明) | string | ✔ | v1 |
| issue-number | 指定的 issue | number | ✔ | v1 |
## `mark-duplicate`
快捷标记重复问题,仅作用于 issue 新增评论。
```yml
name: Issue Mark Duplicate
on:
issue_comment:
types: [created]
jobs:
mark-duplicate:
runs-on: ubuntu-latest
steps:
- name: mark-duplicate
uses: actions-cool/issues-helper@v1.5
with:
actions: 'mark-duplicate'
token: ${{ secrets.GITHUB_TOKEN }}
```
| 参数 | 描述 | 类型 | 必填 | 版本 |
| -- | -- | -- | -- | -- |
| actions | 操作类型 | string | ✔ | v1.5 |
| token | [token 说明](/guide/ref#-token-说明) | 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'` 均可生效
<Alert>
注意:使用简洁命令创建的 Duplicate 不显示下图红框内容。但其实这个没有任何影响的。
</Alert>
![](../public/duplicate.png)
## `open-issue`
打开指定 issue。

View File

@@ -21,4 +21,4 @@ toc: menu
uses: actions-cool/issues-helper@main
```
<embed src="./log.md"></embed>
<embed src="../CHANGELOG.md"></embed>

View File

@@ -21,4 +21,4 @@ toc: menu
uses: actions-cool/issues-helper@main
```
<embed src="./log.md"></embed>
<embed src="../CHANGELOG.md"></embed>

View File

@@ -1,6 +1,6 @@
{
"name": "issue-helper",
"version": "1.4.0",
"version": "1.6.0",
"private": true,
"description": "Some operations on issue.",
"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",
];
const { dealInput } = require('./util.js');
const { dealInput, testDuplicate } = require('./util.js');
const token = core.getInput('token');
const octokit = new Octokit({ auth: `token ${token}` });
@@ -24,6 +24,8 @@ const octokit = new Octokit({ auth: `token ${token}` });
const contents = core.getInput("contents");
const issueContents = core.getInput("issue-contents");
const context = github.context;
async function doAddAssignees (owner, repo, issueNumber, assignees) {
await octokit.issues.addAssignees({
owner,
@@ -138,6 +140,47 @@ async function doLockIssue (owner, repo, issueNumber) {
core.info(`Actions: [lock-issue][${issueNumber}] success!`);
};
async function doMarkDuplicate (owner, repo, labels) {
if (context.eventName != 'issue_comment') {
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 closeIssue = core.getInput("close-issue");
const commentId = context.payload.comment.id;
const commentBody = context.payload.comment.body;
const issueNumber = context.payload.issue.number;
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'`);
}
};
async function doOpenIssue (owner, repo, issueNumber) {
await octokit.issues.update({
owner,
@@ -204,7 +247,8 @@ async function doUpdateComment (
repo,
commentId,
body,
updateMode
updateMode,
ifUpdateBody,
) {
const comment = await octokit.issues.getComment({
owner,
@@ -219,7 +263,7 @@ async function doUpdateComment (
comment_id: commentId
};
if (core.getInput("body")) {
if (core.getInput("body") || ifUpdateBody) {
if (updateMode === 'append') {
params.body = `${comment_body}\n${body}`;
} else {
@@ -355,6 +399,7 @@ module.exports = {
doCreateIssue,
doCreateIssueContent,
doDeleteComment,
doMarkDuplicate,
doLockIssue,
doOpenIssue,
doRemoveAssignees,

View File

@@ -10,6 +10,7 @@ const {
doCreateIssue,
doCreateIssueContent,
doDeleteComment,
doMarkDuplicate,
doLockIssue,
doOpenIssue,
doRemoveAssignees,
@@ -38,6 +39,7 @@ const ALLACTIONS = [
'create-issue',
'delete-comment',
'lock-issue',
'mark-duplicate',
'open-issue',
'remove-assignees',
'remove-labels',
@@ -79,7 +81,9 @@ async function main() {
updateMode = 'replace';
}
// actions
const actions = core.getInput("actions", { required: true });
const actionsArr = actions.split(',');
actionsArr.forEach(item => {
testActions(item.trim());
@@ -117,6 +121,9 @@ async function main() {
case 'lock-issue':
await doLockIssue(owner, repo, issueNumber);
break;
case 'mark-duplicate':
await doMarkDuplicate(owner, repo, labels);
break;
case 'open-issue':
await doOpenIssue(owner, repo, issueNumber);
break;

View File

@@ -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,
};