diff options
| author | Hugo Soto <hsotoorellana@gmail.com> | 2018-12-27 17:51:06 -0300 |
|---|---|---|
| committer | Ibrahim Serdar Acikgoz <serdaracikgoz86@gmail.com> | 2018-12-27 23:51:06 +0300 |
| commit | dd5d87b9194954f45135edfc15d6b22bf135cddf (patch) | |
| tree | 84114b4da27f2b79838afb7f11645017ad9232d5 | |
| parent | bump version (diff) | |
| download | gitbatch-dd5d87b9194954f45135edfc15d6b22bf135cddf.tar.gz | |
Fix/linting (#41)
* Clean err returning
* Fix var naming convention
* Inline error return values and reorder imports
* Add and improve func and const descriptions
* Inline returning values
| -rw-r--r-- | pkg/git/authentication.go | 4 | ||||
| -rw-r--r-- | pkg/git/branch.go | 6 | ||||
| -rw-r--r-- | pkg/git/cmd-commit.go | 8 | ||||
| -rw-r--r-- | pkg/git/cmd-config.go | 16 | ||||
| -rw-r--r-- | pkg/git/cmd-fetch.go | 5 | ||||
| -rw-r--r-- | pkg/git/cmd-pull.go | 6 | ||||
| -rw-r--r-- | pkg/git/cmd-reset.go | 5 | ||||
| -rw-r--r-- | pkg/git/commit.go | 5 | ||||
| -rw-r--r-- | pkg/git/job.go | 10 | ||||
| -rw-r--r-- | pkg/git/remotebranch.go | 2 | ||||
| -rw-r--r-- | pkg/git/repository.go | 4 |
11 files changed, 35 insertions, 36 deletions
diff --git a/pkg/git/authentication.go b/pkg/git/authentication.go index 3e834ec..a33816b 100644 --- a/pkg/git/authentication.go +++ b/pkg/git/authentication.go @@ -14,8 +14,8 @@ type Credentials struct { } var ( - authProtocolHttp = "http" - authProtocolHttps = "https" + authProtocolHTTP = "http" + authProtocolHTTPS = "https" authProtocolSSH = "ssh" ) diff --git a/pkg/git/branch.go b/pkg/git/branch.go index 5be8e16..5277e20 100644 --- a/pkg/git/branch.go +++ b/pkg/git/branch.go @@ -1,13 +1,13 @@ package git import ( + "strconv" + "strings" + "github.com/isacikgoz/gitbatch/pkg/helpers" log "github.com/sirupsen/logrus" "gopkg.in/src-d/go-git.v4" "gopkg.in/src-d/go-git.v4/plumbing" - - "strconv" - "strings" ) // Branch is the wrapper of go-git's Reference struct. In addition to that, it diff --git a/pkg/git/cmd-commit.go b/pkg/git/cmd-commit.go index 6e836ab..23c1de1 100644 --- a/pkg/git/cmd-commit.go +++ b/pkg/git/cmd-commit.go @@ -27,7 +27,7 @@ type CommitOptions struct { Email string } -// CommitCommand +// CommitCommand defines which commit command to use. func CommitCommand(e *RepoEntity, options CommitOptions) (err error) { // here we configure commit operation // default mode is go-git (this may be configured) @@ -35,11 +35,9 @@ func CommitCommand(e *RepoEntity, options CommitOptions) (err error) { switch commitCmdMode { case commitCmdModeLegacy: - err = commitWithGit(e, options) - return err + return commitWithGit(e, options) case commitCmdModeNative: - err = commitWithGoGit(e, options) - return err + return commitWithGoGit(e, options) } return errors.New("Unhandled commit operation") } diff --git a/pkg/git/cmd-config.go b/pkg/git/cmd-config.go index 06ba74b..e4bacf0 100644 --- a/pkg/git/cmd-config.go +++ b/pkg/git/cmd-config.go @@ -14,7 +14,7 @@ var ( configCmdModeNative = "go-git" ) -// CommitOptions defines the rules for commit operation +// ConfigOptions defines the rules for commit operation type ConfigOptions struct { // Section Section string @@ -24,12 +24,14 @@ type ConfigOptions struct { Site ConfigSite } +// ConfigSite defines a string type for the site. type ConfigSite string const ( - // ConfigStieLocal + // ConfigSiteLocal defines a local config. ConfigSiteLocal ConfigSite = "local" - // ConfgiSiteGlobal + + // ConfgiSiteGlobal defines a global config. ConfgiSiteGlobal ConfigSite = "global" ) @@ -41,11 +43,9 @@ func Config(e *RepoEntity, options ConfigOptions) (value string, err error) { switch configCmdMode { case configCmdModeLegacy: - value, err = configWithGit(e, options) - return value, err + return configWithGit(e, options) case configCmdModeNative: - value, err = configWithGoGit(e, options) - return value, err + return configWithGoGit(e, options) } return value, errors.New("Unhandled config operation") } @@ -78,7 +78,7 @@ func configWithGoGit(e *RepoEntity, options ConfigOptions) (value string, err er return config.Raw.Section(options.Section).Option(options.Option), nil } -// AddConfig +// AddConfig adds an entry on the ConfigOptions field. func AddConfig(e *RepoEntity, options ConfigOptions, value string) (err error) { return addConfigWithGit(e, options, value) diff --git a/pkg/git/cmd-fetch.go b/pkg/git/cmd-fetch.go index e7a60f7..0830105 100644 --- a/pkg/git/cmd-fetch.go +++ b/pkg/git/cmd-fetch.go @@ -113,7 +113,7 @@ func fetchWithGoGit(e *RepoEntity, options FetchOptions, refspec string) (err er if err != nil { return err } - if protocol == authProtocolHttp || protocol == authProtocolHttps { + if protocol == authProtocolHTTP || protocol == authProtocolHTTPS { opt.Auth = &http.BasicAuth{ Username: options.Credentials.User, Password: options.Credentials.Password, @@ -123,8 +123,7 @@ func fetchWithGoGit(e *RepoEntity, options FetchOptions, refspec string) (err er } } - err = e.Repository.Fetch(opt) - if err != nil { + if err := e.Repository.Fetch(opt); err != nil { if err == git.NoErrAlreadyUpToDate { // Already up-to-date log.Warn(err.Error()) diff --git a/pkg/git/cmd-pull.go b/pkg/git/cmd-pull.go index 2c28d3a..f620925 100644 --- a/pkg/git/cmd-pull.go +++ b/pkg/git/cmd-pull.go @@ -85,7 +85,7 @@ func pullWithGoGit(e *RepoEntity, options PullOptions) (err error) { if err != nil { return err } - if protocol == authProtocolHttp || protocol == authProtocolHttps { + if protocol == authProtocolHTTP || protocol == authProtocolHTTPS { opt.Auth = &http.BasicAuth{ Username: options.Credentials.User, Password: options.Credentials.Password, @@ -98,8 +98,8 @@ func pullWithGoGit(e *RepoEntity, options PullOptions) (err error) { if err != nil { return err } - err = w.Pull(opt) - if err != nil { + + if err = w.Pull(opt); err != nil { if err == git.NoErrAlreadyUpToDate { // Already up-to-date log.Warn(err.Error()) diff --git a/pkg/git/cmd-reset.go b/pkg/git/cmd-reset.go index cc5f0f9..bea436c 100644 --- a/pkg/git/cmd-reset.go +++ b/pkg/git/cmd-reset.go @@ -24,23 +24,28 @@ type ResetOptions struct { Rtype ResetType } +// ResetType defines a string type for reset git command. type ResetType string const ( // ResetHard Resets the index and working tree. Any changes to tracked // files in the working tree since <commit> are discarded. ResetHard ResetType = "hard" + // ResetMixed Resets the index but not the working tree (i.e., the changed // files are preserved but not marked for commit) and reports what has not // been updated. This is the default action. ResetMixed ResetType = "mixed" + // ResetMerge Resets the index and updates the files in the working tree // that are different between <commit> and HEAD, but keeps those which are // different between the index and working tree ResetMerge ResetType = "merge" + // ResetSoft Does not touch the index file or the working tree at all // (but resets the head to <commit> ResetSoft ResetType = "soft" + // ResetKeep Resets index entries and updates files in the working tree // that are different between <commit> and HEAD ResetKeep ResetType = "keep" diff --git a/pkg/git/commit.go b/pkg/git/commit.go index 716ccba..f78bb64 100644 --- a/pkg/git/commit.go +++ b/pkg/git/commit.go @@ -99,10 +99,7 @@ func (e *RepoEntity) loadCommits() error { e.Commits = append(e.Commits, commit) return nil }) - if err != nil { - return err - } - return nil + return err } // this function creates the commit entities according to active branchs diffs diff --git a/pkg/git/job.go b/pkg/git/job.go index c64086e..85c28f3 100644 --- a/pkg/git/job.go +++ b/pkg/git/job.go @@ -1,7 +1,5 @@ package git -import () - // Job relates the type of the operation and the entity type Job struct { // JobType is to select operation type that will be applied to repository @@ -16,11 +14,13 @@ type Job struct { type JobType string const ( - // Fetch is wrapper of git fetch command + // FetchJob is wrapper of git fetch command FetchJob JobType = "fetch" - // Pull is wrapper of git pull command + + // PullJob is wrapper of git pull command PullJob JobType = "pull" - // Merge is wrapper of git merge command + + // MergeJob is wrapper of git merge command MergeJob JobType = "merge" ) diff --git a/pkg/git/remotebranch.go b/pkg/git/remotebranch.go index 207f5a9..337b28b 100644 --- a/pkg/git/remotebranch.go +++ b/pkg/git/remotebranch.go @@ -86,5 +86,5 @@ func (r *Remote) switchRemoteBranch(remoteBranchName string) error { return nil } } - return errors.New("Remote branch not found.") + return errors.New("Remote branch not found") } diff --git a/pkg/git/repository.go b/pkg/git/repository.go index 28c95cd..0e57482 100644 --- a/pkg/git/repository.go +++ b/pkg/git/repository.go @@ -65,7 +65,7 @@ var ( ) const ( - // This is the repository updated topic + // RepositoryUpdated defines the topic for an updated repository. RepositoryUpdated = "repository.updated" ) @@ -176,7 +176,7 @@ func (e *RepoEntity) On(event string, listener RepositoryListener) { e.listeners[event] = append(e.listeners[event], listener) } -// Emit notifies listeners about the event +// Publish publishes the data to a certain event by its name. func (e *RepoEntity) Publish(eventName string, data interface{}) error { e.mutex.RLock() defer e.mutex.RUnlock() |
