Skip to content

Commit

Permalink
Fix some go lints
Browse files Browse the repository at this point in the history
commit-id:e2ae7a2e
  • Loading branch information
ejoffe committed Jul 7, 2021
1 parent 62db5a5 commit a5c67a9
Show file tree
Hide file tree
Showing 9 changed files with 33 additions and 15 deletions.
1 change: 1 addition & 0 deletions git/commit.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package git

// Commit has all the git commit info
type Commit struct {
// CommitID is a long lasting id describing the commit.
// The CommitID is generated and added to the end of the commit message on the initial commit.
Expand Down
1 change: 1 addition & 0 deletions git/mockgit/mockgit.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"github.com/stretchr/testify/require"
)

// NewMockGit creates and new mock git instance
func NewMockGit(t *testing.T) *mock {
return &mock{
assert: require.New(t),
Expand Down
1 change: 1 addition & 0 deletions git/realgit/realcmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"github.com/rs/zerolog/log"
)

// NewGitCmd returns a new git cmd instance
func NewGitCmd(cfg *config.Config) *gitcmd {
initcmd := &gitcmd{
config: cfg,
Expand Down
5 changes: 1 addition & 4 deletions github/githubclient/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,15 +112,12 @@ func (c *client) GetInfo(ctx context.Context, gitcmd git.GitInterface) *github.G
Body: node.Commits.Nodes[0].Commit.MessageBody,
}

checkStatus := github.CheckStatusUnknown
checkStatus := github.CheckStatusFail
switch node.Commits.Nodes[0].Commit.StatusCheckRollup.State {

case "SUCCESS":
checkStatus = github.CheckStatusPass
case "PENDING":
checkStatus = github.CheckStatusPending
default:
checkStatus = github.CheckStatusFail
}

pullRequest.MergeStatus = github.PullRequestMergeStatus{
Expand Down
1 change: 1 addition & 0 deletions github/mockclient/mockclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"github.com/stretchr/testify/require"
)

// NewMockClient creates a new mock client
func NewMockClient(t *testing.T) *mockclient {
return &mockclient{
assert: require.New(t),
Expand Down
25 changes: 22 additions & 3 deletions github/pullrequest.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"github.com/ejoffe/spr/terminal"
)

// PullRequest has GitHub pull request data
type PullRequest struct {
ID string
Number int
Expand All @@ -24,17 +25,32 @@ type PullRequest struct {
type checkStatus int

const (
// CheckStatusUnknown
CheckStatusUnknown checkStatus = iota

// CheckStatusPending when checks are still running
CheckStatusPending

// CheckStatusPass when all checks pass
CheckStatusPass

// CheckStatusFail when some chechs have failed
CheckStatusFail
)

// PullRequestMergeStatus is the merge status of a pull request
type PullRequestMergeStatus struct {
ChecksPass checkStatus
// ChecksPass is the status of GitHub checks
ChecksPass checkStatus

// ReviewApproved is true when a pull request is approved by a fellow reviewer
ReviewApproved bool
NoConflicts bool
Stacked bool

// NoConflicts is true when there are no merge conflicts
NoConflicts bool

// Stacked is true when all requests in the stack up to this one are ready to merge
Stacked bool
}

// SortPullRequests sorts the pull requests so that the one that is on top of
Expand Down Expand Up @@ -73,6 +89,7 @@ func SortPullRequests(prs []*PullRequest, config *config.Config) []*PullRequest
return prs
}

// Mergeable returns true if the pull request is mergable
func (pr *PullRequest) Mergeable(config *config.Config) bool {
if !pr.MergeStatus.NoConflicts {
return false
Expand All @@ -89,6 +106,7 @@ func (pr *PullRequest) Mergeable(config *config.Config) bool {
return true
}

// Ready returns true if pull request is ready to merge
func (pr *PullRequest) Ready(config *config.Config) bool {
if pr.Commit.WIP {
return false
Expand All @@ -109,6 +127,7 @@ const checkmark = "\xE2\x9C\x94"
const crossmark = "\xE2\x9C\x97"
const middledot = "\xC2\xB7"

// StatusString returs a string representation of the merge status bits
func (pr *PullRequest) StatusString(config *config.Config) string {
statusString := "["

Expand Down
1 change: 1 addition & 0 deletions hook/commithook.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"github.com/google/uuid"
)

// CommitHook runs the commit hook to add commit-id to file named filename
func CommitHook(filename string) {
if shouldAppendCommitID(filename) {
appendCommitID(filename)
Expand Down
12 changes: 4 additions & 8 deletions spr/spr.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ type stackediff struct {
DetailEnabled bool
}

// AmendCommit enables one to easily ammend a commit in the middle of a stack
// of commits. A list of commits is printed and one can be chosen to be ammended.
// AmendCommit enables one to easily amend a commit in the middle of a stack
// of commits. A list of commits is printed and one can be chosen to be amended.
func (sd *stackediff) AmendCommit(ctx context.Context) {
localCommits := sd.getLocalCommitStack()
if len(localCommits) == 0 {
Expand Down Expand Up @@ -344,7 +344,7 @@ A commit is missing a commit-id.
This most likely means the commit-msg hook isn't installed.
To install the hook run the following cmd in the repo root dir:
> ln -s $(which spr_commit_hook) .git/hooks/commit-msg
After installing the hook, you'll need to ammend your commits.
After installing the hook, you'll need to amend your commits.
`

func (sd *stackediff) printCommitInstallHelper() {
Expand Down Expand Up @@ -385,11 +385,7 @@ func (sd *stackediff) syncCommitStackToGitHub(ctx context.Context,
commitUpdated := func(c git.Commit, info *github.GitHubInfo) bool {
for _, pr := range info.PullRequests {
if pr.Commit.CommitID == c.CommitID {
if pr.Commit.CommitHash == c.CommitHash {
return false
} else {
return true
}
return pr.Commit.CommitHash != c.CommitHash
}
}
return true
Expand Down
1 change: 1 addition & 0 deletions terminal/terminal_other.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"golang.org/x/sys/unix"
)

// Width returns the current character width of the terminal
func Width() (int, error) {
terminalMaxSize, err := unix.IoctlGetWinsize(int(os.Stdin.Fd()), unix.TIOCGWINSZ)
if err != nil {
Expand Down

0 comments on commit a5c67a9

Please sign in to comment.