diff --git a/gh-cli/README.md b/gh-cli/README.md index 4baa7fa..34a000c 100644 --- a/gh-cli/README.md +++ b/gh-cli/README.md @@ -912,6 +912,10 @@ Retrieve the download URL for a specific version of a package in GitHub Packages > [!NOTE] > No longer works for GitHub.com and deprecated for GHES 3.7+. See [Changelog post](https://github.blog/changelog/2022-08-18-deprecation-notice-graphql-for-packages/), [GraphQL breaking changes](https://docs.github.com/en/graphql/overview/breaking-changes#changes-scheduled-for-2022-11-21-1), and [GHES 3.7 deprecations](https://docs.github.com/en/enterprise-server@3.7/admin/release-notes#3.7.0-deprecations) +### get-parent-issue-of-issue.sh + +Gets the parent issue of a given sub-issue (child). See: [Community Discussions Post](https://github.com/orgs/community/discussions/139932) + ### get-projects-added-to-repository.sh Gets ProjectsV2 added to a repository @@ -1088,6 +1092,14 @@ Retrieves all SSO enabled PATs users have created for an organization. Retrieves all SSO-enabled SSH keys users have created for an organization. +### get-sub-issue-summary-of-issue.sh + +Gets a summary of the sub-issues (children) of an issue (parent). See: [Community Discussions Post](https://github.com/orgs/community/discussions/139932) + +### get-sub-issues-of-issue.sh + +Gets the sub-issues (children) of an issue (parent). See: [Community Discussions Post](https://github.com/orgs/community/discussions/139932) + ### get-user-id.sh Retrieves the ID of a user for other GraphQL calls diff --git a/gh-cli/add-sub-issue-to-issue.sh b/gh-cli/add-sub-issue-to-issue.sh index e400794..77821de 100755 --- a/gh-cli/add-sub-issue-to-issue.sh +++ b/gh-cli/add-sub-issue-to-issue.sh @@ -47,7 +47,7 @@ parent_issue_id=$(fetch_issue_id "$org" "$repo" "$parent_issue_number") # Fetch the child issue ID given the issue number child_issue_id=$(fetch_issue_id "$org" "$repo" "$child_issue_number") -# Set the issue type on the issue +# Add the sub-issue to the parent issue gh api graphql -H GraphQL-Features:issue_types -H GraphQL-Features:sub_issues -f parrentIssueId="$parent_issue_id" -f childIssueId="$child_issue_id" -f query=' mutation($parrentIssueId: ID!, $childIssueId: ID!) { addSubIssue(input: { issueId: $parrentIssueId, subIssueId: $childIssueId }) { diff --git a/gh-cli/get-parent-issue-of-issue.sh b/gh-cli/get-parent-issue-of-issue.sh new file mode 100755 index 0000000..f11a04f --- /dev/null +++ b/gh-cli/get-parent-issue-of-issue.sh @@ -0,0 +1,68 @@ +#!/bin/bash + +# Gets the parent issue of an issue + +if [ -z "$3" ]; then + echo "Usage: $0 " + echo "Example: ./get-parent-issue-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' +NC='\033[0m' # No Color + +# Fetch the issue ID given the issue number +issue_id=$(gh api graphql -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) { + id + } + } +}' --jq '.data.repository.issue.id') + +# 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 + +# Get the parent issue for the issue +parent_issue=$(gh api graphql -H GraphQL-Features:sub_issues -H GraphQL-Features:issue_types -f issueId="$issue_id" -f query=' +query($issueId: ID!) { + node(id: $issueId) { + ... on Issue { + parent { + title + number + url + issueType { + name + } + } + } + } +}') + +# Check if the gh api graphql command was successful +if [ $? -ne 0 ]; then + echo -e "${RED}Failed to get the parent issue for $org/$repo#$issue_number.${NC}" + exit 1 +fi + +# Extract and format the parent issue details using jq +formatted_parent_issue=$(echo "$parent_issue" | jq -r ' + .data.node.parent | { + title: .title, + number: .number, + url: .url, + issueType: .issueType + }') + +# Print the formatted parent issue details +echo "$formatted_parent_issue" | jq . diff --git a/gh-cli/get-sub-issue-summary-of-issue.sh b/gh-cli/get-sub-issue-summary-of-issue.sh new file mode 100755 index 0000000..56edd93 --- /dev/null +++ b/gh-cli/get-sub-issue-summary-of-issue.sh @@ -0,0 +1,71 @@ +#!/bin/bash + +# Gets the sub-issue summary of an issue + +if [ -z "$3" ]; then + echo "Usage: $0 " + echo "Example: ./get-sub-issues-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_id=$(gh api graphql -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) { + id + } + } +}' --jq '.data.repository.issue.id') + +# 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 + +# Get the sub-issues for the issue +sub_issue_summary=$(gh api graphql -H GraphQL-Features:sub_issues -f issueId="$issue_id" -f query=' +query($issueId: ID!) { + node(id: $issueId) { + ... on Issue { + subIssuesSummary { + total + completed + percentCompleted + } + } + } +}') + +# Check if the gh api graphql command was successful +if [ $? -ne 0 ]; then + echo -e "${RED}Failed to get sub-issue summary for $org/$repo#$issue_number.${NC}" + exit 1 +fi + +# Extract and format the sub-issue summary details using jq +formatted_sub_issue_summary=$(echo "$sub_issue_summary" | jq -r ' + .data.node.subIssuesSummary | { + total: .total, + completed: .completed, + percentCompleted: .percentCompleted + }') + +# Print the formatted sub-issue summary details +echo "$formatted_sub_issue_summary" | jq . + +# Check if total is 0 and print a warning +total=$(echo "$formatted_sub_issue_summary" | jq -r '.total') +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/get-sub-issues-of-issue.sh b/gh-cli/get-sub-issues-of-issue.sh new file mode 100755 index 0000000..c7a9710 --- /dev/null +++ b/gh-cli/get-sub-issues-of-issue.sh @@ -0,0 +1,73 @@ +#!/bin/bash + +# Gets a list of sub-issues from an issue + +if [ -z "$3" ]; then + echo "Usage: $0 " + echo "Example: ./get-sub-issues-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' +NC='\033[0m' # No Color + +# Fetch the issue ID given the issue number +issue_id=$(gh api graphql -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) { + id + } + } +}' --jq '.data.repository.issue.id') + +# 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 + +# Get the sub-issues for the issue +sub_issues=$(gh api graphql --paginate -H GraphQL-Features:sub_issues -H GraphQL-Features:issue_types -f issueId="$issue_id" -f query=' +query($issueId: ID!, $endCursor: String) { + node(id: $issueId) { + ... on Issue { + subIssues(first: 100, after: $endCursor) { + totalCount + nodes { + title + number + url + issueType { + name + } + } + pageInfo { + hasNextPage + endCursor + } + } + } + } +}') + +# Check if the gh api graphql command was successful +if [ $? -ne 0 ]; then + echo -e "${RED}Failed to get sub-issues for $org/$repo#$issue_number.${NC}" + exit 1 +fi + +# Combine the results using jq +combined_result=$(echo "$sub_issues" | jq -s ' + { + totalCount: .[0].data.node.subIssues.totalCount, + issues: (map(.data.node.subIssues.nodes) | add) + }') + +# Print the combined result as a colorized JSON object +echo "$combined_result" | jq . diff --git a/gh-cli/remove-sub-issue-from-issue.sh b/gh-cli/remove-sub-issue-from-issue.sh index e7d8450..ee2b6d1 100755 --- a/gh-cli/remove-sub-issue-from-issue.sh +++ b/gh-cli/remove-sub-issue-from-issue.sh @@ -69,7 +69,7 @@ else exit 1 fi -# Set the issue type on the issue +# Remove the sub-issue from the parent issue gh api graphql -H GraphQL-Features:issue_types -H GraphQL-Features:sub_issues -f parrentIssueId="$parent_issue_id" -f childIssueId="$child_issue_id" -f query=' mutation($parrentIssueId: ID!, $childIssueId: ID!) { removeSubIssue(input: { issueId: $parrentIssueId, subIssueId: $childIssueId }) {