|
| 1 | +# Script Name: issue-list-generator.sh |
| 2 | +# Description: Generates a list of issues from a specified GitHub repository and formats them for Confluence. |
| 3 | + |
| 4 | +# Requires: |
| 5 | +# - gh: GitHub CLI (https://github.com/cli/cli) |
| 6 | +# - jq: Command-line JSON processor (https://github.com/stedolan/jq) |
| 7 | + |
| 8 | +# Usage: |
| 9 | +# sh ./issue-list-generator.sh -d "<default_charge_account>" -i "<improvement_charge_account>" -f "<defect_charge_account>" |
| 10 | +# Then in the confluence page, insert markup and select "Confluence Wiki" as the format and paste the output. |
| 11 | + |
| 12 | +# Notes: |
| 13 | +# - Ensure you have the necessary permissions to access the GitHub repository. |
| 14 | +# - Customize the REPO, MILESTONE_NUMBERS, and LABELS variables as needed. |
| 15 | + |
| 16 | + |
| 17 | +# Change as needed |
| 18 | +REPO="NASA-AMMOS/openmct-mcws" |
| 19 | +MILESTONE_NUMBERS=("11") |
| 20 | +MILESTONE_TITLES=() # will be populated with titles mapped to milestone nnumbers |
| 21 | +LABELS=("commitment" "improvement" "defect" "sustaining" "other") |
| 22 | + |
| 23 | +# Default charge accounts |
| 24 | +CHARGE_ACCOUNT_DEFAULT="N/A" |
| 25 | +CHARGE_ACCOUNT_IMPROVEMENT="N/A" |
| 26 | +CHARGE_ACCOUNT_DEFECT="N/A" |
| 27 | + |
| 28 | +# Parse command-line arguments |
| 29 | +while getopts "d:i:f:" opt; do |
| 30 | + case $opt in |
| 31 | + d) CHARGE_ACCOUNT_DEFAULT="$OPTARG" |
| 32 | + ;; |
| 33 | + i) CHARGE_ACCOUNT_IMPROVEMENT="$OPTARG" |
| 34 | + ;; |
| 35 | + f) CHARGE_ACCOUNT_DEFECT="$OPTARG" |
| 36 | + ;; |
| 37 | + \?) echo "Invalid option -$OPTARG" >&2 |
| 38 | + exit 1 |
| 39 | + ;; |
| 40 | + esac |
| 41 | +done |
| 42 | + |
| 43 | +# Fetch and store milestone titles from their numbers |
| 44 | +for i in "${!MILESTONE_NUMBERS[@]}"; do |
| 45 | + MILESTONE_TITLES[$i]=$(gh api repos/$REPO/milestones/${MILESTONE_NUMBERS[$i]} --jq '.title' -H "Accept: application/vnd.github.v3+json") |
| 46 | +done |
| 47 | + |
| 48 | +# Get the heading based on the label |
| 49 | +get_heading() { |
| 50 | + case $1 in |
| 51 | + "commitment") |
| 52 | + echo "Requirements" |
| 53 | + ;; |
| 54 | + "improvement") |
| 55 | + echo "Improvements" |
| 56 | + ;; |
| 57 | + "defect") |
| 58 | + echo "Defect Repairs" |
| 59 | + ;; |
| 60 | + "sustaining") |
| 61 | + echo "Sustaining Activities" |
| 62 | + ;; |
| 63 | + "other") |
| 64 | + echo "Other" |
| 65 | + ;; |
| 66 | + *) |
| 67 | + echo "Uknown" |
| 68 | + ;; |
| 69 | + esac |
| 70 | +} |
| 71 | + |
| 72 | +# Get Release Version by milestone |
| 73 | +get_release() { |
| 74 | + case $1 in |
| 75 | + "11") |
| 76 | + echo "MC 2512 Point Release 1" |
| 77 | + ;; |
| 78 | + "12") |
| 79 | + echo "MC 2512 Point Release 2" |
| 80 | + ;; |
| 81 | + "13") |
| 82 | + echo "MC 2512 Point Release 3" |
| 83 | + ;; |
| 84 | + *) |
| 85 | + echo "Uknown" |
| 86 | + ;; |
| 87 | + esac |
| 88 | +} |
| 89 | + |
| 90 | +# Function to extract a variable from the issue body |
| 91 | +extract_variable() { |
| 92 | + local var_name=$1 |
| 93 | + local issue_body=$2 |
| 94 | + local value=$(echo "$issue_body" | sed -n "s/.*\$\$$var_name:\(.*\).*/\1/p" | tr -d '\n' | tr -d '\r') |
| 95 | + |
| 96 | + if [[ "$var_name" == "ask" && -n "$value" ]]; then |
| 97 | + echo "[ASK-$value|https://jira.jpl.nasa.gov/browse/ASK-$value]" |
| 98 | + elif [[ "$var_name" == "mcr" && -n "$value" ]]; then |
| 99 | + echo "[MCR-$value|https://jira.jpl.nasa.gov/browse/MCR-$value]" |
| 100 | + elif [[ -n "$value" ]]; then |
| 101 | + echo "$value" |
| 102 | + elif [[ "$var_name" == "ask" || "$var_name" == "mcr" ]]; then |
| 103 | + echo "" |
| 104 | + else |
| 105 | + echo "N/A" |
| 106 | + fi |
| 107 | +} |
| 108 | + |
| 109 | +# List issues for a specific label and format as a Confluence wiki table |
| 110 | +list_issues() { |
| 111 | + local label=$1 |
| 112 | + local heading=$(get_heading $label) |
| 113 | + local columns |
| 114 | + local jq_filter='.[] | @base64' |
| 115 | + |
| 116 | + # Constructing the milestone part of the URL |
| 117 | + local milestone_part="" |
| 118 | + for i in "${!MILESTONE_TITLES[@]}"; do |
| 119 | + if [[ -n "$milestone_part" ]]; then |
| 120 | + milestone_part+="," |
| 121 | + fi |
| 122 | + milestone_part+="\"${MILESTONE_TITLES[$i]}\"" |
| 123 | + done |
| 124 | + |
| 125 | + # Loop through provided milestones and pool the issues |
| 126 | + local issues="" |
| 127 | + for i in "${!MILESTONE_NUMBERS[@]}"; do |
| 128 | + local milestone_number=${MILESTONE_NUMBERS[i]} |
| 129 | + local issue_data=$(gh issue list --repo "$REPO" --milestone "$milestone_number" --label "$label" --state all --json number,title,url,labels,body --jq "$jq_filter") |
| 130 | + local planned_release=$(get_release $milestone_number) |
| 131 | + |
| 132 | + while IFS= read -r line; do |
| 133 | + # Check if no issue |
| 134 | + if [ -z "$line" ]; then |
| 135 | + break |
| 136 | + fi |
| 137 | + |
| 138 | + local issue_body=$(echo "$line" | base64 --decode | jq '.body') |
| 139 | + local issue_number=$(echo "$line" | base64 --decode | jq -r '.number') |
| 140 | + local issue_title=$(echo "$line" | base64 --decode | jq -r '.title') |
| 141 | + local issue_url=$(echo "$line" | base64 --decode | jq -r '.url') |
| 142 | + local ask=$(extract_variable "ask" "$issue_body") |
| 143 | + local mcr=$(extract_variable "mcr" "$issue_body") |
| 144 | + local related_issue=$(printf '%s%s%s' "$ask" "${ask:+${mcr:+, }}$mcr") |
| 145 | + local rationale=$(extract_variable "rationale" "$issue_body") |
| 146 | + local reporter=$(extract_variable "reporter" "$issue_body") |
| 147 | + local estimated_hours=$(extract_variable "estimate" "$issue_body") |
| 148 | + local requester=$(extract_variable "requester" "$issue_body") |
| 149 | + local doc_id=$(extract_variable "docid" "$issue_body") |
| 150 | + local issue_labels=$(echo "$line" | base64 --decode | jq -r '.labels | map(.name) | join(", ")') |
| 151 | + local criticality=$(echo "$issue_labels" | grep -o 'crit-[1-4]' | sed 's/crit-//' || echo "N/A") |
| 152 | + criticality=${criticality:-N/A} |
| 153 | + local is_security_related="n" |
| 154 | + if [[ $issue_labels == *"security"* ]]; then |
| 155 | + is_security_related="y" |
| 156 | + fi |
| 157 | + |
| 158 | + # Select charge account based on label |
| 159 | + local charge_account=$CHARGE_ACCOUNT_DEFAULT |
| 160 | + if [[ "$label" == "improvement" ]]; then |
| 161 | + charge_account=$CHARGE_ACCOUNT_IMPROVEMENT |
| 162 | + elif [[ "$label" == "defect" ]]; then |
| 163 | + charge_account=$CHARGE_ACCOUNT_DEFECT |
| 164 | + fi |
| 165 | + |
| 166 | + # Define columns and extract variables based on label |
| 167 | + case $label in |
| 168 | + "commitment") |
| 169 | + columns="|| *ID* || *Title* || *Rational/Issue (PRS/ASK/MCR)* || *Rationale* || *Requester/Reporter* || *Estimated Hours* || *Charge Account* || *Security Related (y/n)* || *Release Version* ||" |
| 170 | + issues="| [$issue_number|$issue_url] | $issue_title | ${related_issue} | ${rationale} | ${reporter} | ${estimated_hours} | ${charge_account} | ${is_security_related} | ${planned_release} |\n$issues" |
| 171 | + ;; |
| 172 | + "improvement") |
| 173 | + columns="|| *ID* || *Title* || *Rational/Issue (PRS/ASK/MCR)* || *Requester/Reporter* || *Estimated Hours* || *Charge Account* || *Security Related (y/n)* || *Release Version* ||" |
| 174 | + issues="| [$issue_number|$issue_url] | $issue_title | ${related_issue} | ${reporter} | ${estimated_hours} | ${charge_account} | ${is_security_related} | ${planned_release} |\n$issues" |
| 175 | + ;; |
| 176 | + "defect") |
| 177 | + columns="|| *ID* || *Title* || *Rational/Issue (PRS/ASK/MCR)* || *Requester/Reporter* || *Estimated Hours* || *Charge Account* || *Security Related (y/n)* || *Criticality* || *Release Version* ||" |
| 178 | + issues="| [$issue_number|$issue_url] | $issue_title | ${related_issue} | ${reporter} | ${estimated_hours} | ${charge_account} | ${is_security_related} | ${criticality} | ${planned_release} |\n$issues" |
| 179 | + ;; |
| 180 | + "sustaining") |
| 181 | + columns="|| *ID* || *Title* || *Rational/Issue (PRS/ASK/MCR)* || *Requester/Reporter* || *Estimated Hours* || *Charge Account* || *Security Related (y/n)* || *Release Version* ||" |
| 182 | + issues="| [$issue_number|$issue_url] | $issue_title | ${rationale} | ${requester} | ${estimated_hours} | ${charge_account} | ${is_security_related} | ${planned_release} |\n$issues" |
| 183 | + ;; |
| 184 | + "other") |
| 185 | + columns="|| *ID* || *Title* || *Doc-id* || *Requester/Reporter* || *Estimated Hours* || *Charge Account* || *Security Related (y/n)* || *Release Version* ||" |
| 186 | + issues="| [$issue_number|$issue_url] | $issue_title | ${doc_id} | ${requester} | ${estimated_hours} | ${charge_account} | ${is_security_related} | ${planned_release} |\n$issues" |
| 187 | + ;; |
| 188 | + esac |
| 189 | + done <<< "$issue_data" |
| 190 | + |
| 191 | + done |
| 192 | + |
| 193 | + echo "h3. $heading" |
| 194 | + echo "*Repository*: [openmct-mcws|https://github.com/NASA-AMMOS/openmct-mcws]" |
| 195 | + |
| 196 | + if [[ -z "$issues" ]]; then |
| 197 | + echo None. |
| 198 | + else |
| 199 | + echo "$columns" |
| 200 | + echo "$issues" |
| 201 | + fi |
| 202 | + echo |
| 203 | +} |
| 204 | + |
| 205 | +# Main Script |
| 206 | +for label in "${LABELS[@]}"; do |
| 207 | + list_issues "$label" |
| 208 | +done |
0 commit comments