File tree Expand file tree Collapse file tree 2 files changed +61
-17
lines changed Expand file tree Collapse file tree 2 files changed +61
-17
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 } ` ) ) ;
Original file line number Diff line number Diff line change 1- name : Process Access Requests
1+ name : Send GitHub Collaborator Invite from Issue
22
33on :
44 issues :
5- types :
6- - closed
5+ types : [closed]
76
87jobs :
9- invite-user :
8+ send-invite :
9+
1010 if : contains(github.event.issue.labels.*.name, 'access-request')
1111 runs-on : ubuntu-latest
1212
1313 steps :
14- - name : Invite User to Private Repo
15- env :
16- TOKEN : ${{ secrets.GITHUB_TOKEN }}
17- USERNAME : ${{ github.event.issue.user.login }}
18- run : |
19- curl -X PUT \
20- -H "Authorization: token $TOKEN" \
21- -H "Accept: application/vnd.github.v3+json" \
22- https://api.github.com/repos/recodehive/Opensource-practice/collaborators/${USERNAME} \
23- -d '{"permission": "pull"}'
14+ - name : Checkout repository
15+ uses : actions/checkout@v3
16+
17+ - name : Set up Node.js
18+ uses : actions/setup-node@v3
19+ with :
20+ node-version : 16
2421
25- - name : Handle Errors
26- if : failure()
27- run : echo "An error occurred while processing the request."
22+ - name : Invite User to Private Repo
23+ env :
24+ TOKEN : ${{ secrets.GH_TOKEN }}
25+ USERNAME : ${{ github.event.issue.user.login }}
26+ run : |
27+ npm install
28+ node scripts/invite.js $USERNAME $TOKEN
You can’t perform that action at this time.
0 commit comments