#!/bin/bash # This script fetches all the issues from a GitHub project and saves them in a JSON file. # It needs the GitHub CLI to be installed and configured. # You can find the GitHub CLI here: https://cli.github.com/ PROJECT=$1 # Check if the project is set if [ -z "$PROJECT" ]; then echo "Usage: $0 [open|closed|all]" exit 1 fi # Set the state STATE=${2:-open} # Set the target file name TARGET_FILE="$(echo ${PROJECT}|sed -r 's/\//-/g')_$(date +"%Y-%m-%d-%H-%M-%S").json" # Check if the file already exists if [ -f "${TARGET_FILE}" ]; then echo "File ${TARGET_FILE} already exists" exit 1 fi # Create the file touch "${TARGET_FILE}" # Fetch the issues echo "Fetching issues from $1" ISSUES_NUMBERS=$(gh issue list -R "${PROJECT}" -s "${STATE}" -L 10000000 |awk '{print $1}') ISSUES_OUTPUT="" # Process the issues for ISSUE_NUMBER in $ISSUES_NUMBERS do echo "Processing issue $ISSUE_NUMBER" ISSUE=$(gh issue view "${ISSUE_NUMBER}" -R "${PROJECT}" --json assignees,author,body,closed,closedAt,comments,createdAt,id,isPinned,labels,milestone,number,projectCards,projectItems,reactionGroups,state,stateReason,title,updatedAt,url |jq .) # Append the issue to the file printf "\n---\n%s\n" "${ISSUE}" >> "${TARGET_FILE}" done # Display the file cat "${TARGET_FILE}"