|
#! /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 |
|
" \; |
|
} |