From f6788d2b8ed6c23be9be04007904584db3f2db12 Mon Sep 17 00:00:00 2001 From: xrkffgg Date: Tue, 2 Feb 2021 17:55:54 +0800 Subject: [PATCH] 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;