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
16 changes: 16 additions & 0 deletions gh-cli/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,10 @@ Use the [get-enterprise-id.sh](./get-enterprise-id.sh) or [get-organization-id.s

See the [docs](https://docs.github.com/en/graphql/reference/mutations#createipallowlistentry) for further information.

### add-sub-issue-to-issue.sh

Adds a sub-issue (child) to an issue (parent). See: [Community Discussions Post](https://github.com/orgs/community/discussions/139932)

### add-team-to-repositories-from-list.sh

This script adds a specified team to a list of repositories with specified permissions.
Expand Down Expand Up @@ -1164,6 +1168,14 @@ Removes an enterprise user. See notes:
1. List org members and get the id from there: `./get-organization-members.sh`
2. Get user id: `./get-user-id.sh`

### remove-issue-issue-type.sh

Remove the issue type from an issue (set it to `null`). See: [Community Discussions Post](https://github.com/orgs/community/discussions/139933)

### remove-sub-issue-from-issue.sh

Removes a sub-issue (child) from an issue (parent). See: [Community Discussions Post](https://github.com/orgs/community/discussions/139932)

### remove-users-from-organization.sh

Removes a list of users from the organization.
Expand Down Expand Up @@ -1265,6 +1277,10 @@ Updates a branch protection rule for a given branch.

Adds your account to an organization in an enterprise as an owner, member, or leave the organization. This requires the user running the script to be an Enterprise Owner.

### update-issue-issue-type.sh

Updates / sets the issue type for an issue. See: [Community Discussions Post](https://github.com/orgs/community/discussions/139933)

### verify-team-membership.sh

Simple script to verify that a user is a member of a team
79 changes: 79 additions & 0 deletions gh-cli/add-sub-issue-to-issue.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
#!/bin/bash

# Adds a sub-issue (child) to an issue (parent)

if [ -z "$4" ]; then
echo "Usage: $0 <org> <repo> <parent-issue-number> <child-issue-number>"
echo "Example: ./add-sub-issue-to-issue.sh joshjohanning-org migrating-ado-to-gh-issues-v2 5 6"
exit 1
fi

org="$1"
repo="$2"
parent_issue_number="$3"
child_issue_number="$4"

# Define color codes
RED='\033[0;31m'
NC='\033[0m' # No Color

# Function to fetch the issue ID given the issue number
fetch_issue_id() {
local org=$1
local repo=$2
local issue_number=$3

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 ] || [ -z "$issue_id" ]; then
echo -e "${RED}Issue #$issue_number not found in repository '$repo' of organization '$org'.${NC}"
exit 1
fi

echo "$issue_id"
}

# Fetch the parent issue ID given the issue number
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
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 }) {
issue {
title
number
url
issueType {
name
}
}
subIssue {
title
number
url
issueType {
name
}
}
}
}'

# Check if the mutation was successful
if [ $? -eq 0 ]; then
echo "Successfully added issue $org/$repo#$child_issue_number as a sub-issue to $org/$repo#$parent_issue_number."
else
echo -e "${RED}Failed to add issue $org/$repo#$child_issue_number as a sub-issue to $org/$repo#$parent_issue_number.${NC}"
exit 1
fi
68 changes: 68 additions & 0 deletions gh-cli/remove-issue-issue-type.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
#!/bin/bash

# Remove the issue type from an issue (set it to `null`)

if [ -z "$3" ]; then
echo "Usage: $0 <org> <repo> <issue-number>"
echo "Example: ./remove-issue-issue-type.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=$(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) {
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

issue_id=$(echo "$issue" | jq -r '.data.repository.issue.id')
issue_type=$(echo "$issue" | jq -r '.data.repository.issue.issueType.name')

# Check if the issue type is already null
if [ "$issue_type" == "null" ]; then
echo -e "${RED}The issue type is already null for issue #$issue_number in $org/$repo${NC}"
exit 1
fi

# Remove the issue type on the issue
gh api graphql -H GraphQL-Features:issue_types -f issueId="$issue_id" -f query='
mutation($issueId: ID!) {
updateIssueIssueType(input: {issueId: $issueId, issueTypeId: null}) {
issue {
title
number
url
issueType {
name
}
}
}
}'

# Check if the mutation was successful
if [ $? -eq 0 ]; then
echo "Issue type removed for issue #$issue_number."
else
echo -e "${RED}Failed to remove issue type for issue $org/$repo#$issue_number.${NC}"
exit 1
fi
101 changes: 101 additions & 0 deletions gh-cli/remove-sub-issue-from-issue.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
#!/bin/bash

# Removes a sub-issue (child) from an issue (parent)

if [ -z "$4" ]; then
echo "Usage: $0 <org> <repo> <parent-issue-number> <child-issue-number>"
echo "Example: ./remove-sub-issue-to-issue.sh joshjohanning-org migrating-ado-to-gh-issues-v2 5 bug"
exit 1
fi

org="$1"
repo="$2"
parent_issue_number="$3"
child_issue_number="$4"

# Define color codes
RED='\033[0;31m'
NC='\033[0m' # No Color

# Function to fetch the issue ID given the issue number
fetch_issue_id() {
local org=$1
local repo=$2
local issue_number=$3

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 ] || [ -z "$issue_id" ]; then
echo -e "${RED}Issue #$issue_number not found in repository '$repo' of organization '$org'.${NC}"
exit 1
fi

echo "$issue_id"
}

# Fetch the parent issue ID given the issue number
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")

child_issues=$(gh api graphql -H GraphQL-Features:sub_issues -F parrentIssueId="$parent_issue_id" -f query='
query ($parrentIssueId: ID!) {
node(id: $parrentIssueId) {
... on Issue {
subIssues(first: 10) {
nodes {
number
id
}
}
}
}
}')

# Check if the child issue number is in the list of child issues
if echo "$child_issues" | jq -e --argjson child_issue_number "$child_issue_number" '.data.node.subIssues.nodes[] | select(.number == $child_issue_number)' > /dev/null; then
echo "Child issue #$child_issue_number is a sub-issue of parent issue #$parent_issue_number."
else
echo -e "${RED}Child issue #$child_issue_number is not a sub-issue of parent issue #$parent_issue_number.${NC}"
exit 1
fi

# Set the issue type on the 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 }) {
issue {
title
number
url
issueType {
name
}
}
subIssue {
title
number
url
issueType {
name
}
}
}
}'

# Check if the mutation was successful
if [ $? -eq 0 ]; then
echo "Successfully removed issue $org/$repo#$child_issue_number as a sub-issue to $org/$repo#$parent_issue_number."
else
echo -e "${RED}Failed to remove issue $org/$repo#$child_issue_number as a sub-issue to $org/$repo#$parent_issue_number.${NC}"
exit 1
fi
76 changes: 76 additions & 0 deletions gh-cli/update-issue-issue-type.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
#!/bin/bash

# Updates / sets the issue type for an issue

if [ -z "$4" ]; then
echo "Usage: $0 <org> <repo> <issue-number> <type>"
echo "Example: ./update-issue-issue-type.sh joshjohanning-org migrating-ado-to-gh-issues-v2 5 'user story'"
exit 1
fi

org="$1"
repo="$2"
issue_number="$3"
type=$(echo "$4" | tr '[:upper:]' '[:lower:]')

# Define color codes
RED='\033[0;31m'
NC='\033[0m' # No Color

# Fetch issue types and filter to get the ID where name equals $type_upper
issue_type_id=$(gh api graphql -H GraphQL-Features:issue_types -f owner="$org" -f query='
query($owner: String!) {
organization(login: $owner) {
issueTypes(first: 100) {
nodes {
id
name
}
}
}
}' | jq -r --arg type "$type" '.data.organization.issueTypes.nodes[] | select(.name | ascii_downcase == $type) | .id')

# Check if issue type ID was found
if [ -z "$issue_type_id" ]; then
echo "Issue type '$type' not found in organization '$org'."
exit 1
fi

# 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

# Set the issue type on the issue
gh api graphql -H GraphQL-Features:issue_types -f issueId="$issue_id" -f issueTypeId="$issue_type_id" -f query='
mutation($issueId: ID!, $issueTypeId: ID!) {
updateIssueIssueType(input: {issueId: $issueId, issueTypeId: $issueTypeId}) {
issue {
title
number
url
issueType {
name
}
}
}
}'

# Check if the mutation was successful
if [ $? -eq 0 ]; then
echo "Issue type set to '$type' for issue #$issue_number."
else
echo -e "${RED}Failed to set issue type for issue $org/$repo#$issue_number.${NC}"
exit 1
fi