Skip to content

Commit 2fbd8d7

Browse files
jdsutherlandnywilken
authored andcommitted
Rename 'solution metadata' to 'exercise metadata' (#736)
* Rename solution.json related refs to metadata.json * Rename Metadata to ExerciseMetadata for clarity
1 parent 2c1e6c8 commit 2fbd8d7

21 files changed

Lines changed: 104 additions & 104 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ The exercism CLI follows [semantic versioning](http://semver.org/).
55
----------------
66

77
## Next Release
8-
* **Your contribution here**
8+
* [#736](https://github.com/exercism/cli/pull/736) Metadata file .solution.json renamed to metadata.json - [@jdsutherland]
99

1010
## v3.0.9 (2018-08-29)
1111
* [#720](https://github.com/exercism/cli/pull/720) Make the timeout configurable globally - [@kytrinyx]

cmd/download.go

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ func runDownload(cfg config.Config, flags *pflag.FlagSet, args []string) error {
132132
}
133133
}
134134

135-
solution := workspace.Solution{
135+
metadata := workspace.ExerciseMetadata{
136136
AutoApprove: payload.Solution.Exercise.AutoApprove,
137137
Track: payload.Solution.Exercise.Track.ID,
138138
Team: payload.Solution.Team.Slug,
@@ -144,17 +144,17 @@ func runDownload(cfg config.Config, flags *pflag.FlagSet, args []string) error {
144144
}
145145

146146
root := usrCfg.GetString("workspace")
147-
if solution.Team != "" {
148-
root = filepath.Join(root, "teams", solution.Team)
147+
if metadata.Team != "" {
148+
root = filepath.Join(root, "teams", metadata.Team)
149149
}
150-
if !solution.IsRequester {
151-
root = filepath.Join(root, "users", solution.Handle)
150+
if !metadata.IsRequester {
151+
root = filepath.Join(root, "users", metadata.Handle)
152152
}
153153

154154
exercise := workspace.Exercise{
155155
Root: root,
156-
Track: solution.Track,
157-
Slug: solution.Exercise,
156+
Track: metadata.Track,
157+
Slug: metadata.Exercise,
158158
}
159159

160160
dir := exercise.MetadataDir()
@@ -163,7 +163,7 @@ func runDownload(cfg config.Config, flags *pflag.FlagSet, args []string) error {
163163
return err
164164
}
165165

166-
err = solution.Write(dir)
166+
err = metadata.Write(dir)
167167
if err != nil {
168168
return err
169169
}
@@ -204,7 +204,7 @@ func runDownload(cfg config.Config, flags *pflag.FlagSet, args []string) error {
204204
// Work around a path bug due to an early design decision (later reversed) to
205205
// allow numeric suffixes for exercise directories, allowing people to have
206206
// multiple parallel versions of an exercise.
207-
pattern := fmt.Sprintf(`\A.*[/\\]%s-\d*/`, solution.Exercise)
207+
pattern := fmt.Sprintf(`\A.*[/\\]%s-\d*/`, metadata.Exercise)
208208
rgxNumericSuffix := regexp.MustCompile(pattern)
209209
if rgxNumericSuffix.MatchString(file) {
210210
file = string(rgxNumericSuffix.ReplaceAll([]byte(file), []byte("")))
@@ -214,10 +214,10 @@ func runDownload(cfg config.Config, flags *pflag.FlagSet, args []string) error {
214214
file = strings.Replace(file, "\\", "/", -1)
215215

216216
relativePath := filepath.FromSlash(file)
217-
dir := filepath.Join(solution.Dir, filepath.Dir(relativePath))
217+
dir := filepath.Join(metadata.Dir, filepath.Dir(relativePath))
218218
os.MkdirAll(dir, os.FileMode(0755))
219219

220-
f, err := os.Create(filepath.Join(solution.Dir, relativePath))
220+
f, err := os.Create(filepath.Join(metadata.Dir, relativePath))
221221
if err != nil {
222222
return err
223223
}
@@ -228,7 +228,7 @@ func runDownload(cfg config.Config, flags *pflag.FlagSet, args []string) error {
228228
}
229229
}
230230
fmt.Fprintf(Err, "\nDownloaded to\n")
231-
fmt.Fprintf(Out, "%s\n", solution.Dir)
231+
fmt.Fprintf(Out, "%s\n", metadata.Dir)
232232
return nil
233233
}
234234

cmd/download_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -144,13 +144,13 @@ func TestDownload(t *testing.T) {
144144

145145
dir := filepath.Join(targetDir, "bogus-track", "bogus-exercise")
146146
b, err := ioutil.ReadFile(workspace.NewExerciseFromDir(dir).MetadataFilepath())
147-
var s workspace.Solution
148-
err = json.Unmarshal(b, &s)
147+
var metadata workspace.ExerciseMetadata
148+
err = json.Unmarshal(b, &metadata)
149149
assert.NoError(t, err)
150150

151-
assert.Equal(t, "bogus-track", s.Track)
152-
assert.Equal(t, "bogus-exercise", s.Exercise)
153-
assert.Equal(t, tc.requester, s.IsRequester)
151+
assert.Equal(t, "bogus-track", metadata.Track)
152+
assert.Equal(t, "bogus-exercise", metadata.Exercise)
153+
assert.Equal(t, tc.requester, metadata.IsRequester)
154154
}
155155
}
156156

cmd/open.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,11 @@ Pass the path to the directory that contains the solution you want to see on the
1717
`,
1818
Args: cobra.ExactArgs(1),
1919
RunE: func(cmd *cobra.Command, args []string) error {
20-
solution, err := workspace.NewSolution(args[0])
20+
metadata, err := workspace.NewExerciseMetadata(args[0])
2121
if err != nil {
2222
return err
2323
}
24-
browser.Open(solution.URL)
24+
browser.Open(metadata.URL)
2525
return nil
2626
},
2727
}

cmd/submit.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ func runSubmit(cfg config.Config, flags *pflag.FlagSet, args []string) error {
109109

110110
var exerciseDir string
111111
for _, arg := range args {
112-
dir, err := ws.SolutionDir(arg)
112+
dir, err := ws.ExerciseDir(arg)
113113
if err != nil {
114114
if workspace.IsMissingMetadata(err) {
115115
return errors.New(msgMissingMetadata)
@@ -136,12 +136,12 @@ func runSubmit(cfg config.Config, flags *pflag.FlagSet, args []string) error {
136136
if verbose, _ := flags.GetBool("verbose"); verbose {
137137
fmt.Fprintf(os.Stderr, migrationStatus.String())
138138
}
139-
solution, err := workspace.NewSolution(exerciseDir)
139+
metadata, err := workspace.NewExerciseMetadata(exerciseDir)
140140
if err != nil {
141141
return err
142142
}
143143

144-
if !solution.IsRequester {
144+
if !metadata.IsRequester {
145145
// TODO: add test
146146
msg := `
147147
@@ -151,7 +151,7 @@ func runSubmit(cfg config.Config, flags *pflag.FlagSet, args []string) error {
151151
%s download --exercise=%s --track=%s
152152
153153
`
154-
return fmt.Errorf(msg, BinaryName, solution.Exercise, solution.Track)
154+
return fmt.Errorf(msg, BinaryName, metadata.Exercise, metadata.Track)
155155
}
156156

157157
exercise.Documents = make([]workspace.Document, 0, len(args))
@@ -226,7 +226,7 @@ func runSubmit(cfg config.Config, flags *pflag.FlagSet, args []string) error {
226226
if err != nil {
227227
return err
228228
}
229-
url := fmt.Sprintf("%s/solutions/%s", usrCfg.GetString("apibaseurl"), solution.ID)
229+
url := fmt.Sprintf("%s/solutions/%s", usrCfg.GetString("apibaseurl"), metadata.ID)
230230
req, err := client.NewRequest("PATCH", url, body)
231231
if err != nil {
232232
return err
@@ -251,11 +251,11 @@ func runSubmit(cfg config.Config, flags *pflag.FlagSet, args []string) error {
251251
%s
252252
`
253253
suffix := "View it at:\n\n "
254-
if solution.AutoApprove {
254+
if metadata.AutoApprove {
255255
suffix = "You can complete the exercise and unlock the next core exercise at:\n"
256256
}
257257
fmt.Fprintf(Err, msg, suffix)
258-
fmt.Fprintf(Out, " %s\n\n", solution.URL)
258+
fmt.Fprintf(Out, " %s\n\n", metadata.URL)
259259
return nil
260260
}
261261

cmd/submit_symlink_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ func TestSubmitFilesInSymlinkedPath(t *testing.T) {
4444
dir := filepath.Join(dstDir, "bogus-track", "bogus-exercise")
4545
os.MkdirAll(dir, os.FileMode(0755))
4646

47-
writeFakeSolution(t, dir, "bogus-track", "bogus-exercise")
47+
writeFakeMetadata(t, dir, "bogus-track", "bogus-exercise")
4848

4949
v := viper.New()
5050
v.Set("token", "abc123")

cmd/submit_test.go

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ func TestSubmitNonExistentFile(t *testing.T) {
7070
assert.Regexp(t, "cannot be found", err.Error())
7171
}
7272

73-
func TestSubmitExerciseWithoutSolutionMetadataFile(t *testing.T) {
73+
func TestSubmitExerciseWithoutMetadataFile(t *testing.T) {
7474
tmpDir, err := ioutil.TempDir("", "no-metadata-file")
7575
defer os.RemoveAll(tmpDir)
7676
assert.NoError(t, err)
@@ -147,7 +147,7 @@ func TestSubmitFiles(t *testing.T) {
147147

148148
dir := filepath.Join(tmpDir, "bogus-track", "bogus-exercise")
149149
os.MkdirAll(filepath.Join(dir, "subdir"), os.FileMode(0755))
150-
writeFakeSolution(t, dir, "bogus-track", "bogus-exercise")
150+
writeFakeMetadata(t, dir, "bogus-track", "bogus-exercise")
151151

152152
file1 := filepath.Join(dir, "file-1.txt")
153153
err = ioutil.WriteFile(file1, []byte("This is file 1."), os.FileMode(0755))
@@ -186,7 +186,7 @@ func TestSubmitFiles(t *testing.T) {
186186
assert.Equal(t, "This is the readme.", submittedFiles["README.md"])
187187
}
188188

189-
func TestLegacySolutionMetadataMigration(t *testing.T) {
189+
func TestLegacyMetadataMigration(t *testing.T) {
190190
oldOut := Out
191191
oldErr := Err
192192
Out = ioutil.Discard
@@ -207,14 +207,14 @@ func TestLegacySolutionMetadataMigration(t *testing.T) {
207207
dir := filepath.Join(tmpDir, "bogus-track", "bogus-exercise")
208208
os.MkdirAll(dir, os.FileMode(0755))
209209

210-
solution := &workspace.Solution{
210+
metadata := &workspace.ExerciseMetadata{
211211
ID: "bogus-solution-uuid",
212212
Track: "bogus-track",
213213
Exercise: "bogus-exercise",
214214
URL: "http://example.com/bogus-url",
215215
IsRequester: true,
216216
}
217-
b, err := json.Marshal(solution)
217+
b, err := json.Marshal(metadata)
218218
assert.NoError(t, err)
219219
exercise := workspace.NewExerciseFromDir(dir)
220220
err = ioutil.WriteFile(exercise.LegacyMetadataFilepath(), b, os.FileMode(0600))
@@ -271,7 +271,7 @@ func TestSubmitWithEmptyFile(t *testing.T) {
271271
dir := filepath.Join(tmpDir, "bogus-track", "bogus-exercise")
272272
os.MkdirAll(dir, os.FileMode(0755))
273273

274-
writeFakeSolution(t, dir, "bogus-track", "bogus-exercise")
274+
writeFakeMetadata(t, dir, "bogus-track", "bogus-exercise")
275275

276276
v := viper.New()
277277
v.Set("token", "abc123")
@@ -317,7 +317,7 @@ func TestSubmitWithEnormousFile(t *testing.T) {
317317
dir := filepath.Join(tmpDir, "bogus-track", "bogus-exercise")
318318
os.MkdirAll(dir, os.FileMode(0755))
319319

320-
writeFakeSolution(t, dir, "bogus-track", "bogus-exercise")
320+
writeFakeMetadata(t, dir, "bogus-track", "bogus-exercise")
321321

322322
v := viper.New()
323323
v.Set("token", "abc123")
@@ -360,7 +360,7 @@ func TestSubmitFilesForTeamExercise(t *testing.T) {
360360

361361
dir := filepath.Join(tmpDir, "teams", "bogus-team", "bogus-track", "bogus-exercise")
362362
os.MkdirAll(filepath.Join(dir, "subdir"), os.FileMode(0755))
363-
writeFakeSolution(t, dir, "bogus-track", "bogus-exercise")
363+
writeFakeMetadata(t, dir, "bogus-track", "bogus-exercise")
364364

365365
file1 := filepath.Join(dir, "file-1.txt")
366366
err = ioutil.WriteFile(file1, []byte("This is file 1."), os.FileMode(0755))
@@ -409,7 +409,7 @@ func TestSubmitOnlyEmptyFile(t *testing.T) {
409409
dir := filepath.Join(tmpDir, "bogus-track", "bogus-exercise")
410410
os.MkdirAll(dir, os.FileMode(0755))
411411

412-
writeFakeSolution(t, dir, "bogus-track", "bogus-exercise")
412+
writeFakeMetadata(t, dir, "bogus-track", "bogus-exercise")
413413

414414
v := viper.New()
415415
v.Set("token", "abc123")
@@ -435,11 +435,11 @@ func TestSubmitFilesFromDifferentSolutions(t *testing.T) {
435435

436436
dir1 := filepath.Join(tmpDir, "bogus-track", "bogus-exercise-1")
437437
os.MkdirAll(dir1, os.FileMode(0755))
438-
writeFakeSolution(t, dir1, "bogus-track", "bogus-exercise-1")
438+
writeFakeMetadata(t, dir1, "bogus-track", "bogus-exercise-1")
439439

440440
dir2 := filepath.Join(tmpDir, "bogus-track", "bogus-exercise-2")
441441
os.MkdirAll(dir2, os.FileMode(0755))
442-
writeFakeSolution(t, dir2, "bogus-track", "bogus-exercise-2")
442+
writeFakeMetadata(t, dir2, "bogus-track", "bogus-exercise-2")
443443

444444
file1 := filepath.Join(dir1, "file-1.txt")
445445
err = ioutil.WriteFile(file1, []byte("This is file 1."), os.FileMode(0755))
@@ -510,7 +510,7 @@ func TestSubmitRelativePath(t *testing.T) {
510510
dir := filepath.Join(tmpDir, "bogus-track", "bogus-exercise")
511511
os.MkdirAll(dir, os.FileMode(0755))
512512

513-
writeFakeSolution(t, dir, "bogus-track", "bogus-exercise")
513+
writeFakeMetadata(t, dir, "bogus-track", "bogus-exercise")
514514

515515
v := viper.New()
516516
v.Set("token", "abc123")
@@ -534,14 +534,14 @@ func TestSubmitRelativePath(t *testing.T) {
534534
assert.Equal(t, "This is a file.", submittedFiles["file.txt"])
535535
}
536536

537-
func writeFakeSolution(t *testing.T, dir, trackID, exerciseSlug string) {
538-
solution := &workspace.Solution{
537+
func writeFakeMetadata(t *testing.T, dir, trackID, exerciseSlug string) {
538+
metadata := &workspace.ExerciseMetadata{
539539
ID: "bogus-solution-uuid",
540540
Track: trackID,
541541
Exercise: exerciseSlug,
542542
URL: "http://example.com/bogus-url",
543543
IsRequester: true,
544544
}
545-
err := solution.Write(dir)
545+
err := metadata.Write(dir)
546546
assert.NoError(t, err)
547547
}

fixtures/is-solution-path/broken/.exercism/solution.json renamed to fixtures/is-solution-path/broken/.exercism/metadata.json

File renamed without changes.

fixtures/is-solution-path/yepp/.exercism/solution.json renamed to fixtures/is-solution-path/yepp/.exercism/metadata.json

File renamed without changes.

fixtures/solution-dir/workspace/exercise/.exercism/solution.json renamed to fixtures/solution-dir/workspace/exercise/.exercism/metadata.json

File renamed without changes.

0 commit comments

Comments
 (0)