Created
September 3, 2024 12:13
-
-
Save heyajulia/9f965e036043186606b628b0444700cf to your computer and use it in GitHub Desktop.
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 | |
| # How to use this script: | |
| # | |
| # 1. gh auth logout | |
| # 2. gh auth login --scopes "project,read:project" | |
| # 3. gh api graphql --cache 5m --jq ".data.user.projectV2.id" -f query='query { user(login: "octocat") { projectV2(number: 42) { id } } }' | |
| # | |
| # Replace "octocat" with your GitHub username and "42" with the project number, and add the project ID to the script. | |
| # 4. Create a file named "issues.txt" with one issue title per line. | |
| # 5. chmod +x add_issues.sh | |
| # 6. ./add_issues.sh | |
| # | |
| # Perhaps this is not the best way, but it worked for me. Once the issues have been imported, you can select them all | |
| # in the web UI and move them to the "Todo" column. | |
| set -euxo pipefail | |
| # File containing issue titles | |
| FILE="issues.txt" | |
| # Your GitHub project ID | |
| PROJECT_ID="" | |
| escape_title() { | |
| printf '%s' "$1" | sed 's/"/\\"/g' | sed "s/'/\\'/g" | |
| } | |
| add_issues_one_by_one() { | |
| while IFS= read -r title || [[ -n "$title" ]]; do | |
| if [[ -n "$title" ]]; then | |
| escaped_title=$(escape_title "$title") | |
| query=$(printf 'mutation { | |
| addProjectV2DraftIssue(input: {projectId: "%s" title: "%s" body: ""}) { | |
| projectItem { | |
| id | |
| } | |
| } | |
| }' "$PROJECT_ID" "$escaped_title") | |
| gh api graphql --silent -f query="$query" | |
| fi | |
| done < "$FILE" | |
| } | |
| add_issues_one_by_one | |
| echo "All draft issues have been added to the project." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment