Skip to content

Commit 78c2d3c

Browse files
lemoncurryFridaTveit
authored andcommitted
Create script to check for unimplemented exercises and submit issue (exercism#1733)
* [WIP] Create script to check for unimplemented exercises * implement new exercise add issue submission * add description for script in CONTRIBUTING.md * improve wording
1 parent f96bed4 commit 78c2d3c

2 files changed

Lines changed: 182 additions & 3 deletions

File tree

CONTRIBUTING.md

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ To run this script:
200200

201201
There is [a script which allows you to submit new issues](https://github.com/exercism/java/blob/master/scripts/create_issues_versionchange_canonical.sh) to this repo with generic title, description and labels if a change in version was detected.
202202

203-
Example generic new isse:
203+
Example generic new issue:
204204
<img width="1005" alt="image" src="https://user-images.githubusercontent.com/6614867/57221803-bf1a6600-7000-11e9-93cf-b930ef24ce97.png">
205205

206206
Before you may submit a new issue, the script
@@ -216,11 +216,37 @@ To run this script:
216216

217217
3. In this file, you have to put the following variables:
218218
- `TOKEN="your_token"`
219-
- `OWNER="repo_owner"` # -> `"exercism"`
220-
- `REPO="repo_name"` # -> `"java"`
219+
- `OWNER="exercism"`
220+
- `REPO="java"`
221221

222222
For authentication, you need to create a personal token, see [this GitHub page](https://help.github.com/en/articles/creating-a-personal-access-token-for-the-command-line) for more information.
223223

224224
4. Run `./scripts/create_issues_versionchange_canonical.sh -t . -s --spec-path path_to_problem_specifications` from the root of this repository and follow the directions.
225225

226226
5. If you submitted new issues, please check these submissions on the [issues page](https://github.com/exercism/java/issues).
227+
228+
## Checking exercises are implemented and submit new issues
229+
230+
There is [a script](https://github.com/exercism/java/blob/master/scripts/create_issues_new_exercise.sh) which allows you to easily check if there are any exercism exercises which haven't been implemented in the Java track, and create issues for those exercises if there are any.
231+
232+
Before you may submit a new issue, the script
233+
1. Checks whether the exercise exists in the Java track (compared to exercism/problem-specifications)
234+
2. Checks whether an open issue exists for this exercise concerning the implementation of the exercise;
235+
3. If a new issue may be opened for an exercise, the script will ask you if you want to submit the issue. Entering `y` will create the new issue.
236+
237+
To run this script:
238+
239+
1. Clone [the problem-specifications repository](https://github.com/exercism/problem-specifications).
240+
241+
2. Create a file `.exercism-version-update-issue-script-settings.sh` in your home directory.
242+
243+
3. In this file, you have to put the following variables:
244+
- `TOKEN="your_token"`
245+
- `OWNER="exercism"`
246+
- `REPO="java"`
247+
248+
For authentication, you need to create a personal token, see [this GitHub page](https://help.github.com/en/articles/creating-a-personal-access-token-for-the-command-line) for more information.
249+
250+
4. Run `./scripts/create_issues_new_exercise.sh -t . -s --spec-path path_to_problem_specifications` from the root of this repository and follow the directions.
251+
252+
5. If you decide to submit a new issue you can find the opened issue on the [issues page](https://github.com/exercism/java/issues).
Lines changed: 153 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,153 @@
1+
#!/bin/bash
2+
3+
print_usage() {
4+
echo ">>>>> Usage: scripts/create_issues_new_exercise.sh -t path/to/track -s path/to/problem/specifications"
5+
}
6+
7+
command -v jq >/dev/null 2>&1 || {
8+
echo >&2 ">>>>> This script requires jq but it's not installed. Aborting."
9+
exit 1
10+
}
11+
12+
num_args=$#
13+
14+
if [[ $num_args = 0 ]]; then
15+
print_usage
16+
exit 0
17+
fi
18+
19+
path_to_track=
20+
path_to_problem_specifications=
21+
22+
while getopts ":t:s:" option; do
23+
case "$option" in
24+
"t")
25+
path_to_track="$OPTARG"
26+
;;
27+
"s")
28+
path_to_problem_specifications="$OPTARG"
29+
;;
30+
*)
31+
echo ">>>>> Unrecognized option. Aborting."
32+
print_usage
33+
exit 1
34+
;;
35+
esac
36+
done
37+
38+
if [[ -z "$path_to_track" ]]; then
39+
echo ">>>>> Path to track missing."
40+
print_usage
41+
exit 1
42+
fi
43+
44+
if [[ -z "$path_to_problem_specifications" ]]; then
45+
echo ">>>>> Path to problem specifications missing."
46+
print_usage
47+
exit 1
48+
fi
49+
50+
config_file_path="$path_to_track/config.json"
51+
52+
if ! [[ -f "$config_file_path" ]]; then
53+
echo ">>>>> Config file not found at ${config_file_path}."
54+
exit 1
55+
fi
56+
57+
problem_spec_exercises=
58+
exercise_name=
59+
track_exercise_slugs=$(jq '.exercises[] | select(has("deprecated") | not) | .slug' "$config_file_path" | tr -d "\"" | sort)
60+
track_foregone_exercises=$(jq '.foregone[]' "$config_file_path" | tr -d "\"")
61+
track_deprecated_exercises=$(jq '.exercises[] | select(has("deprecated")) | .slug' "$config_file_path" | tr -d "\"")
62+
63+
for path_to_exercise in ${path_to_problem_specifications}/exercises/*; do
64+
if [[ -d "$path_to_exercise" ]]; then
65+
if [[ -f "$path_to_exercise"/.deprecated ]]; then
66+
continue
67+
fi
68+
exercise_name=$(echo "$path_to_exercise" | sed "s/.*\///")
69+
problem_spec_exercises="$problem_spec_exercises $exercise_name"
70+
fi
71+
done
72+
73+
# Create a file named ".exercism-version-update-issue-script-settings.sh"
74+
# with the following variables and put in in your home directory
75+
#
76+
# TOKEN="your_token"
77+
# OWNER="your_username"
78+
# REPO="repo_name"
79+
80+
if ! [[ -f "$HOME/.exercism-version-update-issue-script-settings.sh" ]]; then
81+
echo "Create a file named \".exercism-version-update-issue-script-settings.sh\""
82+
echo "with the following variables and put in in your home directory"
83+
echo "TOKEN=\"your_token\""
84+
echo "OWNER=\"repo_owner\""
85+
echo "REPO=\"repo_name\""
86+
fi
87+
88+
. "$HOME/.exercism-version-update-issue-script-settings.sh"
89+
90+
if [[ -z "$TOKEN" ]]; then
91+
echo "Please insert your personal token into \".exercism-version-update-issue-script-settings.sh\"."
92+
exit 1
93+
elif [[ -z "$OWNER" ]]; then
94+
echo "Please insert the repo owner into \".exercism-version-update-issue-script-settings.sh\"."
95+
exit 1
96+
elif [[ -z "$REPO" ]]; then
97+
echo "Please insert the name of the repo into \".exercism-version-update-issue-script-settings.sh\"."
98+
exit 1
99+
fi
100+
101+
102+
# Fetch issues opened by us to avoid duplicate issues
103+
open_issues=$(curl --silent -HAuthorization:token\ ${TOKEN} https://api.github.com/repos/${OWNER}/${REPO}/issues\?state=open\&labels=implement+exercise | jq -r '.[] |(.title | split(":")[0]) + " Issue Title: " + .title + " (" + (.comments|tostring) +" comments)" + ", URL: " + .html_url')
104+
105+
count=0
106+
for exercise in $problem_spec_exercises; do
107+
if echo "$track_exercise_slugs" | grep -q "$exercise" ; then
108+
continue
109+
elif echo "$track_deprecated_exercises" | grep -q "$exercise"; then
110+
continue
111+
elif echo "$track_foregone_exercises" | grep -q "$exercise"; then
112+
continue
113+
fi
114+
(( count+=1 ))
115+
if echo "$open_issues" | grep --quiet "^$exercise "; then
116+
echo ">>>>> $exercise: implement exercise"
117+
echo "The following issue(s) are currently open for exercise $exercise in ${REPO} with label <implement exercise>:"
118+
echo "$open_issues" | grep "^$exercise " | cut -d' ' -f2-
119+
echo "Please check manually if a new issue may be opened."
120+
read -p "Press enter to continue."
121+
echo
122+
continue
123+
else
124+
printf ">>>>> Exercise $exercise is not yet implemented in the Java track.\n"
125+
title="$exercise: implement exercise"
126+
body="The exercise **$exercise** has not been implemented yet for the Java track. \nThe description of the exercise can be found in the [problem specification repository](https://github.com/exercism/problem-specifications/tree/master/exercises/$exercise). \n\nHow to implement a new exercise for the Java track is described in detail in [CONTRIBUTING.md](https://github.com/exercism/java/blob/master/CONTRIBUTING.md#adding-a-new-exercise). Please have a look there first before starting working on the exercise. \nAlso please make sure it is clear that you are currently working on this issue, either by asking to be assigned to it, or by opening an empty PR. \n\nWhen opening an PR, please reference this issue using any of the [closing keywords](https://help.github.com/en/articles/closing-issues-using-keywords). \n\nIf you have had a look at the exercise description and you concluded that the exercise might not be possible to implement in the Java language, please leave a comment and describe the problem. \n\nIn case you have any further questions, feel free to ask here. \n"
127+
labels='"help wanted", "implement exercise", "enhancement"'
128+
129+
response=""
130+
while [[ $response != "y" && $response != "n" ]]; do
131+
read -r -p "Do you want to publish this new issue for exercise $exercise with title: $title? [y/n] " response
132+
done
133+
echo
134+
if [[ $response == "y" ]]; then
135+
printf ">>>>> Generating new issue for exercise $exercise with title: ${title}\n"
136+
137+
curl --fail --silent -H 'Content-Type: application/json' -H 'Authorization: token '"$TOKEN"'' -X POST -d '{"title": "'"$title"'", "body": "'"$body"'", "labels": ['"$labels"']}' https://api.github.com/repos/${OWNER}/${REPO}/issues | jq -r '"New issue created at: " + .html_url'
138+
read -p "Press enter to continue."
139+
echo
140+
141+
if [[ "$?" != "0" ]]; then
142+
echo ">>>>> Issue submission failed. Exit 1"
143+
exit 1
144+
fi
145+
fi
146+
fi
147+
148+
done
149+
150+
echo "Total: $count exercises unimplemented."
151+
echo "All exercises checked."
152+
153+
exit 0

0 commit comments

Comments
 (0)