diff options
author | Michael Muré <batolettre@gmail.com> | 2018-09-13 11:13:51 +0200 |
---|---|---|
committer | Michael Muré <batolettre@gmail.com> | 2018-09-13 11:13:51 +0200 |
commit | 19f43a83c3925ed3d05a4874dcbc84cbb454ea6c (patch) | |
tree | 3a1d595a7da57a89f46c595e46aafadaaa198425 /bug | |
parent | 27c5ea5b5b57887f51d5700398ee283dc191fff9 (diff) | |
download | git-bug-19f43a83c3925ed3d05a4874dcbc84cbb454ea6c.tar.gz |
bug: proper int baked enum for merge result status instead of a string
Diffstat (limited to 'bug')
-rw-r--r-- | bug/bug_actions.go | 91 | ||||
-rw-r--r-- | bug/operation.go | 2 |
2 files changed, 57 insertions, 36 deletions
diff --git a/bug/bug_actions.go b/bug/bug_actions.go index a51a1bf9..8bda15b7 100644 --- a/bug/bug_actions.go +++ b/bug/bug_actions.go @@ -7,11 +7,6 @@ import ( "github.com/MichaelMure/git-bug/repository" ) -const MsgMergeNew = "new" -const MsgMergeInvalid = "invalid data" -const MsgMergeUpdated = "updated" -const MsgMergeNothing = "nothing to do" - // Fetch retrieve update from a remote // This does not change the local bugs state func Fetch(repo repository.Repo, remote string) (string, error) { @@ -44,32 +39,6 @@ func Pull(repo repository.Repo, remote string) error { return nil } -type MergeResult struct { - // Err is set when a terminal error occur in the process - Err error - - Id string - Status string - Bug *Bug -} - -func newMergeError(err error, id string) MergeResult { - return MergeResult{ - Err: err, - Id: id, - } -} - -func newMergeStatus(status string, id string, bug *Bug) MergeResult { - return MergeResult{ - Id: id, - Status: status, - - // Bug is not set for an invalid merge result - Bug: bug, - } -} - // MergeAll will merge all the available remote bug func MergeAll(repo repository.Repo, remote string) <-chan MergeResult { out := make(chan MergeResult) @@ -98,7 +67,7 @@ func MergeAll(repo repository.Repo, remote string) <-chan MergeResult { // Check for error in remote data if !remoteBug.IsValid() { - out <- newMergeStatus(MsgMergeInvalid, id, nil) + out <- newMergeStatus(MergeStatusInvalid, id, nil) continue } @@ -119,7 +88,7 @@ func MergeAll(repo repository.Repo, remote string) <-chan MergeResult { return } - out <- newMergeStatus(MsgMergeNew, id, remoteBug) + out <- newMergeStatus(MergeStatusNew, id, remoteBug) continue } @@ -138,12 +107,64 @@ func MergeAll(repo repository.Repo, remote string) <-chan MergeResult { } if updated { - out <- newMergeStatus(MsgMergeUpdated, id, localBug) + out <- newMergeStatus(MergeStatusUpdated, id, localBug) } else { - out <- newMergeStatus(MsgMergeNothing, id, localBug) + out <- newMergeStatus(MergeStatusNothing, id, localBug) } } }() return out } + +// MergeStatus represent the result of a merge operation of a bug +type MergeStatus int + +const ( + _ MergeStatus = iota + MergeStatusNew + MergeStatusInvalid + MergeStatusUpdated + MergeStatusNothing +) + +func (ms MergeStatus) String() string { + switch ms { + case MergeStatusNew: + return "new" + case MergeStatusInvalid: + return "invalid data" + case MergeStatusUpdated: + return "updated" + case MergeStatusNothing: + return "nothing to do" + default: + panic("unknown merge status") + } +} + +type MergeResult struct { + // Err is set when a terminal error occur in the process + Err error + + Id string + Status MergeStatus + Bug *Bug +} + +func newMergeError(err error, id string) MergeResult { + return MergeResult{ + Err: err, + Id: id, + } +} + +func newMergeStatus(status MergeStatus, id string, bug *Bug) MergeResult { + return MergeResult{ + Id: id, + Status: status, + + // Bug is not set for an invalid merge result + Bug: bug, + } +} diff --git a/bug/operation.go b/bug/operation.go index 5d42a175..6a8aa0cd 100644 --- a/bug/operation.go +++ b/bug/operation.go @@ -5,7 +5,7 @@ import ( "time" ) -// OperationType is an identifier +// OperationType is an operation type identifier type OperationType int const ( |