Skip to content

Commit 4b841f9

Browse files
committed
Update index.ts
1 parent 9cd2a1b commit 4b841f9

1 file changed

Lines changed: 25 additions & 13 deletions

File tree

src/index.ts

Lines changed: 25 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,33 @@
11
import * as core from '@actions/core';
22
import * as github from '@actions/github';
33

4-
try {
5-
const allowedIds = core.getInput('whitelisted-github-ids');
6-
if (allowedIds === undefined || allowedIds === "") {
7-
throw new Error("Input 'whitelisted-github-ids' was empty.")
8-
}
4+
async function run() {
5+
try {
6+
const allowedIds = core.getInput('whitelisted-github-ids');
7+
if (allowedIds === undefined || allowedIds === "") {
8+
throw new Error("Input 'whitelisted-github-ids' was empty.")
9+
}
10+
11+
const allowedUserIds = allowedIds.split(',');
12+
13+
const octokit = github.getOctokit(core.getInput('GITHUB_TOKEN'));
914

10-
const allowedUserIds = allowedIds.split(',');
15+
const username = github.context.actor;
1116

12-
const userId = github.context.actor;
17+
const { data: user } = await octokit.rest.users.getByUsername({
18+
username: username,
19+
});
1320

14-
if (allowedUserIds.includes(userId)) {
15-
console.log(`User ${userId} is allowed to run this workflow.`);
16-
} else {
17-
throw new Error(`User ${userId} is not authorized to run this workflow.`);
21+
const userId = user.id.toString();
22+
23+
if (allowedUserIds.includes(userId)) {
24+
console.log(`User ${userId} is allowed to run this workflow.`);
25+
} else {
26+
throw new Error(`User ${userId} is not authorized to run this workflow.`);
27+
}
28+
} catch (error: any) {
29+
core.setFailed(error.message);
1830
}
19-
} catch (error: any) {
20-
core.setFailed(error.message);
2131
}
32+
33+
run();

0 commit comments

Comments
 (0)