Skip to content

Commit

Permalink
Rename 'solution metadata' to 'exercise metadata' (#736)
Browse files Browse the repository at this point in the history
* Rename solution.json related refs to metadata.json
* Rename Metadata to ExerciseMetadata for clarity
  • Loading branch information
jdsutherland authored and nywilken committed Sep 22, 2018
1 parent 2c1e6c8 commit 2fbd8d7
Show file tree
Hide file tree
Showing 21 changed files with 104 additions and 104 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ The exercism CLI follows [semantic versioning](http://semver.org/).
----------------

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

## v3.0.9 (2018-08-29)
* [#720](https://github.com/exercism/cli/pull/720) Make the timeout configurable globally - [@kytrinyx]
Expand Down
24 changes: 12 additions & 12 deletions cmd/download.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ func runDownload(cfg config.Config, flags *pflag.FlagSet, args []string) error {
}
}

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

root := usrCfg.GetString("workspace")
if solution.Team != "" {
root = filepath.Join(root, "teams", solution.Team)
if metadata.Team != "" {
root = filepath.Join(root, "teams", metadata.Team)
}
if !solution.IsRequester {
root = filepath.Join(root, "users", solution.Handle)
if !metadata.IsRequester {
root = filepath.Join(root, "users", metadata.Handle)
}

exercise := workspace.Exercise{
Root: root,
Track: solution.Track,
Slug: solution.Exercise,
Track: metadata.Track,
Slug: metadata.Exercise,
}

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

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

relativePath := filepath.FromSlash(file)
dir := filepath.Join(solution.Dir, filepath.Dir(relativePath))
dir := filepath.Join(metadata.Dir, filepath.Dir(relativePath))
os.MkdirAll(dir, os.FileMode(0755))

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

Expand Down
10 changes: 5 additions & 5 deletions cmd/download_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,13 +144,13 @@ func TestDownload(t *testing.T) {

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

assert.Equal(t, "bogus-track", s.Track)
assert.Equal(t, "bogus-exercise", s.Exercise)
assert.Equal(t, tc.requester, s.IsRequester)
assert.Equal(t, "bogus-track", metadata.Track)
assert.Equal(t, "bogus-exercise", metadata.Exercise)
assert.Equal(t, tc.requester, metadata.IsRequester)
}
}

Expand Down
4 changes: 2 additions & 2 deletions cmd/open.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ Pass the path to the directory that contains the solution you want to see on the
`,
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
solution, err := workspace.NewSolution(args[0])
metadata, err := workspace.NewExerciseMetadata(args[0])
if err != nil {
return err
}
browser.Open(solution.URL)
browser.Open(metadata.URL)
return nil
},
}
Expand Down
14 changes: 7 additions & 7 deletions cmd/submit.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ func runSubmit(cfg config.Config, flags *pflag.FlagSet, args []string) error {

var exerciseDir string
for _, arg := range args {
dir, err := ws.SolutionDir(arg)
dir, err := ws.ExerciseDir(arg)
if err != nil {
if workspace.IsMissingMetadata(err) {
return errors.New(msgMissingMetadata)
Expand All @@ -136,12 +136,12 @@ func runSubmit(cfg config.Config, flags *pflag.FlagSet, args []string) error {
if verbose, _ := flags.GetBool("verbose"); verbose {
fmt.Fprintf(os.Stderr, migrationStatus.String())
}
solution, err := workspace.NewSolution(exerciseDir)
metadata, err := workspace.NewExerciseMetadata(exerciseDir)
if err != nil {
return err
}

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

exercise.Documents = make([]workspace.Document, 0, len(args))
Expand Down Expand Up @@ -226,7 +226,7 @@ func runSubmit(cfg config.Config, flags *pflag.FlagSet, args []string) error {
if err != nil {
return err
}
url := fmt.Sprintf("%s/solutions/%s", usrCfg.GetString("apibaseurl"), solution.ID)
url := fmt.Sprintf("%s/solutions/%s", usrCfg.GetString("apibaseurl"), metadata.ID)
req, err := client.NewRequest("PATCH", url, body)
if err != nil {
return err
Expand All @@ -251,11 +251,11 @@ func runSubmit(cfg config.Config, flags *pflag.FlagSet, args []string) error {
%s
`
suffix := "View it at:\n\n "
if solution.AutoApprove {
if metadata.AutoApprove {
suffix = "You can complete the exercise and unlock the next core exercise at:\n"
}
fmt.Fprintf(Err, msg, suffix)
fmt.Fprintf(Out, " %s\n\n", solution.URL)
fmt.Fprintf(Out, " %s\n\n", metadata.URL)
return nil
}

Expand Down
2 changes: 1 addition & 1 deletion cmd/submit_symlink_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func TestSubmitFilesInSymlinkedPath(t *testing.T) {
dir := filepath.Join(dstDir, "bogus-track", "bogus-exercise")
os.MkdirAll(dir, os.FileMode(0755))

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

v := viper.New()
v.Set("token", "abc123")
Expand Down
30 changes: 15 additions & 15 deletions cmd/submit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ func TestSubmitNonExistentFile(t *testing.T) {
assert.Regexp(t, "cannot be found", err.Error())
}

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

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

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

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

solution := &workspace.Solution{
metadata := &workspace.ExerciseMetadata{
ID: "bogus-solution-uuid",
Track: "bogus-track",
Exercise: "bogus-exercise",
URL: "http://example.com/bogus-url",
IsRequester: true,
}
b, err := json.Marshal(solution)
b, err := json.Marshal(metadata)
assert.NoError(t, err)
exercise := workspace.NewExerciseFromDir(dir)
err = ioutil.WriteFile(exercise.LegacyMetadataFilepath(), b, os.FileMode(0600))
Expand Down Expand Up @@ -271,7 +271,7 @@ func TestSubmitWithEmptyFile(t *testing.T) {
dir := filepath.Join(tmpDir, "bogus-track", "bogus-exercise")
os.MkdirAll(dir, os.FileMode(0755))

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

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

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

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

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

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

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

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

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

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

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

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

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

func writeFakeSolution(t *testing.T, dir, trackID, exerciseSlug string) {
solution := &workspace.Solution{
func writeFakeMetadata(t *testing.T, dir, trackID, exerciseSlug string) {
metadata := &workspace.ExerciseMetadata{
ID: "bogus-solution-uuid",
Track: trackID,
Exercise: exerciseSlug,
URL: "http://example.com/bogus-url",
IsRequester: true,
}
err := solution.Write(dir)
err := metadata.Write(dir)
assert.NoError(t, err)
}
2 changes: 1 addition & 1 deletion workspace/exercise.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func (e Exercise) MetadataFilepath() string {

// LegacyMetadataFilepath is the absolute path to the legacy exercise metadata.
func (e Exercise) LegacyMetadataFilepath() string {
return filepath.Join(e.Filepath(), legacySolutionFilename)
return filepath.Join(e.Filepath(), legacyMetadataFilename)
}

// MetadataDir returns the directory that the exercise metadata lives in.
Expand Down
Loading

0 comments on commit 2fbd8d7

Please sign in to comment.