Skip to content

Commit 8281e69

Browse files
committed
feat: add a script to get issue type of an issue
1 parent 5f744fb commit 8281e69

File tree

2 files changed

+63
-0
lines changed

2 files changed

+63
-0
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/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

0 commit comments

Comments
 (0)