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/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-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 diff --git a/gh-cli/get-parent-issue-of-issue.sh b/gh-cli/get-parent-issue-of-issue.sh index f11a04f..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 @@ -41,6 +42,7 @@ query($issueId: ID!) { title number url + id issueType { name } @@ -61,8 +63,15 @@ 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 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 c7a9710..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 @@ -43,6 +44,7 @@ query($issueId: ID!, $endCursor: String) { title number url + id issueType { name } @@ -66,8 +68,14 @@ 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 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 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 }