Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Removing team functionality #957

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ language: go
sudo: false

go:
- "1.11.x"
- "1.12.x"
- "1.15.x"
- tip

matrix:
Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,12 @@ This CLI ships as a binary with no additional runtime requirements.

## Installing the CLI

Instructions can be found at [exercism/cli/releases](https://github.com/exercism/cli/releases)
Instructions can be found at [Cutting a CLI Release][release].

## Contributing

If you wish to help improve the CLI, please see the [Contributing guide][contributing].

[exercism]: http://exercism.io
[contributing]: /CONTRIBUTING.md
[release]: /RELEASE.md
4 changes: 2 additions & 2 deletions RELEASE.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ Make sure all the recent changes are reflected in the "next release" section of
You can view changes using the /compare/ view:
https://github.com/exercism/cli/compare/$PREVIOUS_RELEASE...master

GoReleaser supports the [auto generation of a changelog](https://goreleaser.com/customization/#customize-the-changelog) we will want to customize to meet our standards (not including refactors, test updates, etc). We should also consider using [the release notes feature](https://goreleaser.com/customization/#custom-release-notes).
GoReleaser supports the [auto generation of a changelog](https://goreleaser.com/customization/#customize-the-changelog), however we would need to customize the output to meet our standards (not including refactors, test updates, etc). We should also consider using [the release notes feature](https://goreleaser.com/customization/#custom-release-notes).

## Bump the version

Expand Down Expand Up @@ -97,6 +97,6 @@ For more information see [How To Open a Homebrew Pull Request](https://docs.brew
## Update the docs site

If there are any significant changes, we should describe them on
[exercism.io/cli]([https://exercism.io/cli).
[exercism.io/cli](https://exercism.io/cli).

The codebase lives at [exercism/website-copy](https://github.com/exercism/website-copy) in `pages/cli.md`.
27 changes: 7 additions & 20 deletions cmd/download.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ type download struct {
token, apibaseurl, workspace string

// optional
track, team string
track string

payload *downloadPayload
}
Expand All @@ -153,10 +153,6 @@ func newDownload(flags *pflag.FlagSet, usrCfg *viper.Viper) (*download, error) {
if err != nil {
return nil, err
}
d.team, err = flags.GetString("team")
if err != nil {
return nil, err
}

d.token = usrCfg.GetString("token")
d.apibaseurl = usrCfg.GetString("apibaseurl")
Expand All @@ -168,7 +164,7 @@ func newDownload(flags *pflag.FlagSet, usrCfg *viper.Viper) (*download, error) {
if err = d.needsUserConfigValues(); err != nil {
return nil, err
}
if err = d.needsSlugWhenGivenTrackOrTeam(); err != nil {
if err = d.needsSlugWhenGivenTrack(); err != nil {
return nil, err
}

Expand Down Expand Up @@ -218,9 +214,6 @@ func (d download) buildQueryParams(url *netURL.URL) {
if d.track != "" {
query.Add("track_id", d.track)
}
if d.team != "" {
query.Add("team_id", d.team)
}
}
url.RawQuery = query.Encode()
}
Expand Down Expand Up @@ -248,11 +241,11 @@ func (d download) needsUserConfigValues() error {
return nil
}

// needsSlugWhenGivenTrackOrTeam ensures that track/team arguments are also given with a slug.
// (track/team meaningless when given a uuid).
func (d download) needsSlugWhenGivenTrackOrTeam() error {
if (d.team != "" || d.track != "") && d.slug == "" {
return errors.New("--track or --team requires --exercise (not --uuid)")
// needsSlugWhenGivenTrack ensures that track arguments are also given with a slug.
// (track is meaningless when given a uuid).
func (d download) needsSlugWhenGivenTrack() error {
if d.track != "" && d.slug == "" {
return errors.New("--track requires --exercise (not --uuid)")
}
return nil
}
Expand All @@ -261,10 +254,6 @@ type downloadPayload struct {
Solution struct {
ID string `json:"id"`
URL string `json:"url"`
Team struct {
Name string `json:"name"`
Slug string `json:"slug"`
} `json:"team"`
User struct {
Handle string `json:"handle"`
IsRequester bool `json:"is_requester"`
Expand Down Expand Up @@ -295,7 +284,6 @@ func (dp downloadPayload) metadata() workspace.ExerciseMetadata {
return workspace.ExerciseMetadata{
AutoApprove: dp.Solution.Exercise.AutoApprove,
Track: dp.Solution.Exercise.Track.ID,
Team: dp.Solution.Team.Slug,
ExerciseSlug: dp.Solution.Exercise.ID,
ID: dp.Solution.ID,
URL: dp.Solution.URL,
Expand Down Expand Up @@ -353,7 +341,6 @@ func setupDownloadFlags(flags *pflag.FlagSet) {
flags.StringP("uuid", "u", "", "the solution UUID")
flags.StringP("track", "t", "", "the track ID")
flags.StringP("exercise", "e", "", "the exercise slug")
flags.StringP("team", "T", "", "the team slug")
}

func init() {
Expand Down
18 changes: 4 additions & 14 deletions cmd/download_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,19 +161,14 @@ func TestDownload(t *testing.T) {
expectedDir: filepath.Join("users", "alice"),
flags: map[string]string{"uuid": "bogus-id"},
},
{
requester: true,
expectedDir: filepath.Join("teams", "bogus-team"),
flags: map[string]string{"exercise": "bogus-exercise", "track": "bogus-track", "team": "bogus-team"},
},
}

for _, tc := range testCases {
tmpDir, err := ioutil.TempDir("", "download-cmd")
defer os.RemoveAll(tmpDir)
assert.NoError(t, err)

ts := fakeDownloadServer(strconv.FormatBool(tc.requester), tc.flags["team"])
ts := fakeDownloadServer(strconv.FormatBool(tc.requester))
defer ts.Close()

v := viper.New()
Expand Down Expand Up @@ -209,7 +204,7 @@ func TestDownload(t *testing.T) {
}
}

func fakeDownloadServer(requestor, teamSlug string) *httptest.Server {
func fakeDownloadServer(requestor string) *httptest.Server {
mux := http.NewServeMux()
server := httptest.NewServer(mux)

Expand All @@ -226,15 +221,11 @@ func fakeDownloadServer(requestor, teamSlug string) *httptest.Server {
})

mux.HandleFunc("/solutions/latest", func(w http.ResponseWriter, r *http.Request) {
team := "null"
if teamSlug := r.FormValue("team_id"); teamSlug != "" {
team = fmt.Sprintf(`{"name": "Bogus Team", "slug": "%s"}`, teamSlug)
}
payloadBody := fmt.Sprintf(payloadTemplate, requestor, team, server.URL+"/")
payloadBody := fmt.Sprintf(payloadTemplate, requestor, server.URL+"/")
fmt.Fprint(w, payloadBody)
})
mux.HandleFunc("/solutions/bogus-id", func(w http.ResponseWriter, r *http.Request) {
payloadBody := fmt.Sprintf(payloadTemplate, requestor, "null", server.URL+"/")
payloadBody := fmt.Sprintf(payloadTemplate, requestor, server.URL+"/")
fmt.Fprint(w, payloadBody)
})

Expand Down Expand Up @@ -314,7 +305,6 @@ const payloadTemplate = `
"handle": "alice",
"is_requester": %s
},
"team": %s,
"exercise": {
"id": "bogus-exercise",
"instructions_url": "http://example.com/bogus-exercise",
Expand Down
2 changes: 1 addition & 1 deletion cmd/submit.go
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ func (s *submitCmdContext) printResult(metadata *workspace.ExerciseMetadata) {
%s
`
suffix := "View it at:\n\n "
if metadata.AutoApprove && metadata.Team == "" {
if metadata.AutoApprove {
suffix = "You can complete the exercise and unlock the next core exercise at:\n"
}
fmt.Fprintf(Err, msg, suffix)
Expand Down
47 changes: 0 additions & 47 deletions cmd/submit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -385,53 +385,6 @@ func TestSubmitWithEnormousFile(t *testing.T) {
}
}

func TestSubmitFilesForTeamExercise(t *testing.T) {
co := newCapturedOutput()
co.override()
defer co.reset()

// The fake endpoint will populate this when it receives the call from the command.
submittedFiles := map[string]string{}
ts := fakeSubmitServer(t, submittedFiles)
defer ts.Close()

tmpDir, err := ioutil.TempDir("", "submit-files")
assert.NoError(t, err)

dir := filepath.Join(tmpDir, "teams", "bogus-team", "bogus-track", "bogus-exercise")
os.MkdirAll(filepath.Join(dir, "subdir"), os.FileMode(0755))
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))
assert.NoError(t, err)

file2 := filepath.Join(dir, "subdir", "file-2.txt")
err = ioutil.WriteFile(file2, []byte("This is file 2."), os.FileMode(0755))
assert.NoError(t, err)

v := viper.New()
v.Set("token", "abc123")
v.Set("workspace", tmpDir)
v.Set("apibaseurl", ts.URL)

cfg := config.Config{
Dir: tmpDir,
UserViperConfig: v,
}

files := []string{
file1, file2,
}
err = runSubmit(cfg, pflag.NewFlagSet("fake", pflag.PanicOnError), files)
assert.NoError(t, err)

assert.Equal(t, 2, len(submittedFiles))

assert.Equal(t, "This is file 1.", submittedFiles["file-1.txt"])
assert.Equal(t, "This is file 2.", submittedFiles["subdir/file-2.txt"])
}

func TestSubmitOnlyEmptyFile(t *testing.T) {
co := newCapturedOutput()
co.override()
Expand Down
40 changes: 22 additions & 18 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,26 +1,30 @@
module github.com/exercism/cli

go 1.15

require (
github.com/blang/semver v3.5.1+incompatible
github.com/davecgh/go-spew v1.1.0
github.com/fsnotify/fsnotify v1.4.2
github.com/hashicorp/hcl v0.0.0-20170509225359-392dba7d905e
github.com/davecgh/go-spew v1.1.1
github.com/fsnotify/fsnotify v1.4.9
github.com/hashicorp/hcl v1.0.0
github.com/inconshreveable/go-update v0.0.0-20160112193335-8152e7eb6ccf
github.com/inconshreveable/mousetrap v1.0.0
github.com/magiconair/properties v1.7.3
github.com/mitchellh/mapstructure v0.0.0-20170523030023-d0303fe80992
github.com/pelletier/go-buffruneio v0.2.0
github.com/pelletier/go-toml v1.0.0
github.com/magiconair/properties v1.8.2
github.com/mitchellh/mapstructure v1.3.3
github.com/pelletier/go-buffruneio v0.3.0
github.com/pelletier/go-toml v1.8.0
github.com/pmezard/go-difflib v1.0.0
github.com/spf13/afero v0.0.0-20170217164146-9be650865eab
github.com/spf13/cast v1.1.0
github.com/spf13/cobra v0.0.0-20170731170427-b26b538f6930
github.com/spf13/jwalterweatherman v0.0.0-20170523133247-0efa5202c046
github.com/spf13/pflag v1.0.0
github.com/spf13/viper v0.0.0-20180507071007-15738813a09d
github.com/stretchr/testify v1.1.4
golang.org/x/net v0.0.0-20170726083632-f5079bd7f6f7
golang.org/x/sys v0.0.0-20170803140359-d8f5ea21b929
golang.org/x/text v0.0.0-20170730040918-3bd178b88a81
gopkg.in/yaml.v2 v2.0.0-20170721122051-25c4ec802a7d
github.com/spf13/afero v1.3.5
github.com/spf13/cast v1.3.1
github.com/spf13/cobra v1.0.0
github.com/spf13/jwalterweatherman v1.1.0
github.com/spf13/pflag v1.0.5
github.com/spf13/viper v1.7.1
github.com/stretchr/testify v1.6.1
golang.org/x/net v0.0.0-20200822124328-c89045814202
golang.org/x/sys v0.0.0-20200831180312-196b9ba8737a
golang.org/x/text v0.3.3
gopkg.in/ini.v1 v1.60.2 // indirect
gopkg.in/yaml.v2 v2.3.0
gopkg.in/yaml.v3 v3.0.0-20200615113413-eeeca48fe776 // indirect
)
Loading