From dc902312cc5630dad7aec5d546ac5faf90cd8a12 Mon Sep 17 00:00:00 2001 From: xrkffgg Date: Tue, 26 Jan 2021 21:38:43 +0800 Subject: [PATCH 1/2] refactor: rename allow-permissions --- README.en-US.md | 11 ++++++----- README.md | 11 ++++++----- action.yml | 2 +- dist/index.js | 21 +++++++++++++++++---- docs/base.en-US.md | 11 ++++++----- docs/base.md | 11 ++++++----- src/base.js | 8 ++++---- src/util.js | 13 +++++++++++++ 8 files changed, 59 insertions(+), 29 deletions(-) diff --git a/README.en-US.md b/README.en-US.md index 67a00c89..760dc786 100644 --- a/README.en-US.md +++ b/README.en-US.md @@ -400,15 +400,16 @@ jobs: | labels | Replace the labels of the issue | string | ✖ | | contents | Add [reaction](#reactions-types) for this comment | string | ✖ | | close-issue | Whether to close the issue at the same time | string | ✖ | -| allow-permissions | Permission to operate | string | ✖ | +| require-permission | Permission required | string | ✖ | - `duplicate-command`: When setting concise commands, while still supporting the original `Duplicate of`. Block content contains `?` - `labels`: Highest priority - `close-issue`: Both `true` or `'true'` can take effect -- `allow-permissions`: When you do not input, there is no limit. Anyone comment will trigger. Optional values are `admin`, `write`, `read`, `none` - - If the team member sets the read permission, it is read - - If the external Collaborator is set to read permission, it is read - - Ordinary users have read permission +- `require-permission`: When you do not input, there is no limit. Anyone comment will trigger. Optional values are `admin`, `write`, `read`, `none` + - If the team member sets the `read` permission, it is `read` + - If the external Collaborator is set to `read` permission, it is `read` + - Ordinary users have `read` permission + - When set `write`, `admin` and `write` meet the conditions ⏫ [Back to list](#List) diff --git a/README.md b/README.md index 7c73a2e8..fa85de0d 100644 --- a/README.md +++ b/README.md @@ -400,15 +400,16 @@ jobs: | labels | 替换该 issue 的 labels | string | ✖ | | contents | 为该评论的增加 [reaction](#reactions-types) | string | ✖ | | close-issue | 是否同时关闭该 issue | string | ✖ | -| allow-permissions | 允许操作的权限 | string | ✖ | +| require-permission | 要求权限 | string | ✖ | - `duplicate-command`:当设置简洁命令时,同时仍支持原有 `Duplicate of`。屏蔽内容包含 `?` - `labels`:优先级最高 - `close-issue`:`true` 或 `'true'` 均可生效 -- `allow-permissions`:当不输时,即无限制。任何人评论都会触发。可选值有 `admin`,`write`,`read`,`none` - - 团队成员若设置 read 权限,则为 read - - 外部 Collaborator 若设置 read 权限,则为 read - - 普通用户为 read 权限 +- `require-permission`:当不输时,即无限制,任何人评论都会触发。可选值有 `admin`,`write`,`read`,`none` + - 团队成员若设置 `read` 权限,则为 `read` + - 外部 Collaborator 若设置 `read` 权限,则为 `read` + - 普通用户为 `read` 权限 + - 当设置 `write` 后,`admin` 和 `write` 满足条件 ⏫ [返回列表](#列-表) diff --git a/action.yml b/action.yml index 5df93ddf..b12e9e06 100644 --- a/action.yml +++ b/action.yml @@ -58,7 +58,7 @@ inputs: description: 'For mark-duplicate' duplicate-labels: description: 'For mark-duplicate add labels' - allow-permissions: + require-permission: description: 'Only the allow can do. Possible admin, write, read, and none.' remove-labels: description: 'For remove labels' diff --git a/dist/index.js b/dist/index.js index 50781ba6..f1e05aca 100644 --- a/dist/index.js +++ b/dist/index.js @@ -7871,7 +7871,7 @@ const ALLREACTIONS = ['+1', '-1', 'laugh', 'confused', 'heart', 'hooray', 'rocke const { doQueryIssues } = __webpack_require__(197); -const { dealStringToArr, dealRandomAssignees, testDuplicate } = __webpack_require__(6254); +const { dealStringToArr, dealRandomAssignees, testDuplicate, checkPermission } = __webpack_require__(6254); // ************************************************************************** const token = core.getInput('token'); @@ -8009,7 +8009,7 @@ async function doMarkDuplicate(owner, repo, labels) { const duplicateLabels = core.getInput('duplicate-labels'); const removeLables = core.getInput('remove-labels'); const closeIssue = core.getInput('close-issue'); - const allowPermissions = core.getInput('allow-permissions'); + const requirePermission = core.getInput('require-permission'); const commentId = context.payload.comment.id; const commentBody = context.payload.comment.body; @@ -8018,14 +8018,14 @@ async function doMarkDuplicate(owner, repo, labels) { const ifCommandInput = !!duplicateCommand; - if (allowPermissions) { + if (requirePermission) { const res = await octokit.repos.getCollaboratorPermissionLevel({ owner, repo, username: commentUser, }); const { permission } = res.data; - if (!allowPermissions.includes(permission)) { + if (!checkPermission(requirePermission, permission)) { core.info(`The user ${commentUser} is not allow!`); return false; } @@ -8706,12 +8706,25 @@ function getPreMonth(m) { return m == 1 ? 12 : m - 1; } +function checkPermission(require, permission) { + /** + * 有权限返回 true + */ + const permissions = ['none', 'read', 'write', 'admin']; + const requireNo = permissions.indexOf(require); + const permissionNo = permissions.indexOf(permission); + + return requireNo <= permissionNo; +} + +// ********************************************************** module.exports = { dealStringToArr, dealRandomAssignees, getPreMonth, matchKeyword, testDuplicate, + checkPermission, }; diff --git a/docs/base.en-US.md b/docs/base.en-US.md index 09b75f71..8ade6aba 100644 --- a/docs/base.en-US.md +++ b/docs/base.en-US.md @@ -264,15 +264,16 @@ jobs: | labels | Replace the labels of the issue | string | ✖ | | contents | Add [reaction](/en-US/guide/ref#-reactions-type) for this comment | string | ✖ | | close-issue | Whether to close the issue at the same time | string | ✖ | -| allow-permissions | Permission to operate | string | ✖ | +| require-permission | Permission required | string | ✖ | - `duplicate-command`: When setting concise commands, while still supporting the original `Duplicate of`. Block content contains `?` - `labels`: Highest priority - `close-issue`: Both `true` or `'true'` can take effect -- `allow-permissions`: When you do not input, there is no limit. Anyone comment will trigger. Optional values are `admin`, `write`, `read`, `none` - - If the team member sets the read permission, it is read - - If the external Collaborator is set to read permission, it is read - - Ordinary users have read permission +- `require-permission`: When you do not input, there is no limit. Anyone comment will trigger. Optional values are `admin`, `write`, `read`, `none` + - If the team member sets the `read` permission, it is `read` + - If the external Collaborator is set to `read` permission, it is `read` + - Ordinary users have `read` permission + - When set `write`, `admin` and `write` meet the conditions 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. diff --git a/docs/base.md b/docs/base.md index 454e1585..13baa450 100644 --- a/docs/base.md +++ b/docs/base.md @@ -264,15 +264,16 @@ jobs: | labels | 替换该 issue 的 labels | string | ✖ | | contents | 为该评论的增加 [reaction](/guide/ref#-reactions-类型) | string | ✖ | | close-issue | 是否同时关闭该 issue | string | ✖ | -| allow-permissions | 允许操作的权限 | string | ✖ | +| require-permission | 要求权限 | string | ✖ | - `duplicate-command`:当设置简洁命令时,同时仍支持原有 `Duplicate of`。屏蔽内容包含 `?` - `labels`:优先级最高 - `close-issue`:`true` 或 `'true'` 均可生效 -- `allow-permissions`:当不输时,即无限制。任何人评论都会触发。可选值有 `admin`,`write`,`read`,`none` - - 团队成员若设置 read 权限,则为 read - - 外部 Collaborator 若设置 read 权限,则为 read - - 普通用户为 read 权限 +- `require-permission`:当不输时,即无限制,任何人评论都会触发。可选值有 `admin`,`write`,`read`,`none` + - 团队成员若设置 `read` 权限,则为 `read` + - 外部 Collaborator 若设置 `read` 权限,则为 `read` + - 普通用户为 `read` 权限 + - 当设置 `write` 后,`admin` 和 `write` 满足条件 注意:使用简洁命令创建的 Duplicate 不显示下图红框内容。但其实这个没有任何影响的。 diff --git a/src/base.js b/src/base.js index 59770e4e..a1d9993f 100644 --- a/src/base.js +++ b/src/base.js @@ -8,7 +8,7 @@ const ALLREACTIONS = ['+1', '-1', 'laugh', 'confused', 'heart', 'hooray', 'rocke const { doQueryIssues } = require('./public.js'); -const { dealStringToArr, dealRandomAssignees, testDuplicate } = require('./util.js'); +const { dealStringToArr, dealRandomAssignees, testDuplicate, checkPermission } = require('./util.js'); // ************************************************************************** const token = core.getInput('token'); @@ -146,7 +146,7 @@ async function doMarkDuplicate(owner, repo, labels) { const duplicateLabels = core.getInput('duplicate-labels'); const removeLables = core.getInput('remove-labels'); const closeIssue = core.getInput('close-issue'); - const allowPermissions = core.getInput('allow-permissions'); + const requirePermission = core.getInput('require-permission'); const commentId = context.payload.comment.id; const commentBody = context.payload.comment.body; @@ -155,14 +155,14 @@ async function doMarkDuplicate(owner, repo, labels) { const ifCommandInput = !!duplicateCommand; - if (allowPermissions) { + if (requirePermission) { const res = await octokit.repos.getCollaboratorPermissionLevel({ owner, repo, username: commentUser, }); const { permission } = res.data; - if (!allowPermissions.includes(permission)) { + if (!checkPermission(requirePermission, permission)) { core.info(`The user ${commentUser} is not allow!`); return false; } diff --git a/src/util.js b/src/util.js index f76e4669..39043841 100644 --- a/src/util.js +++ b/src/util.js @@ -46,10 +46,23 @@ function getPreMonth(m) { return m == 1 ? 12 : m - 1; } +function checkPermission(require, permission) { + /** + * 有权限返回 true + */ + const permissions = ['none', 'read', 'write', 'admin']; + const requireNo = permissions.indexOf(require); + const permissionNo = permissions.indexOf(permission); + + return requireNo <= permissionNo; +} + +// ********************************************************** module.exports = { dealStringToArr, dealRandomAssignees, getPreMonth, matchKeyword, testDuplicate, + checkPermission, }; From 2e62d0e2d44b68ca22001ec431876b2ca180730b Mon Sep 17 00:00:00 2001 From: xrkffgg Date: Tue, 26 Jan 2021 21:45:29 +0800 Subject: [PATCH 2/2] up --- dist/index.js | 7 ++++++- src/base.js | 7 ++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/dist/index.js b/dist/index.js index f1e05aca..b85b3edf 100644 --- a/dist/index.js +++ b/dist/index.js @@ -7871,7 +7871,12 @@ const ALLREACTIONS = ['+1', '-1', 'laugh', 'confused', 'heart', 'hooray', 'rocke const { doQueryIssues } = __webpack_require__(197); -const { dealStringToArr, dealRandomAssignees, testDuplicate, checkPermission } = __webpack_require__(6254); +const { + dealStringToArr, + dealRandomAssignees, + testDuplicate, + checkPermission, +} = __webpack_require__(6254); // ************************************************************************** const token = core.getInput('token'); diff --git a/src/base.js b/src/base.js index a1d9993f..903f231c 100644 --- a/src/base.js +++ b/src/base.js @@ -8,7 +8,12 @@ const ALLREACTIONS = ['+1', '-1', 'laugh', 'confused', 'heart', 'hooray', 'rocke const { doQueryIssues } = require('./public.js'); -const { dealStringToArr, dealRandomAssignees, testDuplicate, checkPermission } = require('./util.js'); +const { + dealStringToArr, + dealRandomAssignees, + testDuplicate, + checkPermission, +} = require('./util.js'); // ************************************************************************** const token = core.getInput('token');