Skip to content

Commit 03facc3

Browse files
Merge pull request #91 from joshjohanning/add-get-issue-type
Add script to get issue type of an issue
2 parents 1562a57 + 49092a6 commit 03facc3

8 files changed

+88
-2
lines changed

gh-cli/README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -673,6 +673,10 @@ Gets info about an enterprise using the [EnterpriseOwnerInfo](https://docs.githu
673673

674674
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).
675675

676+
### get-issue-type-of-issue.sh
677+
678+
Gets the issue type of an issue. See: [Community Discussions Post](https://github.com/orgs/community/discussions/139933)
679+
676680
### get-label-usage-in-repository.sh
677681

678682
Gets the usage of a label in a repository. Returns data in table format.

gh-cli/add-sub-issue-to-issue.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ mutation($parrentIssueId: ID!, $childIssueId: ID!) {
5555
title
5656
number
5757
url
58+
id
5859
issueType {
5960
name
6061
}
@@ -63,6 +64,7 @@ mutation($parrentIssueId: ID!, $childIssueId: ID!) {
6364
title
6465
number
6566
url
67+
id
6668
issueType {
6769
name
6870
}

gh-cli/get-issue-type-of-issue.sh

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
#!/bin/bash
2+
3+
# Gets the issue type of an issue
4+
5+
if [ -z "$3" ]; then
6+
echo "Usage: $0 <org> <repo> <issue-number>"
7+
echo "Example: ./get-issue-type-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=$(gh api graphql -H GraphQL-Features:issue_types -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+
title
26+
number
27+
url
28+
id
29+
issueType {
30+
name
31+
}
32+
}
33+
}
34+
}')
35+
36+
# Check if the query was successful
37+
if [ $? -ne 0 ]; then
38+
echo -e "${RED}Issue #$issue_number not found in $org/$repo${NC}"
39+
exit 1
40+
fi
41+
42+
# Extract and format the issue details using jq
43+
formatted_issue=$(echo "$issue" | jq -r '
44+
.data.repository.issue | {
45+
title: .title,
46+
number: .number,
47+
url: .url,
48+
id: .id,
49+
issueType: .issueType.name
50+
}')
51+
52+
# Print the formatted issue details
53+
echo "$formatted_issue" | jq .
54+
55+
# Check if issue type is null and print a warning
56+
issue_type=$(echo "$formatted_issue" | jq -r '.issueType')
57+
if [ "$issue_type" = "null" ]; then
58+
echo -e "${YELLOW}Warning: No issue type for $org/$repo#$issue_number.${NC}"
59+
fi

gh-cli/get-parent-issue-of-issue.sh

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ issue_number="$3"
1414

1515
# Define color codes
1616
RED='\033[0;31m'
17+
YELLOW='\033[0;33m'
1718
NC='\033[0m' # No Color
1819

1920
# Fetch the issue ID given the issue number
@@ -41,6 +42,7 @@ query($issueId: ID!) {
4142
title
4243
number
4344
url
45+
id
4446
issueType {
4547
name
4648
}
@@ -61,8 +63,15 @@ formatted_parent_issue=$(echo "$parent_issue" | jq -r '
6163
title: .title,
6264
number: .number,
6365
url: .url,
64-
issueType: .issueType
66+
id: .id,
67+
issueType: .issueType.name
6568
}')
6669

6770
# Print the formatted parent issue details
6871
echo "$formatted_parent_issue" | jq .
72+
73+
# Check if parent issue is null and print a warning
74+
number=$(echo "$formatted_parent_issue" | jq -r '.number')
75+
if [ "$number" = "null" ]; then
76+
echo -e "${YELLOW}Warning: No parent issue for $org/$repo#$issue_number.${NC}"
77+
fi

gh-cli/get-sub-issues-of-issue.sh

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ issue_number="$3"
1414

1515
# Define color codes
1616
RED='\033[0;31m'
17+
YELLOW='\033[0;33m'
1718
NC='\033[0m' # No Color
1819

1920
# Fetch the issue ID given the issue number
@@ -43,6 +44,7 @@ query($issueId: ID!, $endCursor: String) {
4344
title
4445
number
4546
url
47+
id
4648
issueType {
4749
name
4850
}
@@ -66,8 +68,14 @@ fi
6668
combined_result=$(echo "$sub_issues" | jq -s '
6769
{
6870
totalCount: .[0].data.node.subIssues.totalCount,
69-
issues: (map(.data.node.subIssues.nodes) | add)
71+
issues: (map(.data.node.subIssues.nodes) | add | map(.issueType = .issueType.name))
7072
}')
7173

7274
# Print the combined result as a colorized JSON object
7375
echo "$combined_result" | jq .
76+
77+
# Check if total is 0 and print a warning
78+
total=$(echo "$combined_result" | jq -r '.totalCount')
79+
if [ "$total" -eq 0 ]; then
80+
echo -e "${YELLOW}Warning: The total number of sub-issues for $org/$repo#$issue_number is 0.${NC}"
81+
fi

gh-cli/remove-issue-issue-type.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ mutation($issueId: ID!) {
5252
title
5353
number
5454
url
55+
id
5556
issueType {
5657
name
5758
}

gh-cli/remove-sub-issue-from-issue.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ mutation($parrentIssueId: ID!, $childIssueId: ID!) {
7777
title
7878
number
7979
url
80+
id
8081
issueType {
8182
name
8283
}
@@ -85,6 +86,7 @@ mutation($parrentIssueId: ID!, $childIssueId: ID!) {
8586
title
8687
number
8788
url
89+
id
8890
issueType {
8991
name
9092
}

gh-cli/update-issue-issue-type.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ mutation($issueId: ID!, $issueTypeId: ID!) {
6060
title
6161
number
6262
url
63+
id
6364
issueType {
6465
name
6566
}

0 commit comments

Comments
 (0)