-
-
Save Uvacoder/e8682526b2cf40845da49fe3a2e2d3f6 to your computer and use it in GitHub Desktop.
Add GitHub user to private GitHub repo utility function
This file contains hidden or 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
| const axios = require('axios') | |
| const GITHUB_REPO = process.env.GITHUB_REPO | |
| const GITHUB_API_TOKEN = process.env.GITHUB_API_TOKEN | |
| const GITHUB_USERNAME = process.env.GITHUB_USERNAME | |
| module.exports = function addUserToGithubRepo(username) { | |
| const githubEndpoint = `https://api.github.com/repos/${GITHUB_REPO}/collaborators/${username}` | |
| const config = { | |
| 'headers': { | |
| 'User-Agent': GITHUB_USERNAME, | |
| 'Authorization': `token ${GITHUB_API_TOKEN}` | |
| } | |
| } | |
| return axios.put(githubEndpoint, { | |
| "permission": "pull" | |
| }, config).then(function(response) { | |
| if (response.status === 204 || response.status === 201) { | |
| console.log(`${username} added`) | |
| return true | |
| } | |
| console.log(`${username} added ad collaborator`, response) | |
| return false | |
| }).catch((e) => { | |
| console.log(e) | |
| return e | |
| }) | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment