Skip to content

Commit d8c09c9

Browse files
committed
Merge pull request #270 from exercism/submission-comments
Allow including a comment during submission using --comment
2 parents 2b42111 + bbfbf4f commit d8c09c9

5 files changed

Lines changed: 24 additions & 1 deletion

File tree

CHANGELOG.md

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

77
## Next Release
88
* **Your contribution here**
9+
* [#270](https://github.com/exercism/cli/pull/270) Allow commenting on submission with --comment [@Tonkpils](https://github.com/Tonkpils)
910

1011
## v2.2.3 (2015-12-27)
1112
* [#264](https://github.com/exercism/cli/pull/264) Fix version flag to use --version and --v - [@Tonkpils](https://github.com/Tonkpils)

api/api_test.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package api
22

33
import (
4+
"encoding/json"
45
"fmt"
56
"io"
67
"net/http"
@@ -148,9 +149,20 @@ func TestGetSubmission(t *testing.T) {
148149
}
149150

150151
func TestSubmitAssignment(t *testing.T) {
152+
submissionComment := "hello world!"
151153
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
152154
w.WriteHeader(http.StatusCreated)
153155

156+
var body map[string]string
157+
if err := json.NewDecoder(req.Body).Decode(&body); err != nil {
158+
t.Fatal(err)
159+
}
160+
161+
comment, ok := body["comment"]
162+
if ok && comment != submissionComment {
163+
t.Fatal("comment found and was empty")
164+
}
165+
154166
if err := respondWithFixture(w, "submit.json"); err != nil {
155167
t.Fatal(err)
156168
}
@@ -163,6 +175,11 @@ func TestSubmitAssignment(t *testing.T) {
163175
assert.NoError(t, err)
164176

165177
assert.Equal(t, sub.Language, "ruby")
178+
179+
// Test sending comment
180+
iter.Comment = submissionComment
181+
_, err = client.Submit(iter)
182+
assert.NoError(t, err)
166183
}
167184

168185
func TestListTrack(t *testing.T) {

api/iteration.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,13 +69,13 @@ type Iteration struct {
6969
TrackID string `json:"language"`
7070
Problem string `json:"problem"`
7171
Solution map[string]string `json:"solution"`
72+
Comment string `json:"comment,omitempty"`
7273
}
7374

7475
// NewIteration prepares an iteration of a problem in a track for submission to the API.
7576
// It takes a dir (from the global config) and a list of files which it will read from disk.
7677
// All paths are assumed to be absolute paths with symlinks resolved.
7778
func NewIteration(dir string, filenames []string) (*Iteration, error) {
78-
7979
if len(filenames) == 0 {
8080
return nil, errNoFiles
8181
}

cmd/submit.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ func Submit(ctx *cli.Context) {
8484
log.Fatalf("Unable to submit - %s", err)
8585
}
8686
iteration.Key = c.APIKey
87+
iteration.Comment = ctx.String("comment")
8788

8889
client := api.NewClient(c)
8990
submission, err := client.Submit(iteration)

exercism/main.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,10 @@ func main() {
117117
Name: "test",
118118
Usage: "allow submission of test files",
119119
},
120+
cli.StringFlag{
121+
Name: "comment",
122+
Usage: "includes a comment with the submission",
123+
},
120124
},
121125
},
122126
{

0 commit comments

Comments
 (0)