-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #490 from yashksaini-coder/repo-access
Invite user request workflow
- Loading branch information
Showing
2 changed files
with
61 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import fetch from 'node-fetch'; | ||
|
||
let GITHUB_TOKEN = ''; | ||
const OWNER = 'recodehive'; | ||
const REPO = 'Job-Seeker'; | ||
|
||
async function sendInvite(username) { | ||
const url = `https://api.github.com/repos/${OWNER}/${REPO}/collaborators/${username}`; | ||
|
||
const response = await fetch(url, { | ||
method: 'PUT', | ||
headers: { | ||
'Authorization': `token ${GITHUB_TOKEN}`, | ||
'Accept': 'application/vnd.github.v3+json', | ||
}, | ||
body: JSON.stringify({ | ||
permission: 'pull', | ||
}), | ||
}); | ||
|
||
if (response.ok) { | ||
console.log(`Success: Invitation sent to ${username} for the repository ${OWNER}/${REPO}`); | ||
} else { | ||
const error = await response.json(); | ||
console.error(`Error: ${response.status} - ${error.message}`); | ||
} | ||
} | ||
|
||
const username = process.argv[2]; | ||
const token = process.argv[3]; | ||
if (!username) { | ||
console.error('Error: Please provide a username as an argument.'); | ||
process.exit(1); | ||
} | ||
else if (!token) { | ||
console.error('Error: Please provide a token as an argument.'); | ||
process.exit(1); | ||
} | ||
else { | ||
GITHUB_TOKEN = token; | ||
} | ||
|
||
sendInvite(username,token ).catch((err) => console.error(`Unexpected Error: ${err.message}`)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,28 @@ | ||
name: Process Access Requests | ||
name: Send GitHub Collaborator Invite from Issue | ||
|
||
on: | ||
issues: | ||
types: | ||
- closed | ||
types: [closed] | ||
|
||
jobs: | ||
invite-user: | ||
send-invite: | ||
|
||
if: contains(github.event.issue.labels.*.name, 'access-request') | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Invite User to Private Repo | ||
env: | ||
TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
USERNAME: ${{ github.event.issue.user.login }} | ||
run: | | ||
curl -X PUT \ | ||
-H "Authorization: token $TOKEN" \ | ||
-H "Accept: application/vnd.github.v3+json" \ | ||
https://api.github.com/repos/recodehive/Opensource-practice/collaborators/${USERNAME} \ | ||
-d '{"permission": "pull"}' | ||
- name: Checkout repository | ||
uses: actions/checkout@v3 | ||
|
||
- name: Set up Node.js | ||
uses: actions/setup-node@v3 | ||
with: | ||
node-version: 16 | ||
|
||
- name: Handle Errors | ||
if: failure() | ||
run: echo "An error occurred while processing the request." | ||
- name: Invite User to Private Repo | ||
env: | ||
TOKEN: ${{ secrets.GH_TOKEN }} | ||
USERNAME: ${{ github.event.issue.user.login }} | ||
run: | | ||
npm install | ||
node scripts/invite.js $USERNAME $TOKEN |