Compare commits

..

4 Commits
v1.4 ... v1.5

Author SHA1 Message Date
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
13 changed files with 250 additions and 9 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,9 @@
## 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,39 @@ jobs:
⏫ [Back to list](#List)
#### `mark-duplicate`
Quickly mark duplicate issue.
```yml
name: Issue Mark Duplicate
on:
issue_comment:
types: [created, edited]
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 | Operation command, default is `/d` | string | ✖ | v1.5 |
| 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 |
⏫ [返回列表](#列-表)
#### `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,39 @@ jobs:
⏫ [返回列表](#列-表)
#### `mark-duplicate`
快捷标记重复问题。
```yml
name: Issue Mark Duplicate
on:
issue_comment:
types: [created, edited]
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.5 |
| duplicate-labels | 为该 issue 额外增加 labels | string | ✖ | v1.5 |
| labels | 替换该 issue 的 labels | string | ✖ | v1.5 |
| contents | 为该评论的增加 [reaction](#reactions-types) | string | ✖ | v1.5 |
⏫ [返回列表](#列-表)
#### `open-issue`
打开指定 issue。

View File

@@ -52,6 +52,10 @@ 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'
outputs:
issue-number:
description: 'Create Issue Number'

41
dist/index.js vendored
View File

@@ -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,32 @@ 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;
}
const duplicateCommand = core.getInput("duplicate-command") || '/d';
const duplicateLabels = core.getInput("duplicate-labels");
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);
if (duplicateLabels) {
await doAddLabels(owner, repo, issueNumber, duplicateLabels);
}
if (labels) {
await doSetLabels(owner, repo, issueNumber, labels);
}
} else {
core.info(`This comment body should start whith 'duplicate-command'`);
}
};
async function doOpenIssue (owner, repo, issueNumber) {
await octokit.issues.update({
owner,
@@ -6466,7 +6494,8 @@ async function doUpdateComment (
repo,
commentId,
body,
updateMode
updateMode,
ifUpdateBody,
) {
const comment = await octokit.issues.getComment({
owner,
@@ -6481,7 +6510,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 +6646,7 @@ module.exports = {
doCreateIssue,
doCreateIssueContent,
doDeleteComment,
doMarkDuplicate,
doLockIssue,
doOpenIssue,
doRemoveAssignees,
@@ -6646,6 +6676,7 @@ const {
doCreateIssue,
doCreateIssueContent,
doDeleteComment,
doMarkDuplicate,
doLockIssue,
doOpenIssue,
doRemoveAssignees,
@@ -6674,6 +6705,7 @@ const ALLACTIONS = [
'create-issue',
'delete-comment',
'lock-issue',
'mark-duplicate',
'open-issue',
'remove-assignees',
'remove-labels',
@@ -6715,7 +6747,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 +6787,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

@@ -229,6 +229,37 @@ jobs:
| token | [Token explain](/en-US/guide/ref#-token) | string | ✔ | v1 |
| issue-number | The number of issue | number | ✔ | v1 |
## `mark-duplicate`
Quickly mark duplicate issue.
```yml
name: Issue Mark Duplicate
on:
issue_comment:
types: [created, edited]
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 | Operation command, default is `/d` | string | ✖ | v1.5 |
| 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 |
## `open-issue`
Open the specified issue.

View File

@@ -229,6 +229,37 @@ jobs:
| token | [token 说明](/guide/ref#-token-说明) | string | ✔ | v1 |
| issue-number | 指定的 issue | number | ✔ | v1 |
## `mark-duplicate`
快捷标记重复问题。
```yml
name: Issue Mark Duplicate
on:
issue_comment:
types: [created, edited]
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.5 |
| duplicate-labels | 为该 issue 额外增加 labels | string | ✖ | v1.5 |
| labels | 替换该 issue 的 labels | string | ✖ | v1.5 |
| contents | 为该评论的增加 [reaction](/guide/ref#-reactions-类型) | string | ✖ | v1.5 |
## `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.5.0",
"private": true,
"description": "Some operations on issue.",
"main": "src/main.js",

View File

@@ -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,32 @@ 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;
}
const duplicateCommand = core.getInput("duplicate-command") || '/d';
const duplicateLabels = core.getInput("duplicate-labels");
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);
if (duplicateLabels) {
await doAddLabels(owner, repo, issueNumber, duplicateLabels);
}
if (labels) {
await doSetLabels(owner, repo, issueNumber, labels);
}
} else {
core.info(`This comment body should start whith 'duplicate-command'`);
}
};
async function doOpenIssue (owner, repo, issueNumber) {
await octokit.issues.update({
owner,
@@ -204,7 +232,8 @@ async function doUpdateComment (
repo,
commentId,
body,
updateMode
updateMode,
ifUpdateBody,
) {
const comment = await octokit.issues.getComment({
owner,
@@ -219,7 +248,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 +384,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;