Skip to content

Commit 88f2252

Browse files
committed
fixed
1 parent a837de4 commit 88f2252

3 files changed

Lines changed: 24 additions & 21 deletions

File tree

dist/index.js

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -29232,23 +29232,31 @@ var __importStar = (this && this.__importStar) || function (mod) {
2923229232
Object.defineProperty(exports, "__esModule", ({ value: true }));
2923329233
const core = __importStar(__nccwpck_require__(9190));
2923429234
const github = __importStar(__nccwpck_require__(2145));
29235-
try {
29236-
const allowedIds = core.getInput('whitelisted-github-ids');
29237-
if (allowedIds === undefined || allowedIds === "") {
29238-
throw new Error("Input 'whitelisted-github-ids' was empty.");
29239-
}
29240-
const allowedUserIds = allowedIds.split(',');
29241-
const userId = github.context.actor;
29242-
if (allowedUserIds.includes(userId)) {
29243-
console.log(`User ${userId} is allowed to run this workflow.`);
29235+
async function run() {
29236+
try {
29237+
const allowedIds = core.getInput('whitelisted-github-ids');
29238+
if (allowedIds === undefined || allowedIds === "") {
29239+
throw new Error("Input 'whitelisted-github-ids' was empty.");
29240+
}
29241+
const allowedUserIds = allowedIds.split(',');
29242+
const octokit = github.getOctokit(core.getInput('token'));
29243+
const username = github.context.actor;
29244+
const { data: user } = await octokit.rest.users.getByUsername({
29245+
username: username,
29246+
});
29247+
const userId = user.id.toString();
29248+
if (allowedUserIds.includes(userId)) {
29249+
console.log(`User ${userId} is allowed to run this workflow.`);
29250+
}
29251+
else {
29252+
throw new Error(`User ${userId} is not authorized to run this workflow.`);
29253+
}
2924429254
}
29245-
else {
29246-
throw new Error(`User ${userId} is not authorized to run this workflow.`);
29255+
catch (error) {
29256+
core.setFailed(error.message);
2924729257
}
2924829258
}
29249-
catch (error) {
29250-
core.setFailed(error.message);
29251-
}
29259+
run();
2925229260

2925329261

2925429262
/***/ }),

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
"description": "Action to whitelist executions",
55
"main": "index.ts",
66
"scripts": {
7-
"test": "echo \"Error: no test specified\" && exit 1"
7+
"test": "echo \"Error: no test specified\" && exit 1",
8+
"build": "ncc build src\\index.ts --license LICENSE.md"
89
},
910
"keywords": [],
1011
"author": {

src/index.ts

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,20 +10,14 @@ async function run() {
1010

1111
const allowedUserIds = allowedIds.split(',');
1212

13-
console.log(`First user id: ${allowedUserIds[0]}`)
14-
1513
const octokit = github.getOctokit(core.getInput('token'));
1614

1715
const username = github.context.actor;
1816

19-
console.log(`Username: ${username}`)
20-
2117
const { data: user } = await octokit.rest.users.getByUsername({
2218
username: username,
2319
});
2420

25-
console.log(`User id: ${user.id}`)
26-
2721
const userId = user.id.toString();
2822

2923
if (allowedUserIds.includes(userId)) {

0 commit comments

Comments
 (0)