Last active
September 19, 2023 16:05
-
-
Save jstlaurent/720189096d5e3a05e853c969cbcfc0ca to your computer and use it in GitHub Desktop.
Fish shell script to move issues between GitHub projects
This file contains 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
set source_owner "<source_owner_name>" | |
set source_project "<source_project_number>" | |
set destination_owner "<destination_owner_name>" | |
set destination_project "<destination_project_number>" | |
set destination_project_id (gh project view --format=json --owner=$destination_owner $destination_project | jq -r '.id') | |
# Fetch all source_items from the source project | |
set source_items (gh project item-list --limit=1000 --format=json --owner=$source_owner $source_project | jq -c '.items[]') | |
# Loop through each item, add it to the destination project | |
for item in $source_items | |
set url (echo $item | jq -r '.content.url') | |
gh project item-add --owner=$destination_owner --url=$url $destination_project | |
end | |
# Get the status field ID for the destination project | |
set status_field (gh project field-list --format=json --owner=$destination_owner $destination_project | jq -r '.fields[] | select(.name == "Status")') | |
set status_field_id (echo $status_field | jq --slurp -r '.[].id') | |
# Loop through new source_items in the destination project and set their status | |
set destination_items (gh project item-list --limit=1000 --format=json --owner=$destination_owner $destination_project | jq -c '.items[]') | |
for item in $destination_items | |
set id (echo $item | jq -r '.id') | |
set -x number (echo $item | jq -r '.content.number') | |
# Convert the string status to the corresponding field option ID | |
set stat_string (echo $source_items | jq --slurp --argjson nbr $number -r '.[] | select(.content.number == $nbr) | .status') | |
set stat (echo $status_field | jq --slurp -r --arg name $stat_string '.[].options[] | select(.name == $name) | .id') | |
echo "id: $id, number: $number, stat: $stat, stat_string: $stat_string" | |
gh project item-edit --project-id=$destination_project_id --id=$id --field-id=$status_field_id --single-select-option-id=$stat | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment