Merge pull request #5 from BU-Spark/district7_teamA_prelim #7
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
# 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()) | |
} | |
} | |
}); | |