From 5f744fb30e87e989ad3061dff8b5a379ce4f2a33 Mon Sep 17 00:00:00 2001 From: Josh Johanning Date: Fri, 15 Nov 2024 12:05:11 -0600 Subject: [PATCH 1/3] feat: including issue id in the response --- gh-cli/add-sub-issue-to-issue.sh | 2 ++ gh-cli/get-parent-issue-of-issue.sh | 4 +++- gh-cli/get-sub-issues-of-issue.sh | 3 ++- gh-cli/remove-issue-issue-type.sh | 1 + gh-cli/remove-sub-issue-from-issue.sh | 2 ++ gh-cli/update-issue-issue-type.sh | 1 + 6 files changed, 11 insertions(+), 2 deletions(-) diff --git a/gh-cli/add-sub-issue-to-issue.sh b/gh-cli/add-sub-issue-to-issue.sh index 77821de..abaae65 100755 --- a/gh-cli/add-sub-issue-to-issue.sh +++ b/gh-cli/add-sub-issue-to-issue.sh @@ -55,6 +55,7 @@ mutation($parrentIssueId: ID!, $childIssueId: ID!) { title number url + id issueType { name } @@ -63,6 +64,7 @@ mutation($parrentIssueId: ID!, $childIssueId: ID!) { title number url + id issueType { name } diff --git a/gh-cli/get-parent-issue-of-issue.sh b/gh-cli/get-parent-issue-of-issue.sh index f11a04f..05ce6fe 100755 --- a/gh-cli/get-parent-issue-of-issue.sh +++ b/gh-cli/get-parent-issue-of-issue.sh @@ -41,6 +41,7 @@ query($issueId: ID!) { title number url + id issueType { name } @@ -61,7 +62,8 @@ formatted_parent_issue=$(echo "$parent_issue" | jq -r ' title: .title, number: .number, url: .url, - issueType: .issueType + id: .id, + issueType: .issueType.name }') # Print the formatted parent issue details diff --git a/gh-cli/get-sub-issues-of-issue.sh b/gh-cli/get-sub-issues-of-issue.sh index c7a9710..13f274a 100755 --- a/gh-cli/get-sub-issues-of-issue.sh +++ b/gh-cli/get-sub-issues-of-issue.sh @@ -43,6 +43,7 @@ query($issueId: ID!, $endCursor: String) { title number url + id issueType { name } @@ -66,7 +67,7 @@ fi combined_result=$(echo "$sub_issues" | jq -s ' { totalCount: .[0].data.node.subIssues.totalCount, - issues: (map(.data.node.subIssues.nodes) | add) + issues: (map(.data.node.subIssues.nodes) | add | map(.issueType = .issueType.name)) }') # Print the combined result as a colorized JSON object diff --git a/gh-cli/remove-issue-issue-type.sh b/gh-cli/remove-issue-issue-type.sh index 09e0325..fe2d1d4 100755 --- a/gh-cli/remove-issue-issue-type.sh +++ b/gh-cli/remove-issue-issue-type.sh @@ -52,6 +52,7 @@ mutation($issueId: ID!) { title number url + id issueType { name } diff --git a/gh-cli/remove-sub-issue-from-issue.sh b/gh-cli/remove-sub-issue-from-issue.sh index ee2b6d1..fb65931 100755 --- a/gh-cli/remove-sub-issue-from-issue.sh +++ b/gh-cli/remove-sub-issue-from-issue.sh @@ -77,6 +77,7 @@ mutation($parrentIssueId: ID!, $childIssueId: ID!) { title number url + id issueType { name } @@ -85,6 +86,7 @@ mutation($parrentIssueId: ID!, $childIssueId: ID!) { title number url + id issueType { name } diff --git a/gh-cli/update-issue-issue-type.sh b/gh-cli/update-issue-issue-type.sh index c808cbd..7510d13 100755 --- a/gh-cli/update-issue-issue-type.sh +++ b/gh-cli/update-issue-issue-type.sh @@ -60,6 +60,7 @@ mutation($issueId: ID!, $issueTypeId: ID!) { title number url + id issueType { name } From 8281e69e95314468f6995e8052b48579866270d1 Mon Sep 17 00:00:00 2001 From: Josh Johanning Date: Fri, 15 Nov 2024 12:14:44 -0600 Subject: [PATCH 2/3] feat: add a script to get issue type of an issue --- gh-cli/README.md | 4 +++ gh-cli/get-issue-type-of-issue.sh | 59 +++++++++++++++++++++++++++++++ 2 files changed, 63 insertions(+) create mode 100755 gh-cli/get-issue-type-of-issue.sh diff --git a/gh-cli/README.md b/gh-cli/README.md index 34a000c..2374637 100644 --- a/gh-cli/README.md +++ b/gh-cli/README.md @@ -673,6 +673,10 @@ Gets info about an enterprise using the [EnterpriseOwnerInfo](https://docs.githu Gets the status of a [GitHub Enterprise Importer (GEI) migration](https://docs.github.com/en/enterprise-cloud@latest/migrations/using-github-enterprise-importer/migrating-organizations-with-github-enterprise-importer/migrating-organizations-from-githubcom-to-github-enterprise-cloud?tool=api#step-3-check-the-status-of-your-migration). +### get-issue-type-of-issue.sh + +Gets the issue type of an issue. See: [Community Discussions Post](https://github.com/orgs/community/discussions/139933) + ### get-label-usage-in-repository.sh Gets the usage of a label in a repository. Returns data in table format. diff --git a/gh-cli/get-issue-type-of-issue.sh b/gh-cli/get-issue-type-of-issue.sh new file mode 100755 index 0000000..30dc787 --- /dev/null +++ b/gh-cli/get-issue-type-of-issue.sh @@ -0,0 +1,59 @@ +#!/bin/bash + +# Gets the issue type of an issue + +if [ -z "$3" ]; then + echo "Usage: $0 " + echo "Example: ./get-issue-type-of-issue.sh joshjohanning-org migrating-ado-to-gh-issues-v2 5" + exit 1 +fi + +org="$1" +repo="$2" +issue_number="$3" + +# Define color codes +RED='\033[0;31m' +YELLOW='\033[0;33m' +NC='\033[0m' # No Color + +# Fetch the issue ID given the issue number +issue=$(gh api graphql -H GraphQL-Features:issue_types -f owner="$org" -f repository="$repo" -F number="$issue_number" -f query=' +query ($owner: String!, $repository: String!, $number: Int!) { + repository(owner: $owner, name: $repository) { + issue(number: $number) { + title + number + url + id + issueType { + name + } + } + } +}') + +# Check if the query was successful +if [ $? -ne 0 ]; then + echo -e "${RED}Issue #$issue_number not found in $org/$repo${NC}" + exit 1 +fi + +# Extract and format the issue details using jq +formatted_issue=$(echo "$issue" | jq -r ' + .data.repository.issue | { + title: .title, + number: .number, + url: .url, + id: .id, + issueType: .issueType.name + }') + +# Print the formatted issue details +echo "$formatted_issue" | jq . + +# Check if issue type is null and print a warning +issue_type=$(echo "$formatted_issue" | jq -r '.issueType') +if [ "$issue_type" = "null" ]; then + echo -e "${YELLOW}Warning: No issue type for $org/$repo#$issue_number.${NC}" +fi From 49092a6e364549ebce3a90ce5251c0a027e63af1 Mon Sep 17 00:00:00 2001 From: Josh Johanning Date: Fri, 15 Nov 2024 12:15:44 -0600 Subject: [PATCH 3/3] feat: add warning if there are no sub-issues/parents found --- gh-cli/get-parent-issue-of-issue.sh | 7 +++++++ gh-cli/get-sub-issues-of-issue.sh | 7 +++++++ 2 files changed, 14 insertions(+) diff --git a/gh-cli/get-parent-issue-of-issue.sh b/gh-cli/get-parent-issue-of-issue.sh index 05ce6fe..11dffb6 100755 --- a/gh-cli/get-parent-issue-of-issue.sh +++ b/gh-cli/get-parent-issue-of-issue.sh @@ -14,6 +14,7 @@ issue_number="$3" # Define color codes RED='\033[0;31m' +YELLOW='\033[0;33m' NC='\033[0m' # No Color # Fetch the issue ID given the issue number @@ -68,3 +69,9 @@ formatted_parent_issue=$(echo "$parent_issue" | jq -r ' # Print the formatted parent issue details echo "$formatted_parent_issue" | jq . + +# Check if parent issue is null and print a warning +number=$(echo "$formatted_parent_issue" | jq -r '.number') +if [ "$number" = "null" ]; then + echo -e "${YELLOW}Warning: No parent issue for $org/$repo#$issue_number.${NC}" +fi diff --git a/gh-cli/get-sub-issues-of-issue.sh b/gh-cli/get-sub-issues-of-issue.sh index 13f274a..acef923 100755 --- a/gh-cli/get-sub-issues-of-issue.sh +++ b/gh-cli/get-sub-issues-of-issue.sh @@ -14,6 +14,7 @@ issue_number="$3" # Define color codes RED='\033[0;31m' +YELLOW='\033[0;33m' NC='\033[0m' # No Color # Fetch the issue ID given the issue number @@ -72,3 +73,9 @@ combined_result=$(echo "$sub_issues" | jq -s ' # Print the combined result as a colorized JSON object echo "$combined_result" | jq . + +# Check if total is 0 and print a warning +total=$(echo "$combined_result" | jq -r '.totalCount') +if [ "$total" -eq 0 ]; then + echo -e "${YELLOW}Warning: The total number of sub-issues for $org/$repo#$issue_number is 0.${NC}" +fi