|
| 1 | +#!/bin/bash |
| 2 | + |
| 3 | +# Gets the sub-issue summary of an issue |
| 4 | + |
| 5 | +if [ -z "$3" ]; then |
| 6 | + echo "Usage: $0 <org> <repo> <issue-number>" |
| 7 | + echo "Example: ./get-sub-issues-of-issue.sh joshjohanning-org migrating-ado-to-gh-issues-v2 5" |
| 8 | + exit 1 |
| 9 | +fi |
| 10 | + |
| 11 | +org="$1" |
| 12 | +repo="$2" |
| 13 | +issue_number="$3" |
| 14 | + |
| 15 | +# Define color codes |
| 16 | +RED='\033[0;31m' |
| 17 | +YELLOW='\033[0;33m' |
| 18 | +NC='\033[0m' # No Color |
| 19 | + |
| 20 | +# Fetch the issue ID given the issue number |
| 21 | +issue_id=$(gh api graphql -f owner="$org" -f repository="$repo" -F number="$issue_number" -f query=' |
| 22 | +query ($owner: String!, $repository: String!, $number: Int!) { |
| 23 | + repository(owner: $owner, name: $repository) { |
| 24 | + issue(number: $number) { |
| 25 | + id |
| 26 | + } |
| 27 | + } |
| 28 | +}' --jq '.data.repository.issue.id') |
| 29 | + |
| 30 | +# Check if the query was successful |
| 31 | +if [ $? -ne 0 ]; then |
| 32 | + echo -e "${RED}Issue #$issue_number not found in $org/$repo${NC}" |
| 33 | + exit 1 |
| 34 | +fi |
| 35 | + |
| 36 | +# Get the sub-issues for the issue |
| 37 | +sub_issue_summary=$(gh api graphql -H GraphQL-Features:sub_issues -f issueId="$issue_id" -f query=' |
| 38 | +query($issueId: ID!) { |
| 39 | + node(id: $issueId) { |
| 40 | + ... on Issue { |
| 41 | + subIssuesSummary { |
| 42 | + total |
| 43 | + completed |
| 44 | + percentCompleted |
| 45 | + } |
| 46 | + } |
| 47 | + } |
| 48 | +}') |
| 49 | + |
| 50 | +# Check if the gh api graphql command was successful |
| 51 | +if [ $? -ne 0 ]; then |
| 52 | + echo -e "${RED}Failed to get sub-issue summary for $org/$repo#$issue_number.${NC}" |
| 53 | + exit 1 |
| 54 | +fi |
| 55 | + |
| 56 | +# Extract and format the sub-issue summary details using jq |
| 57 | +formatted_sub_issue_summary=$(echo "$sub_issue_summary" | jq -r ' |
| 58 | + .data.node.subIssuesSummary | { |
| 59 | + total: .total, |
| 60 | + completed: .completed, |
| 61 | + percentCompleted: .percentCompleted |
| 62 | + }') |
| 63 | + |
| 64 | +# Print the formatted sub-issue summary details |
| 65 | +echo "$formatted_sub_issue_summary" | jq . |
| 66 | + |
| 67 | +# Check if total is 0 and print a warning |
| 68 | +total=$(echo "$formatted_sub_issue_summary" | jq -r '.total') |
| 69 | +if [ "$total" -eq 0 ]; then |
| 70 | + echo -e "${YELLOW}Warning: The total number of sub-issues for $org/$repo#$issue_number is 0.${NC}" |
| 71 | +fi |
0 commit comments