diff options
author | Michael Muré <michael.mure@consensys.net> | 2019-03-27 21:44:11 +0100 |
---|---|---|
committer | Michael Muré <michael.mure@consensys.net> | 2019-03-27 21:44:11 +0100 |
commit | 24d6714dd59a5c385c21991caa47e5727de043d0 (patch) | |
tree | 154306261bf98b599e1f3465940bb46c290b8c72 /entity/merge.go | |
parent | d27e3849b826309bdf2dbf6f30f2a8ac9db71649 (diff) | |
download | git-bug-24d6714dd59a5c385c21991caa47e5727de043d0.tar.gz |
cache: properly push/pull identities and bugs
Diffstat (limited to 'entity/merge.go')
-rw-r--r-- | entity/merge.go | 68 |
1 files changed, 68 insertions, 0 deletions
diff --git a/entity/merge.go b/entity/merge.go new file mode 100644 index 00000000..544f2168 --- /dev/null +++ b/entity/merge.go @@ -0,0 +1,68 @@ +package entity + +import "fmt" + +// MergeStatus represent the result of a merge operation of an entity +type MergeStatus int + +const ( + _ MergeStatus = iota + MergeStatusNew + MergeStatusInvalid + MergeStatusUpdated + MergeStatusNothing +) + +type MergeResult struct { + // Err is set when a terminal error occur in the process + Err error + + Id string + Status MergeStatus + + // Only set for invalid status + Reason string + + // Not set for invalid status + Entity Interface +} + +func (mr MergeResult) String() string { + switch mr.Status { + case MergeStatusNew: + return "new" + case MergeStatusInvalid: + return fmt.Sprintf("invalid data: %s", mr.Reason) + case MergeStatusUpdated: + return "updated" + case MergeStatusNothing: + return "nothing to do" + default: + panic("unknown merge status") + } +} + +func NewMergeError(err error, id string) MergeResult { + return MergeResult{ + Err: err, + Id: id, + } +} + +func NewMergeStatus(status MergeStatus, id string, entity Interface) MergeResult { + return MergeResult{ + Id: id, + Status: status, + + // Entity is not set for an invalid merge result + Entity: entity, + } +} + +func NewMergeInvalidStatus(id string, reason string) MergeResult { + return MergeResult{ + Id: id, + Status: MergeStatusInvalid, + Reason: reason, + } +} |