From 5aea07054c56853f732c127a04bdf225ba5f9fa6 Mon Sep 17 00:00:00 2001 From: Elliot Forbes Date: Wed, 28 Sep 2022 16:49:08 +0100 Subject: [PATCH] Adds a Taskfile in line with internal Go dev standards and also formats the code --- Taskfile.yml | 60 +++++++++++++++++++++++++++++++++++++++++++++ api/context_rest.go | 4 +-- api/info/info.go | 2 +- cmd/context.go | 4 +-- cmd/follow.go | 4 +-- cmd/info/info.go | 6 ++--- cmd/open.go | 4 +-- cmd/root.go | 2 +- update/update.go | 28 ++++++++++----------- 9 files changed, 87 insertions(+), 27 deletions(-) create mode 100644 Taskfile.yml diff --git a/Taskfile.yml b/Taskfile.yml new file mode 100644 index 000000000..ad2d19df9 --- /dev/null +++ b/Taskfile.yml @@ -0,0 +1,60 @@ +version: '3' + +tasks: + lint: + desc: Lint code + cmds: + - golangci-lint run -c .golangci.yml + summary: Lint the project with golangci-lint + + clean: + desc: Cleans out the build, out, docs, and dist directories + cmds: + - GO111MODULE=off go clean -i + - rm -rf build out docs dist + + fmt: + desc: Run `go fmt` to format the code + cmds: + - go fmt ./... + + test: + desc: Run the tests + cmds: + - TESTING=true go test -v ./... + + tidy: + desc: Run 'go mod tidy' to clean up module files. + cmds: + - go mod tidy -v + + doc: + desc: run's the godocs + cmds: + - godoc -http=:6060 + + check-go-mod: + desc: Check go.mod is tidy + cmds: + - go mod tidy -v + - git diff --exit-code -- go.mod go.sum + + vendor: + desc: go mod vendor + cmds: + - go mod vendor + + build: + desc: Build main + cmds: + - go build -v -o build/darwin/amd64/circleci . + + build-linux: + desc: Build main + cmds: + - go build -v -o build/linux/amd64/circleci . + + cover: + desc: tests and generates a cover profile + cmds: + - TESTING=true go test -race -coverprofile=coverage.txt ./... \ No newline at end of file diff --git a/api/context_rest.go b/api/context_rest.go index fcc169a8a..d953bc7aa 100644 --- a/api/context_rest.go +++ b/api/context_rest.go @@ -359,7 +359,7 @@ func (c *ContextRestClient) listContexts(params *listContextsParams) (*listConte return &dest, nil } -//newCreateContextRequest posts a new context creation with orgname and vcs type using a slug +// newCreateContextRequest posts a new context creation with orgname and vcs type using a slug func (c *ContextRestClient) newCreateContextRequest(vcs, org, name string) (*http.Request, error) { var err error queryURL, err := url.Parse(c.server) @@ -398,7 +398,7 @@ func (c *ContextRestClient) newCreateContextRequest(vcs, org, name string) (*htt return c.newHTTPRequest("POST", queryURL.String(), bodyReader) } -//newCreateContextRequestWithOrgID posts a new context creation with an orgID +// newCreateContextRequestWithOrgID posts a new context creation with an orgID func (c *ContextRestClient) newCreateContextRequestWithOrgID(orgID *string, name string) (*http.Request, error) { var err error queryURL, err := url.Parse(c.server) diff --git a/api/info/info.go b/api/info/info.go index 3ba9c65ce..cb7fae40b 100644 --- a/api/info/info.go +++ b/api/info/info.go @@ -31,7 +31,7 @@ type InfoRESTClient struct { client *http.Client } -//organization json org info +// organization json org info type Organization struct { ID string `json:"id"` Name string `json:"name"` diff --git a/cmd/context.go b/cmd/context.go index 8369d0439..aebdd6558 100644 --- a/cmd/context.go +++ b/cmd/context.go @@ -199,8 +199,8 @@ func readSecretValue() (string, error) { } } -//createContext determines if the context is being created via orgid or vcs and org name -//and navigates to corresponding function accordingly +// createContext determines if the context is being created via orgid or vcs and org name +// and navigates to corresponding function accordingly func createContext(cmd *cobra.Command, client api.ContextInterface, args []string) error { //skip if no orgid provided if orgID != nil && strings.TrimSpace(*orgID) != "" && len(args) == 1 { diff --git a/cmd/follow.go b/cmd/follow.go index 3471c0cd7..31eb3bbae 100644 --- a/cmd/follow.go +++ b/cmd/follow.go @@ -14,7 +14,7 @@ type options struct { cfg *settings.Config } -//followProject gets the remote data and attempts to follow its git project +// followProject gets the remote data and attempts to follow its git project func followProject(opts options) error { remote, err := git.InferProjectFromGitRemotes() @@ -45,7 +45,7 @@ func followProject(opts options) error { return nil } -//followProjectCommand follow cobra command creation +// followProjectCommand follow cobra command creation func followProjectCommand(config *settings.Config) *cobra.Command { opts := options{ cfg: config, diff --git a/cmd/info/info.go b/cmd/info/info.go index d0ba3e0e6..1ed3028fe 100644 --- a/cmd/info/info.go +++ b/cmd/info/info.go @@ -9,7 +9,7 @@ import ( "github.com/spf13/cobra" ) -//infoOptions info command options +// infoOptions info command options type infoOptions struct { cfg *settings.Config validator validator.Validator @@ -33,7 +33,7 @@ func NewInfoCommand(config *settings.Config, preRunE validator.Validator) *cobra return infoCommand } -//orgInfoCommand organization information subcommand cobra command creation +// orgInfoCommand organization information subcommand cobra command creation func orgInfoCommand(client info.InfoClient, opts infoOptions) *cobra.Command { return &cobra.Command{ Use: "org", @@ -48,7 +48,7 @@ func orgInfoCommand(client info.InfoClient, opts infoOptions) *cobra.Command { } } -//getOrgInformation gets all of the users organizations' information +// getOrgInformation gets all of the users organizations' information func getOrgInformation(cmd *cobra.Command, client info.InfoClient) error { resp, err := client.GetInfo() if err != nil { diff --git a/cmd/open.go b/cmd/open.go index 8300aec65..6f1772b1d 100644 --- a/cmd/open.go +++ b/cmd/open.go @@ -16,7 +16,7 @@ var errorMessage = ` This command is intended to be run from a git repository with a remote named 'origin' that is hosted on Github or Bitbucket only. We are not currently supporting any other hosts.` -//projectUrl uses the provided values to create the url to open +// projectUrl uses the provided values to create the url to open func projectUrl(remote *git.Remote) string { return fmt.Sprintf("https://app.circleci.com/pipelines/%s/%s/%s", url.PathEscape(strings.ToLower(string(remote.VcsType))), @@ -24,7 +24,7 @@ func projectUrl(remote *git.Remote) string { url.PathEscape(remote.Project)) } -//openProjectInBrowser takes the created url and opens a browser to it +// openProjectInBrowser takes the created url and opens a browser to it func openProjectInBrowser() error { remote, err := git.InferProjectFromGitRemotes() if err != nil { diff --git a/cmd/root.go b/cmd/root.go index 174f764eb..f47ff96ea 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -294,7 +294,7 @@ func skipUpdateByDefault() bool { /**************** Help Menu Functions ****************/ -//rootHelpLong creates content for the long field in the command +// rootHelpLong creates content for the long field in the command func rootHelpLong() string { long := ` /?? /?? /?? diff --git a/update/update.go b/update/update.go index a82f126f0..77e1aa9ca 100644 --- a/update/update.go +++ b/update/update.go @@ -136,20 +136,20 @@ func checkFromHomebrew(check *Options) error { // HomebrewOutdated wraps the JSON output from running `brew outdated --json=v2` // We're specifically looking for this kind of structured data from the command: // -// { -// "formulae": [ -// { -// "name": "circleci", -// "installed_versions": [ -// "0.1.1248" -// ], -// "current_version": "0.1.3923", -// "pinned": false, -// "pinned_version": null -// } -// ], -// "casks": [] -// } +// { +// "formulae": [ +// { +// "name": "circleci", +// "installed_versions": [ +// "0.1.1248" +// ], +// "current_version": "0.1.3923", +// "pinned": false, +// "pinned_version": null +// } +// ], +// "casks": [] +// } type HomebrewOutdated struct { Formulae []struct { Name string `json:"name"`