Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions gh-cli/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion gh-cli/add-sub-issue-to-issue.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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 }) {
Expand Down
68 changes: 68 additions & 0 deletions gh-cli/get-parent-issue-of-issue.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
#!/bin/bash

# Gets the parent issue of an issue

if [ -z "$3" ]; then
echo "Usage: $0 <org> <repo> <issue-number>"
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 .
71 changes: 71 additions & 0 deletions gh-cli/get-sub-issue-summary-of-issue.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
#!/bin/bash

# Gets the sub-issue summary of an issue

if [ -z "$3" ]; then
echo "Usage: $0 <org> <repo> <issue-number>"
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
73 changes: 73 additions & 0 deletions gh-cli/get-sub-issues-of-issue.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
#!/bin/bash

# Gets a list of sub-issues from an issue

if [ -z "$3" ]; then
echo "Usage: $0 <org> <repo> <issue-number>"
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 .
2 changes: 1 addition & 1 deletion gh-cli/remove-sub-issue-from-issue.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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 }) {
Expand Down