aboutsummaryrefslogtreecommitdiffstats
path: root/bug/bug_actions.go
diff options
context:
space:
mode:
authorMichael Muré <batolettre@gmail.com>2018-09-15 13:15:00 +0200
committerMichael Muré <batolettre@gmail.com>2018-09-15 13:15:00 +0200
commit7bec0b1f134d213e7505fc2ac03ffea26f2193cc (patch)
treee263cccd84406843eacbc6bd184acdacb25a49d1 /bug/bug_actions.go
parentb478cd1bcb4756b20f7f4b15fcf81f23e1a60a02 (diff)
downloadgit-bug-7bec0b1f134d213e7505fc2ac03ffea26f2193cc.tar.gz
bug: add a data validation process to avoid merging incorrect operations
Diffstat (limited to 'bug/bug_actions.go')
-rw-r--r--bug/bug_actions.go41
1 files changed, 27 insertions, 14 deletions
diff --git a/bug/bug_actions.go b/bug/bug_actions.go
index 8bda15b7..7f2194ab 100644
--- a/bug/bug_actions.go
+++ b/bug/bug_actions.go
@@ -66,8 +66,8 @@ func MergeAll(repo repository.Repo, remote string) <-chan MergeResult {
}
// Check for error in remote data
- if !remoteBug.IsValid() {
- out <- newMergeStatus(MergeStatusInvalid, id, nil)
+ if err := remoteBug.Validate(); err != nil {
+ out <- newMergeInvalidStatus(id, err.Error())
continue
}
@@ -128,12 +128,26 @@ const (
MergeStatusNothing
)
-func (ms MergeStatus) String() string {
- switch ms {
+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
+ Bug *Bug
+}
+
+func (mr MergeResult) String() string {
+ switch mr.Status {
case MergeStatusNew:
return "new"
case MergeStatusInvalid:
- return "invalid data"
+ return fmt.Sprintf("invalid data: %s", mr.Reason)
case MergeStatusUpdated:
return "updated"
case MergeStatusNothing:
@@ -143,15 +157,6 @@ func (ms MergeStatus) String() string {
}
}
-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,
@@ -168,3 +173,11 @@ func newMergeStatus(status MergeStatus, id string, bug *Bug) MergeResult {
Bug: bug,
}
}
+
+func newMergeInvalidStatus(id string, reason string) MergeResult {
+ return MergeResult{
+ Id: id,
+ Status: MergeStatusInvalid,
+ Reason: reason,
+ }
+}