Skip to content

Commit 25c5e8c

Browse files
author
yashksaini-coder
committed
feat: 🎸 Main invite script
1 parent 335c00e commit 25c5e8c

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed

.github/scripts/invite.js

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
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}`));

0 commit comments

Comments
 (0)