Skip to content

Commit c62eccc

Browse files
lemoncurryFridaTveit
authored andcommitted
Create script for issue submission (canonical data version changes) (exercism#1674)
* Create script for issue submission (canonical data version changes) Script using GitHub API to create new issue when difference between track exercise version file number and canonical data version number is detected. * Add error messages for token, owner, repo file; fix usage * issue submission script: add info * issue submission remove sentence * fix wording * remove comment
1 parent 5e7e513 commit c62eccc

2 files changed

Lines changed: 195 additions & 0 deletions

File tree

CONTRIBUTING.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
* [Adding a New Exercise](#adding-a-new-exercise)
1212
* [Updating the READMEs](#updating-the-readmes)
1313
* [Checking tests are up to date](#checking-tests-are-up-to-date)
14+
* [Checking tests are up to date and submit new issues](#checking-tests-are-up-to-date-and-submit-new-issues)
1415

1516
## Overview
1617

@@ -192,3 +193,32 @@ To run this script:
192193
1. Clone [the problem-specifications repository](https://github.com/exercism/problem-specifications).
193194

194195
2. Run `./scripts/canonical_data_check.sh -t . -s --spec-path path_to_problem_specifications` from the root of this repository.
196+
197+
## Checking tests are up to date and submit new issues
198+
199+
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.
200+
201+
Example generic new isse:
202+
<img width="1005" alt="image" src="https://user-images.githubusercontent.com/6614867/57221803-bf1a6600-7000-11e9-93cf-b930ef24ce97.png">
203+
204+
Before you may submit a new issue, the script
205+
1. Checks for differences between version numbers of each exercise (in comparison with the version number of the canonical data)
206+
2. Checks whether an open issue exists for this exercise; if there is an open issue, you will have to check by yourself if the title of the open issue might be changed to include the new version number. Here, it is important to check whether someone is already working on the issue.
207+
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.
208+
209+
To run this script:
210+
211+
1. Clone [the problem-specifications repository](https://github.com/exercism/problem-specifications).
212+
213+
2. Create a file `.exercism-version-update-issue-script-settings.sh` in your home directory.
214+
215+
3. In this file, you have to put the following variables:
216+
- `TOKEN="your_token"`
217+
- `OWNER="repo_owner"` # -> `"exercism"`
218+
- `REPO="repo_name"` # -> `"java"`
219+
220+
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.
221+
222+
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.
223+
224+
5. If you submitted new issues, please check these submissions on the [issues page](https://github.com/exercism/java/issues).
Lines changed: 165 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,165 @@
1+
#!/bin/bash
2+
3+
print_usage() {
4+
echo ">>>>> Usage: ./create_issues_versionchange_canonical.sh -t path/to/track -s path/to/problem/specifications"
5+
}
6+
7+
# Execution begins
8+
9+
command -v jq >/dev/null 2>&1 || {
10+
echo >&2 ">>>>> This script requires jq but it's not installed. Aborting."
11+
exit 1
12+
}
13+
14+
num_args=$#
15+
16+
if [[ $num_args = 0 ]]; then
17+
print_usage
18+
exit 0
19+
fi
20+
21+
path_to_track=
22+
path_to_problem_specifications=
23+
24+
while getopts ":t:s:" option; do
25+
case "$option" in
26+
"t")
27+
path_to_track="$OPTARG"
28+
;;
29+
"s")
30+
path_to_problem_specifications="$OPTARG"
31+
;;
32+
*)
33+
echo ">>>>> Unrecognized option. Aborting."
34+
print_usage
35+
exit 1
36+
;;
37+
esac
38+
done
39+
40+
if [[ -z "$path_to_track" ]]; then
41+
echo ">>>>> Path to track missing."
42+
print_usage
43+
exit 1
44+
fi
45+
46+
if [[ -z "$path_to_problem_specifications" ]]; then
47+
echo ">>>>> Path to problem specifications missing."
48+
print_usage
49+
exit 1
50+
fi
51+
52+
config_file_path="$path_to_track/config.json"
53+
54+
if ! [[ -f "$config_file_path" ]]; then
55+
echo ">>>>> Config file not found at ${config_file_path}."
56+
exit 1
57+
fi
58+
59+
track_exercise_slugs=$(jq '.exercises[] | select(has("deprecated") | not) | .slug' "$config_file_path" | tr -d "\"" | sort)
60+
update_needed_count=0
61+
62+
63+
# Create a file named ".exercism-version-update-issue-script-settings.sh"
64+
# with the following variables and put in in your home directory
65+
#
66+
# TOKEN="your_token"
67+
# OWNER="your_username"
68+
# REPO="repo_name"
69+
70+
if ! [[ -f "$HOME/.exercism-version-update-issue-script-settings.sh" ]]; then
71+
echo "Create a file named \".exercism-version-update-issue-script-settings.sh\""
72+
echo "with the following variables and put in in your home directory"
73+
echo "TOKEN=\"your_token\""
74+
echo "OWNER=\"repo_owner\""
75+
echo "REPO=\"repo_name\""
76+
fi
77+
78+
. "$HOME/.exercism-version-update-issue-script-settings.sh"
79+
80+
if [[ -z "$TOKEN" ]]; then
81+
echo "Please insert your personal token into \".exercism-version-update-issue-script-settings.sh\"."
82+
exit 1
83+
elif [[ -z "$OWNER" ]]; then
84+
echo "Please insert the repo owner into \".exercism-version-update-issue-script-settings.sh\"."
85+
exit 1
86+
elif [[ -z "$REPO" ]]; then
87+
echo "Please insert the name of the repo into \".exercism-version-update-issue-script-settings.sh\"."
88+
exit 1
89+
fi
90+
91+
92+
# Fetch issues opened by us to avoid duplicate issues
93+
OPEN_ISSUES=$(curl --silent -HAuthorization:token\ ${TOKEN} https://api.github.com/repos/${OWNER}/${REPO}/issues\?state=open\&labels=exercise+version+update | jq -r '.[] |(.title | split(":")[0]) + " Issue Title: " + .title + " (" + (.comments|tostring) +" comments)" + ", URL: " + .html_url')
94+
95+
# Check each exercise for possible difference in version and check for submission of new issue
96+
for slug in $track_exercise_slugs; do
97+
canonical_data_folder_path="${path_to_problem_specifications}/exercises/${slug}"
98+
99+
if ! [[ -d "$canonical_data_folder_path" ]]; then
100+
echo ">>>>> Canonical data folder ${canonical_data_folder_path} not found. Aborting."
101+
exit 1
102+
fi
103+
104+
canonical_data_file_path="${canonical_data_folder_path}/canonical-data.json"
105+
106+
if ! [[ -f "$canonical_data_file_path" ]]; then
107+
continue
108+
fi
109+
110+
canonical_data_version=$(jq '.version' ${canonical_data_file_path} | tr -d "\"")
111+
112+
track_exercise_version_file_path="${path_to_track}/exercises/${slug}/.meta/version"
113+
114+
if ! [[ -f "$track_exercise_version_file_path" ]]; then
115+
echo ">>>>> ${slug}: needs update or version file (v${canonical_data_version})."
116+
update_needed_count=$((update_needed_count + 1))
117+
read -p "Press enter to continue."
118+
echo
119+
continue
120+
fi
121+
122+
track_data_version=$(cat "$track_exercise_version_file_path" | sed 's/\r$//')
123+
124+
if [[ "$track_data_version" = "$canonical_data_version" ]]; then
125+
continue
126+
elif echo "$OPEN_ISSUES" | grep --quiet "^$slug "; then
127+
echo ">>>>> ${slug}: update tests and version file (v${track_data_version} -> v${canonical_data_version})"
128+
echo "The following issue(s) are currently open for exercise ${slug} in ${REPO}:"
129+
echo "$OPEN_ISSUES" | grep "^$slug " | cut -d' ' -f2-
130+
echo "Please check manually if the title of one of this/these issue(s) might be changed to >> ${slug}: update tests and version file (v${track_data_version} -> v${canonical_data_version}) <<"
131+
read -p "Press enter to continue."
132+
echo
133+
continue
134+
else
135+
update_needed_count=$((update_needed_count + 1))
136+
printf ">>>>> Exercise ${slug} needs an update from v${track_data_version} -> v${canonical_data_version}\n"
137+
title="${slug}: update tests and version file (v${track_data_version} -> v${canonical_data_version})"
138+
body="The tests for the [${slug} exercise](https://github.com/exercism/java/tree/master/exercises/${slug}/src/test/java) are not up-to-date with the [canonical data](https://github.com/exercism/problem-specifications/tree/master/exercises/${slug}/canonical-data.json).\nTo check what has changed and if new tests have been added to the canonical data, please have a look at the [commit history](https://github.com/exercism/problem-specifications/commits/master/exercises/${slug}/canonical-data.json) of the canonical data file for the exercise ${slug}.\nPlease update version and/or test file, and, if the new test(s) fail, fix the reference implementation.\nFeel free to leave a comment if you have any questions. \n\nBackground info: each exercise which has canonical data should have a version file. This file states which version of the canonical data the exercise implements. The version can be found at the top of the [canonical data file](https://github.com/exercism/problem-specifications/tree/master/exercises/${slug}/canonical-data.json) for that exercise."
139+
labels='"good first issue", "help wanted", "exercise version update"'
140+
141+
response=""
142+
while [[ $response != "y" && $response != "n" ]]; do
143+
read -r -p "Do you want to publish this new issue for exercise $slug with title: $title? [y/n] " response
144+
done
145+
echo
146+
if [[ $response == "y" ]]; then
147+
printf ">>>>> Generating new issue for exercise ${slug} with title: ${title}\n"
148+
149+
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'
150+
read -p "Press enter to continue."
151+
echo
152+
153+
if [[ "$?" != "0" ]]; then
154+
echo ">>>>> Issue submission failed. Exit 1"
155+
exit 1
156+
fi
157+
fi
158+
fi
159+
done
160+
161+
if [[ "$update_needed_count" = 0 ]]; then
162+
echo "All exercises are up to date!"
163+
fi
164+
165+
echo "All exercises have been checked. Exit"

0 commit comments

Comments
 (0)