Created
November 27, 2021 18:18
-
-
Save natikgadzhi/ce68015e0b789b8e029cdc9f5bed02b5 to your computer and use it in GitHub Desktop.
github-bulk-projects-import.sh
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 | |
# gh-import grabs issues with the query from the given repo, | |
# and imports them to the given GitHub project (beta). | |
# Your github organization goes here | |
GH_ORG= | |
# repository name to import issues from, i.e. org/repo | |
GH_REPO=$GH_ORG/ | |
# How many issues to batch-import. 1k seems like a sane default? | |
GH_LIMIT=1000 | |
# query to grab issues with, i.e. label:bug -label:weird would grab all non-weird bugs. | |
GH_QUERY="is:open label:kanban" | |
# The number in the project URL: https://github.com/orgs/whatever/projects/{{NUMBER}} | |
GH_PROJECT_NUMBER= | |
# Query GitHub projects and grab the project ID that we want. | |
GH_PROJECT_ID=`gh api graphql -f query=' | |
query($GH_PROJECT_NUMBER: Int!, $GH_ORG: String!) { | |
organization(login: $GH_ORG){ | |
projectNext(number: $GH_PROJECT_NUMBER) { | |
id | |
} | |
} | |
}' \ | |
-f GH_ORG=$GH_ORG \ | |
-F GH_PROJECT_NUMBER=$GH_PROJECT_NUMBER \ | |
-q '.data.organization.projectNext.id'` | |
# Grab the list of all issues in the repository matching the query | |
GH_ISSUES=`gh issue list --limit $GH_LIMIT --json id --search "$GH_QUERY" -q '.[] | .id' --repo $GH_REPO` | |
echo "$GH_ISSUES" | while IFS= read -r GH_ISSUE_ID ; do | |
echo "Importing issue $GH_ISSUE_ID" | |
importedId=`gh api graphql -f query='mutation($issueId: String!, $projectId: String!) { | |
addProjectNextItem(input: {projectId: $projectId contentId: $issueId}) { | |
projectNextItem { | |
id | |
} | |
} | |
}' \ | |
-f issueId=$GH_ISSUE_ID \ | |
-f projectId=$GH_PROJECT_ID \ | |
-q '.data.addProjectNextItem.projectNextItem.id'` | |
echo " -> Imported node ID: $importedId" | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment