Skip to content

Commit 9bc39f0

Browse files
authored
Merge pull request #126 from kolkhis/update-issue-gen-script
feat: Add 'create all' functionality to issue gen script
2 parents d121f6d + 59e12c6 commit 9bc39f0

File tree

1 file changed

+86
-52
lines changed

1 file changed

+86
-52
lines changed

scripts/create-issues

Lines changed: 86 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -7,37 +7,66 @@ declare TYPE
77
declare FILE
88
declare EMOJI
99
declare PROJECT
10+
declare TEMPL_PATH
1011

11-
case $PWD in
12-
*lac*)
13-
PROJECT='lac'
14-
;;
15-
*psc*)
16-
PROJECT='pscpm'
17-
;;
18-
esac
12+
declare -a ALL_TYPES=('intro' 'worksheet' 'lab' 'bonus')
13+
14+
_set_type_vars() {
15+
# Pass in $TYPE
16+
case $1 in
17+
ws|worksheet)
18+
TYPE='worksheet'
19+
FILE="u${UNIT}ws.md"
20+
EMOJI="📄"
21+
LABEL="Worksheet ${EMOJI}"
22+
;;
23+
l|lab)
24+
TYPE='lab'
25+
FILE="u${UNIT}lab.md"
26+
EMOJI="🧪"
27+
LABEL="Lab ${EMOJI}"
28+
;;
29+
i|intro)
30+
TYPE='intro'
31+
FILE="u${UNIT}intro.md"
32+
EMOJI="👋"
33+
LABEL="Intro"
34+
;;
35+
b|bonus)
36+
TYPE='bonus'
37+
FILE="u${UNIT}b.md"
38+
EMOJI="🍒"
39+
LABEL="Bonus ${EMOJI}"
40+
;;
41+
esac
42+
}
1943

2044

2145
while [[ -n $1 ]]; do
2246
case $1 in
2347
-u|--unit)
24-
[[ -n $2 ]] && UNIT=$2 || printf "Bad argument to -u/--unit.\n"
25-
shift; shift;
48+
[[ -n $2 ]] && UNIT=$2 && shift || printf "Bad argument to -u/--unit.\n"
49+
shift;
2650
;;
2751
-t|--type)
28-
[[ -n $2 ]] && TYPE=$2 || printf "No argument to -t/--type.\n"
29-
shift; shift;
52+
[[ -n $2 ]] && TYPE=$2 && shift || printf "No argument to -t/--type.\n"
53+
shift;
54+
;;
55+
-a|--all)
56+
TYPE="all"
57+
shift;
3058
;;
3159
-h|--help)
3260
cat <<- EOF
3361
NAME: create-issues
3462
USAGE:
35-
create-issues [-t|--type TYPE] [-u|--unit UNIT_NUMBER]
63+
create-issues [-t|--type TYPE] [-u|--unit UNIT_NUMBER] [-a|--all]
3664
3765
OPTIONS:
3866
-u | --unit UNIT_NUMBER Specify the unit number for the issue
3967
-t | --type TYPE Specify the type of document for the issue
40-
This can be one of 'worksheet', 'lab', 'intro', 'bonus'
68+
This can be one of 'worksheet', 'lab', 'intro', 'bonus'. Set to 'all' to create an issue of each type.
69+
-a | --all Shorthand for '--type all'
4170
4271
SYNOPSIS:
4372
Creates an issue for the upstream repo. The 'gh' tool must be configured beforehand.
@@ -48,47 +77,52 @@ while [[ -n $1 ]]; do
4877
esac
4978
done
5079

51-
{ [[ -z $UNIT ]] && read -r -p "Enter unit number: " UNIT; }
52-
{ [[ -z $TYPE ]] && read -r -p "Enter type (ws/lab/intro/bonus): " TYPE; }
80+
[[ -z $UNIT ]] && read -r -p "Enter unit number: " UNIT;
81+
[[ -z $TYPE ]] && read -r -p "Enter type (ws/lab/intro/bonus/all): " TYPE;
82+
[[ -z $TYPE || -z $UNIT ]] && printf "Missing Type or Unit!\n" && exit 1
83+
[[ "${PWD##*/}" == scripts ]] &&
84+
TEMPL_PATH="../.github/ISSUE_TEMPLATE" ||
85+
TEMPL_PATH=".github/ISSUE_TEMPLATE"
5386

54-
[[ -z $TYPE || -z $UNIT ]] && printf "Missing Type or Unit!\n"
55-
56-
case $TYPE in
57-
ws|worksheet)
58-
TYPE='worksheet'
59-
FILE="u${UNIT}ws.md"
60-
EMOJI="📄"
61-
LABEL="Worksheet ${EMOJI}"
62-
;;
63-
l|lab)
64-
TYPE='lab'
65-
FILE="u${UNIT}lab.md"
66-
EMOJI="🧪"
67-
LABEL="Lab ${EMOJI}"
68-
;;
69-
i|intro)
70-
TYPE='intro'
71-
FILE="u${UNIT}intro.md"
72-
EMOJI="👋"
73-
LABEL="Intro"
87+
case $PWD in
88+
*lac*)
89+
PROJECT='lac'
7490
;;
75-
b|bonus)
76-
TYPE='bonus'
77-
FILE="u${UNIT}b.md"
78-
EMOJI="🍒"
79-
LABEL="Bonus ${EMOJI}"
91+
*psc*)
92+
PROJECT='pscpm'
8093
;;
8194
esac
8295

83-
gh issue create \
84-
--title "Unit ${UNIT} ${TYPE^} ${EMOJI} (${FILE})" \
85-
--label "${LABEL}" \
86-
--label "Unit #${UNIT}" \
87-
--label "help wanted" \
88-
--label "enhancement" \
89-
--label "good first issue" \
90-
--body "$(cat ../.github/ISSUE_TEMPLATE/unit-"${TYPE,,}"-body.md)" || {
91-
printf >&2 "Failed to create the issue!\n" && exit 1
92-
}
93-
# --project "pscpm" \ # doesn't work
96+
97+
if [[ "${TYPE,,}" == "all" ]]; then
98+
for t in "${ALL_TYPES[@]}"; do
99+
_set_type_vars "$t"
100+
gh issue create \
101+
--title "Unit ${UNIT} ${t^} ${EMOJI} (${FILE})" \
102+
--label "${LABEL}" \
103+
--label "Unit #${UNIT}" \
104+
--label "help wanted" \
105+
--label "enhancement" \
106+
--body-file "$TEMPL_PATH/unit-${t,,}-body.md" || {
107+
printf >&2 "Failed to create the issue!\n" && exit 1
108+
}
109+
done
110+
printf "Successfully created all issues for unit %s.\n" "$UNIT"
111+
exit 0
112+
else
113+
_set_type_vars "$TYPE"
114+
gh issue create \
115+
--title "Unit ${UNIT} ${TYPE^} ${EMOJI} (${FILE})" \
116+
--label "${LABEL}" \
117+
--label "Unit #${UNIT}" \
118+
--label "help wanted" \
119+
--label "enhancement" \
120+
--body-file "$TEMPL_PATH/unit-${TYPE,,}-body.md" || {
121+
printf >&2 "Failed to create the issue!\n" && exit 1
122+
}
123+
printf "Successfully created %s issue for unit %s.\n" "$TYPE" "$UNIT"
124+
exit 0
125+
fi
126+
127+
# --project "$PROJECT" \ # doesn't work
94128

0 commit comments

Comments
 (0)