mirror of
https://github.com/MichaelMure/git-bug.git
synced 2024-12-14 17:51:44 +03:00
5ca326af83
bridge/core: add ImportResult objects to stream import events bridge/core: launchpad support asynchronous import bridge/github: cancellable export and import functions bridge/gitlab: cancellable export and import functions commands: bridge pull/push gracefull kill bridge/github: fix github import bridge/github: use simple context for imports bridge/core: name parameters in interfaces github/core: Add EventError to export and import events types bridge/gitlab: add context support in gitlab requests functions bridge/gitlab: remove imported events count from importer logic bridge/github: remove imported events count from importer logic bridge/github: add context support in query and muration requets bridge/github: fix bug duplicate editions after multiple calls bridge/core: import import and export events String methods bridge/gitlab: fix error handling in note import events commands/bridge: Add statistics about imports and exports bridge/gitlab: properly handle context cancellation bridge/github: improve error handling bridge: break iterators on context cancel or timeout bridge: add context timeout support bridge: improve event formating and error handling commands: handle interrupt and switch cases bridge/github: add export mutation timeouts bridge: fix race condition bug in the github and gitlab importers bridge/github: improve context error handling
75 lines
1.4 KiB
Go
75 lines
1.4 KiB
Go
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
|
|
MergeStatusError
|
|
)
|
|
|
|
type MergeResult struct {
|
|
// Err is set when a terminal error occur in the process
|
|
Err error
|
|
|
|
Id Id
|
|
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"
|
|
case MergeStatusError:
|
|
return fmt.Sprintf("merge error on %s: %s", mr.Id, mr.Err.Error())
|
|
default:
|
|
panic("unknown merge status")
|
|
}
|
|
}
|
|
|
|
func NewMergeError(err error, id Id) MergeResult {
|
|
return MergeResult{
|
|
Err: err,
|
|
Id: id,
|
|
Status: MergeStatusError,
|
|
}
|
|
}
|
|
|
|
func NewMergeStatus(status MergeStatus, id Id, entity Interface) MergeResult {
|
|
return MergeResult{
|
|
Id: id,
|
|
Status: status,
|
|
|
|
// Entity is not set for an invalid merge result
|
|
Entity: entity,
|
|
}
|
|
}
|
|
|
|
func NewMergeInvalidStatus(id Id, reason string) MergeResult {
|
|
return MergeResult{
|
|
Id: id,
|
|
Status: MergeStatusInvalid,
|
|
Reason: reason,
|
|
}
|
|
}
|