File tree Expand file tree Collapse file tree 1 file changed +43
-0
lines changed Expand file tree Collapse file tree 1 file changed +43
-0
lines changed Original file line number Diff line number Diff line change 1+ import fetch from 'node-fetch' ;
2+
3+ let GITHUB_TOKEN = '' ;
4+ const OWNER = 'recodehive' ;
5+ const REPO = 'Job-Seeker' ;
6+
7+ async function sendInvite ( username ) {
8+ const url = `https://api.github.com/repos/${ OWNER } /${ REPO } /collaborators/${ username } ` ;
9+
10+ const response = await fetch ( url , {
11+ method : 'PUT' ,
12+ headers : {
13+ 'Authorization' : `token ${ GITHUB_TOKEN } ` ,
14+ 'Accept' : 'application/vnd.github.v3+json' ,
15+ } ,
16+ body : JSON . stringify ( {
17+ permission : 'pull' ,
18+ } ) ,
19+ } ) ;
20+
21+ if ( response . ok ) {
22+ console . log ( `Success: Invitation sent to ${ username } for the repository ${ OWNER } /${ REPO } ` ) ;
23+ } else {
24+ const error = await response . json ( ) ;
25+ console . error ( `Error: ${ response . status } - ${ error . message } ` ) ;
26+ }
27+ }
28+
29+ const username = process . argv [ 2 ] ;
30+ const token = process . argv [ 3 ] ;
31+ if ( ! username ) {
32+ console . error ( 'Error: Please provide a username as an argument.' ) ;
33+ process . exit ( 1 ) ;
34+ }
35+ else if ( ! token ) {
36+ console . error ( 'Error: Please provide a token as an argument.' ) ;
37+ process . exit ( 1 ) ;
38+ }
39+ else {
40+ GITHUB_TOKEN = token ;
41+ }
42+
43+ sendInvite ( username , token ) . catch ( ( err ) => console . error ( `Unexpected Error: ${ err . message } ` ) ) ;
You can’t perform that action at this time.
0 commit comments