File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11import * as core from '@actions/core' ;
22import * 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 ( ) ;
You can’t perform that action at this time.
0 commit comments