GitHub: Script to Add Users to a Project
Add users to a GitHub ProjectV2 programmatically
Overview
We’re often adding new users to Projects (ProjectsV2) in GitHub, and previously, it was all manual work in the UI. I wanted to automate this, but found the updateProjectV2Collaborators
mutation a little tricky to figure out. After some trial and error, I was able to get it working and wanted to share the script I created to add users to a GitHub Project.
The Script
The script is in my github-misc-scripts repo:
Using the Script
Usage
1
Usage: ./add-user-to-project.sh <org> <repo> <project-number> <user> <role>
Example:
1
./add-user-to-project.sh joshjohanning-org my-repo 1234 joshjohanning ADMIN
Notes:
- You need the
project
scope, e.g.:gh auth login -s project
- Role options:
ADMIN
,WRITER
,READER
,NONE
Summary
Hopefully this speeds up your adding of users to an Organization Project in GitHub! 🚀
See my other ProjectsV2 scripts:
This post is licensed under CC BY 4.0 by the author.