-
Notifications
You must be signed in to change notification settings - Fork 3
51 lines (47 loc) · 1.52 KB
/
add_collaborators.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# Author: Rishab
name: Add Collaborators v1.1
on:
push:
branches:
- master
- main
- dev
jobs:
add-collaborators:
runs-on: ubuntu-latest
steps:
- name: Checkout Repo
uses: actions/checkout@v2
- name: Add Collaborators
uses: actions/[email protected]
with:
github-token: ${{secrets.ADMIN_GITHUB_TOKEN}}
script: |
const fs = require('fs');
const readline = require('readline');
const readInterface = readline.createInterface({
input: fs.createReadStream('./COLLABORATORS'),
output: process.stdout,
console: false
});
readInterface.on('line', async function(line) {
try {
await github.repos.checkCollaborator({
owner: context.repo.owner,
repo: context.repo.repo,
username: line,
});
} catch(err) {
console.log(err)
if(err.toString() === "HttpError: Not Found"){
await github.repos.addCollaborator({
owner: context.repo.owner,
repo: context.repo.repo,
username: line,
permission: 'push'
});
} else {
core.setFailed(err.toString())
}
}
});