From f6788d2b8ed6c23be9be04007904584db3f2db12 Mon Sep 17 00:00:00 2001 From: xrkffgg Date: Tue, 2 Feb 2021 17:55:54 +0800 Subject: [PATCH 1/5] feat: add create-label --- README.md | 28 ++++++++++++++++++++++++++++ action.yml | 8 ++++++++ src/base.js | 21 +++++++++++++++++++++ src/main.js | 5 +++++ 4 files changed, 62 insertions(+) diff --git a/README.md b/README.md index 3c7d869..516a115 100644 --- a/README.md +++ b/README.md @@ -319,6 +319,34 @@ jobs: ⏫ [返回列表](#列-表) +#### `create-label` + +新增 label。若想根据目录生成多个 labels,[可查看](https://github.com/actions-cool/create-labels)。 + +```yml +- name: Create label + uses: actions-cool/issues-helper@v2.0.0 + with: + actions: 'create-label' + token: ${{ secrets.GITHUB_TOKEN }} + label-name: 'xx' + label-color: '0095b3' + label-desc: 'xx' +``` + +| 参数 | 描述 | 类型 | 必填 | +| -- | -- | -- | -- | +| actions | 操作类型 | string | ✔ | +| token | [token 说明](#token) | string | ✔ | +| label-name | 标签名称,支持 emoji | string | ✔ | +| label-color | 标签颜色,格式为 16 进制色码,不加 `#` | string | ✖ | +| label-desc | 标签描述 | string | ✖ | + +- `label-name`:若已存在,则无操作 +- `label-color`:默认为 `ededed` + +⏫ [返回列表](#列-表) + #### `delete-comment` 根据 [`comment-id`](#comment-id) 删除指定评论。 diff --git a/action.yml b/action.yml index 36df7dd..db4c1d2 100644 --- a/action.yml +++ b/action.yml @@ -22,8 +22,16 @@ inputs: description: 'Issue assignees' random-to: description: 'Issue assignees random to' + # label labels: description: 'Issue labels' + label-name: + description: 'Create label name' + label-color: + description: 'Create label color, default #ededed' + label-desc: + description: 'Create label description' + state: description: 'Issue state' update-mode: diff --git a/src/base.js b/src/base.js index 2fce409..83d1910 100644 --- a/src/base.js +++ b/src/base.js @@ -122,6 +122,26 @@ async function doCreateIssueContent(owner, repo, issueNumber, contents) { } } +async function doCreateLabel(owner, repo) { + const name = core.getInput('label-name'); + const color = core.getInput('label-color') || 'ededed'; + const description = core.getInput('label-desc') || ''; + + if (!name) { + core.setFailed(`This actions should input 'label-name'!`); + return false; + } + + await octokit.issues.createLabel({ + owner, + repo, + name, + color, + description, + }); + core.info(`Actions: [create-label][${name}] success!`); +} + async function doDeleteComment(owner, repo, commentId) { await octokit.issues.deleteComment({ owner, @@ -450,6 +470,7 @@ module.exports = { doCreateCommentContent, doCreateIssue, doCreateIssueContent, + doCreateLabel, doDeleteComment, doMarkDuplicate, doLockIssue, diff --git a/src/main.js b/src/main.js index 0a5e781..5e8da64 100644 --- a/src/main.js +++ b/src/main.js @@ -8,6 +8,7 @@ const { doCloseIssue, doCreateComment, doCreateIssue, + doCreateLabel, doDeleteComment, doMarkDuplicate, doLockIssue, @@ -38,6 +39,7 @@ const ALLACTIONS = [ 'close-issue', 'create-comment', 'create-issue', + 'create-label', 'delete-comment', 'lock-issue', 'mark-duplicate', @@ -118,6 +120,9 @@ async function main() { case 'create-issue': await doCreateIssue(owner, repo, title, body, labels, assignees); break; + case 'create-label': + await doCreateLabel(owner, repo); + break; case 'delete-comment': await doDeleteComment(owner, repo, commentId); break; From 1cc6f0b7ca9d01588767e23d872284f6d32c5f89 Mon Sep 17 00:00:00 2001 From: xrkffgg Date: Tue, 2 Feb 2021 20:12:42 +0800 Subject: [PATCH 2/5] add doc --- README.en-US.md | 29 +++++++++++++++++++++++++++++ README.md | 1 + dist/index.js | 30 ++++++++++++++++++++++++++++++ docs/base.en-US.md | 26 ++++++++++++++++++++++++++ docs/base.md | 26 ++++++++++++++++++++++++++ src/base.js | 20 ++++++++++++-------- 6 files changed, 124 insertions(+), 8 deletions(-) diff --git a/README.en-US.md b/README.en-US.md index 0d2905b..96410a6 100644 --- a/README.en-US.md +++ b/README.en-US.md @@ -105,6 +105,7 @@ When the following list does not have the features you want, you can submit it i - [`close-issue`](#close-issue) - [`create-comment`](#create-comment) - [`create-issue`](#create-issue) + - [`create-label`](#create-label) - [`delete-comment`](#delete-comment) - [`lock-issue`](#lock-issue) - [`mark-duplicate`](#mark-duplicate) @@ -319,6 +320,34 @@ jobs: ⏫ [Back to list](#List) +#### `create-label` + +Create label。If you want to create multiple labels base on repository path. [See](https://github.com/actions-cool/create-labels). + +```yml +- name: Create label + uses: actions-cool/issues-helper@v2.0.0 + with: + actions: 'create-label' + token: ${{ secrets.GITHUB_TOKEN }} + label-name: 'xx' + label-color: '0095b3' + label-desc: 'xx' +``` + +| Param | Desc | Type | Required | +| -- | -- | -- | -- | +| actions | Action type | string | ✔ | +| token | [Token explain](#token) | string | ✔ | +| label-name | Label name, emoji support | string | ✔ | +| label-color | Label color, the format is hexadecimal color code, without `#` | string | ✖ | +| label-desc | Label description | string | ✖ | + +- `label-name`: If it already exists, no operation +- `label-color`: Default is `ededed` + +⏫ [Back to list](#List) + #### `delete-comment` According to [`comment-id`](#comment-id) delete the specified comment. diff --git a/README.md b/README.md index 516a115..c21763f 100644 --- a/README.md +++ b/README.md @@ -105,6 +105,7 @@ - [`close-issue`](#close-issue) - [`create-comment`](#create-comment) - [`create-issue`](#create-issue) + - [`create-label`](#create-label) - [`delete-comment`](#delete-comment) - [`lock-issue`](#lock-issue) - [`mark-duplicate`](#mark-duplicate) diff --git a/dist/index.js b/dist/index.js index 69800bd..8024b52 100644 --- a/dist/index.js +++ b/dist/index.js @@ -7985,6 +7985,30 @@ async function doCreateIssueContent(owner, repo, issueNumber, contents) { } } +async function doCreateLabel(owner, repo) { + const name = core.getInput('label-name'); + const color = core.getInput('label-color') || 'ededed'; + const description = core.getInput('label-desc') || ''; + + if (!name) { + core.setFailed(`This actions should input 'label-name'!`); + return false; + } + + try { + await octokit.issues.createLabel({ + owner, + repo, + name, + color, + description, + }); + core.info(`Actions: [create-label][${name}] success!`); + } catch (err) { + console.log(err.message) + } +} + async function doDeleteComment(owner, repo, commentId) { await octokit.issues.deleteComment({ owner, @@ -8313,6 +8337,7 @@ module.exports = { doCreateCommentContent, doCreateIssue, doCreateIssueContent, + doCreateLabel, doDeleteComment, doMarkDuplicate, doLockIssue, @@ -8342,6 +8367,7 @@ const { doCloseIssue, doCreateComment, doCreateIssue, + doCreateLabel, doDeleteComment, doMarkDuplicate, doLockIssue, @@ -8372,6 +8398,7 @@ const ALLACTIONS = [ 'close-issue', 'create-comment', 'create-issue', + 'create-label', 'delete-comment', 'lock-issue', 'mark-duplicate', @@ -8452,6 +8479,9 @@ async function main() { case 'create-issue': await doCreateIssue(owner, repo, title, body, labels, assignees); break; + case 'create-label': + await doCreateLabel(owner, repo); + break; case 'delete-comment': await doDeleteComment(owner, repo, commentId); break; diff --git a/docs/base.en-US.md b/docs/base.en-US.md index 7fb11c6..6ae2aa4 100644 --- a/docs/base.en-US.md +++ b/docs/base.en-US.md @@ -183,6 +183,32 @@ jobs: - `title` default is `Default Title` - Return `issue-number`. [Usage reference](/en-US/guide/ref#-outputs-use) +## `create-label` + +Create label。If you want to create multiple labels base on repository path. [See](https://github.com/actions-cool/create-labels). + +```yml +- name: Create label + uses: actions-cool/issues-helper@v2.0.0 + with: + actions: 'create-label' + token: ${{ secrets.GITHUB_TOKEN }} + label-name: 'xx' + label-color: '0095b3' + label-desc: 'xx' +``` + +| Param | Desc | Type | Required | +| -- | -- | -- | -- | +| actions | Action type | string | ✔ | +| token | [Token explain](/en-US/guide/ref#-token) | string | ✔ | +| label-name | Label name, emoji support | string | ✔ | +| label-color | Label color, the format is hexadecimal color code, without `#` | string | ✖ | +| label-desc | Label description | string | ✖ | + +- `label-name`: If it already exists, no operation +- `label-color`: Default is `ededed` + ## `delete-comment` According to [`comment-id`](/en-US/guide/ref#-comment-id) delete the specified comment. diff --git a/docs/base.md b/docs/base.md index dc410e5..c59a734 100644 --- a/docs/base.md +++ b/docs/base.md @@ -183,6 +183,32 @@ jobs: - `title` 默认为:`Default Title` - 返回 `issue-number`,[用法参考](/guide/ref#-outputs-使用) +## `create-label` + +新增 label。若想根据目录生成多个 labels,[可查看](https://github.com/actions-cool/create-labels)。 + +```yml +- name: Create label + uses: actions-cool/issues-helper@v2.0.0 + with: + actions: 'create-label' + token: ${{ secrets.GITHUB_TOKEN }} + label-name: 'xx' + label-color: '0095b3' + label-desc: 'xx' +``` + +| 参数 | 描述 | 类型 | 必填 | +| -- | -- | -- | -- | +| actions | 操作类型 | string | ✔ | +| token | [token 说明](/guide/ref#-token-说明) | string | ✔ | +| label-name | 标签名称,支持 emoji | string | ✔ | +| label-color | 标签颜色,格式为 16 进制色码,不加 `#` | string | ✖ | +| label-desc | 标签描述 | string | ✖ | + +- `label-name`:若已存在,则无操作 +- `label-color`:默认为 `ededed` + ## `delete-comment` 根据 [`comment-id`](/guide/ref#-comment-id) 删除指定评论。 diff --git a/src/base.js b/src/base.js index 83d1910..ca40665 100644 --- a/src/base.js +++ b/src/base.js @@ -132,14 +132,18 @@ async function doCreateLabel(owner, repo) { return false; } - await octokit.issues.createLabel({ - owner, - repo, - name, - color, - description, - }); - core.info(`Actions: [create-label][${name}] success!`); + try { + await octokit.issues.createLabel({ + owner, + repo, + name, + color, + description, + }); + core.info(`Actions: [create-label][${name}] success!`); + } catch (err) { + console.log(err.message) + } } async function doDeleteComment(owner, repo, commentId) { From 4281108d01adccf9e0f82fd4f76b814a3431be15 Mon Sep 17 00:00:00 2001 From: xrkffgg Date: Tue, 2 Feb 2021 20:22:38 +0800 Subject: [PATCH 3/5] format --- src/base.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/base.js b/src/base.js index ca40665..dd5185a 100644 --- a/src/base.js +++ b/src/base.js @@ -142,7 +142,7 @@ async function doCreateLabel(owner, repo) { }); core.info(`Actions: [create-label][${name}] success!`); } catch (err) { - console.log(err.message) + console.log(err.message); } } From f2288b2a14e7eace7fd0d9c9f737fbbfe61d25c7 Mon Sep 17 00:00:00 2001 From: xrkffgg Date: Tue, 2 Feb 2021 20:22:50 +0800 Subject: [PATCH 4/5] add --- .prettierignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.prettierignore b/.prettierignore index f2393dd..53c8968 100644 --- a/.prettierignore +++ b/.prettierignore @@ -2,3 +2,4 @@ dist/ lib/ docs-dist/ node_modules/ +src/.umi/ From 561193570fafed9949420893ee9377e26b09ec0f Mon Sep 17 00:00:00 2001 From: xrkffgg Date: Tue, 2 Feb 2021 20:32:37 +0800 Subject: [PATCH 5/5] up --- README.en-US.md | 2 +- README.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/README.en-US.md b/README.en-US.md index 96410a6..6cd3dde 100644 --- a/README.en-US.md +++ b/README.en-US.md @@ -6,8 +6,8 @@ [![](https://img.shields.io/badge/marketplace-issues--helper-red?style=flat-square)](https://github.com/marketplace/actions/issues-helper) [![dumi](https://img.shields.io/badge/docs%20by-dumi-blue?style=flat-square)](https://github.com/umijs/dumi) [![code style: prettier](https://img.shields.io/badge/code_style-prettier-ff69b4.svg?style=flat-square)](https://github.com/prettier/prettier) -[![](https://img.shields.io/github/v/release/actions-cool/issues-helper?style=flat-square&color=orange)](https://github.com/actions-cool/issues-helper/releases) +[![](https://img.shields.io/github/v/release/actions-cool/issues-helper?style=flat-square&color=orange)](https://github.com/actions-cool/issues-helper/releases) [![](https://img.shields.io/github/stars/actions-cool/issues-helper?style=flat-square)](https://github.com/actions-cool/issues-helper/stargazers) [![](https://img.shields.io/badge/discussions-on%20github-blue?style=flat-square&color=%2308979c)](https://github.com/actions-cool/issues-helper/discussions) [![](https://img.shields.io/github/license/actions-cool/issues-helper?style=flat-square)](https://github.com/actions-cool/issues-helper/blob/main/LICENSE) diff --git a/README.md b/README.md index c21763f..5c8af00 100644 --- a/README.md +++ b/README.md @@ -6,8 +6,8 @@ [![](https://img.shields.io/badge/marketplace-issues--helper-red?style=flat-square)](https://github.com/marketplace/actions/issues-helper) [![dumi](https://img.shields.io/badge/docs%20by-dumi-blue?style=flat-square)](https://github.com/umijs/dumi) [![code style: prettier](https://img.shields.io/badge/code_style-prettier-ff69b4.svg?style=flat-square)](https://github.com/prettier/prettier) -[![](https://img.shields.io/github/v/release/actions-cool/issues-helper?style=flat-square&color=orange)](https://github.com/actions-cool/issues-helper/releases) +[![](https://img.shields.io/github/v/release/actions-cool/issues-helper?style=flat-square&color=orange)](https://github.com/actions-cool/issues-helper/releases) [![](https://img.shields.io/github/stars/actions-cool/issues-helper?style=flat-square)](https://github.com/actions-cool/issues-helper/stargazers) [![](https://img.shields.io/badge/discussions-on%20github-blue?style=flat-square&color=%2308979c)](https://github.com/actions-cool/issues-helper/discussions) [![](https://img.shields.io/github/license/actions-cool/issues-helper?style=flat-square)](https://github.com/actions-cool/issues-helper/blob/main/LICENSE)