Skip to content

Instantly share code, notes, and snippets.

@funkeyfreak
Last active December 15, 2021 00:54
Show Gist options
  • Save funkeyfreak/41b6494bf342af45c07154fa435f5be2 to your computer and use it in GitHub Desktop.
Save funkeyfreak/41b6494bf342af45c07154fa435f5be2 to your computer and use it in GitHub Desktop.
Handy-Dandy Helpers for Working with GitHub Issues Accross Multiple Repositories

My Workflow For Working Across Multiple Repositories (In GitHub)

So, you work with many, many repositories in github, and you want to use github issues? Then you're in the right place! For the past seven years, I have been working to better streamline my workflow between milestone creation, issue creation, and projects - especally as I am now a senior engineer.

The process I am suggesting is this blog post is no-where near perfect. However, it is a good jumping-off point. If you have any suggestions on how to improve this process, please let me know!

Setting Things Up

First, we need to create our folder structures

#! /bin/zsh
# ------------------------------------------------------------------------------
# Copyright (c) 2021 Dalin Williams
# ------------------------------------------------------------------------------
# Description: Creates an issue in all repositories specified in a text file.
createIssues() {
0="$HOME/workdir/github/HBOCodeLabs";
BASH_ARGV0=$0;
local title;
local body;
local project;
local milestone;
local labels;
local assignee;
local teamRepositories;
help() {
echo "";
echo -e "\033[1mUSAGE\033[0m"
echo " $ createIssues <flags> <optional flags>";
echo "";
echo -e "\033[1mFLAGS\033[0m";
echo " -t The title of the issue.";
echo " -b The body of the issue.";
echo "";
echo -e "\033[1mOPTIONAL FLAGS\033[0m";
echo " -a The GitHub username to assign to the issue";
echo " -m The milestone to assign the issue to.";
echo "";
echo -e "\033[1mOPTIONAL FLAGS WITH DEFAULTS\033[0m";
echo " -p The a comma-seperated set of projects in which to create the issue in. Defaults to 'Data and Operational Excellence - DOX'.";
echo " -l The a comma-seperated set of labels to assign to the issue. Automatically appends the label 'dox'.";
echo " -t The text file containing the team repositories - one repository on each newline. Defailts to .tools/direct-commerce-services.txt.";
echo "";
echo -e "\033[1mEXAMPLES\033[0m";
echo " $ createIssues -t \"Test Issue\" -b \"This is a test issue.\" -p \"Test\" -m \"Test Milestone\" -l \"Test Label\" -a \"Dalin Williams\" -t teamRepositories.txt";
echo " $ createIssues -t \"Test Issue\" -b \"This is a test issue.\"";
}
while getopts ":h:t:b:p:m:l:a:r:" opt; do
case $opt in
t) title="$OPTARG"
;;
b) body="$OPTARG"
;;
p) project="$OPTARG"
;;
m) milestone="$OPTARG"
;;
l) labels="$OPTARG"
;;
a) assignee="$OPTARG"
;;
r) teamRepositories="$OPTARG"
;;
h)
help
return 0
;;
\?)
echo "Invalid option -$OPTARG" >&2
help
return 0
;;
esac
case $OPTARG in
-*) echo "Option $opt needs a valid argument"
return 1
;;
esac
done
if [ -z "$title" ] || [ -z "$body" ]; then
echo "Missing required arguments."
help
return 1
fi
title=${title:-"An issue created against {}"}
body=${body:-"This issue was created against {} by the script createAnIssue.sh"}
project=${project:-"Data and Operational Excellence - DOX"}
labels=${labels:-"dox"}
assignee=${assignee:-"@me"}
teamRepositories=${teamRepositories:-"/Users/dawilliams/workdir/github/HBOCodeLabs/.tools/direct-commerce-services.txt"}
# if string does not contain 'dox' lable, then add 'dox' label
if [[ ! "$labels" == *"dox"* ]]; then
lables="$labels,dox"
fi
find * -maxdepth 0 -type d \( ! -name . \) -exec bash -c "grep {} $teamRepositories &&
if [ $? -eq 0 ]; then
echo 'Creating issue $title in {}'
cd {} &&
gh issue create --title '$title' --body '$body' --label '$labels' --project '$project' --assignee '$assignee' ${milestone:+--milestone '$milestone'}
fi
" \;
}
# Description: Creates a milestone in all repositories specified in a text file.
createMilestones() {
0="$HOME/workdir/github/HBOCodeLabs";
BASH_ARGV0=$0;
local title;
local description;
local dueDate;
local teamRepositories;
help() {
echo "";
echo -e "\033[1mUSAGE\033[0m"
echo " $ createMilestones <flags> <optional flags>";
echo "";
echo -e "\033[1mFLAGS\033[0m";
echo " -t The title of the milestone.";
echo " -d The description of the milestone.";
echo " -D The due date of the milestone.";
echo "";
echo -e "\033[1mOPTIONAL FLAGS\033[0m";
echo " -t The text file containing the team repositories - one repository on each newline. Defailts to .tools/direct-commerce-services.txt.";
echo "";
echo -e "\033[1mEXAMPLES\033[0m";
echo " $ createMilestones -t \"Test Milestone\" -d \"This is a test milestone.\" -D \"2020-01-01\" -t teamRepositories.txt";
echo " $ createMilestones -t \"Test Milestone\" -d \"This is a test milestone.\" -D \"2020-01-01\"";
}
while getopts ":h:t:d:D:r:" opt; do
case $opt in
t) title="$OPTARG"
;;
d) description="$OPTARG"
;;
D) dueDate="$OPTARG"
;;
r) teamRepositories="$OPTARG"
;;
h)
help
return 1
;;
\?)
echo "Invalid option -$OPTARG" >&2
help
return 1
;;
esac
case $OPTARG in
-*) echo "Option $opt needs a valid argument"
return 1
;;
esac
done
if [ -z "$title" ] || [ -z "$description" ]; then
echo "Missing required arguments."
help
return 1
fi
teamRepositories=${teamRepositories:-"/Users/dawilliams/workdir/github/HBOCodeLabs/.tools/direct-commerce-services.txt"}
find * -maxdepth 0 -type d \( ! -name . \) -exec bash -c "grep {} $teamRepositories &&
if [ $? -eq 0 ]; then
echo 'Creating milestone $title in {}'
cd {} &&
echo '{
\"title\": \"$title\",
\"state\": \"open\",
\"due_on\": \"$dueDate\",
\"description\": \"$description\"
}' | gh createMilestone
fi
" \;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment