Created
August 19, 2022 19:28
-
-
Save philip-gai/69ee10c98ce8b6acfc71a1a58b5c07c6 to your computer and use it in GitHub Desktop.
Add open issues of a repository to a ProjectV2 organization project using gh cli
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
#!/bin/bash | |
# This script will add the first 500 open issues of a repository to a ProjectV2 organization project. | |
set -e | |
# Only needed the first time | |
gh auth refresh --scopes project,repo | |
repository_name='<org>/<repo>' | |
project_org='<org>' | |
project_number=<project_number> | |
echo "Getting node id for project $project_org/$project_number" | |
project_node_id=$(gh api graphql -f query=" | |
query{ | |
organization(login: \"$project_org\"){ | |
projectV2(number: $project_number) { | |
id | |
} | |
} | |
}" --jq '.data.organization.projectV2.id') | |
echo "Node ID: $project_node_id" | |
echo "Getting all issues for $repository_name" | |
issueNodeIds=$(gh issue list -R $repository_name -L 500 --json "id" --jq ".[].id") | |
for issueNodeId in $issueNodeIds; do | |
echo "Adding issue $issueNodeId to project $project_org/$project_number" | |
gh api graphql -f query=" | |
mutation { | |
addProjectV2ItemById(input: {projectId: \"$project_node_id\" contentId: \"$issueNodeId\"}) { | |
item { | |
id | |
} | |
} | |
}" | |
done | |
echo "Done" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment