|
| 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