Merge pull request #287 from MichaelMure/github-import-error

Michael Muré created

Github import error

Change summary

bridge/core/bridge.go    |  2 +-
bridge/core/export.go    | 17 +++++++++++++++++
bridge/core/import.go    | 27 +++++++++++++++++++++++++++
bridge/github/import.go  |  5 +++++
repository/config_git.go |  6 +-----
5 files changed, 51 insertions(+), 6 deletions(-)

Detailed changes

bridge/core/bridge.go 🔗

@@ -347,7 +347,7 @@ func (b *Bridge) ImportAllSince(ctx context.Context, since time.Time) (<-chan Im
 
 		// relay all events while checking that everything went well
 		for event := range events {
-			if event.Err != nil {
+			if event.Event == ImportEventError {
 				noError = false
 			}
 			out <- event

bridge/core/export.go 🔗

@@ -29,6 +29,10 @@ const (
 
 	// Error happened during export
 	ExportEventError
+
+	// Something wrong happened during export that is worth notifying to the user
+	// but not severe enough to consider the export a failure.
+	ExportEventWarning
 )
 
 // ExportResult is an event that is emitted during the export process, to
@@ -65,6 +69,11 @@ func (er ExportResult) String() string {
 			return fmt.Sprintf("export error at %s: %s", er.ID, er.Err.Error())
 		}
 		return fmt.Sprintf("export error: %s", er.Err.Error())
+	case ExportEventWarning:
+		if er.ID != "" {
+			return fmt.Sprintf("warning at %s: %s", er.ID, er.Err.Error())
+		}
+		return fmt.Sprintf("warning: %s", er.Err.Error())
 
 	default:
 		panic("unknown export result")
@@ -79,6 +88,14 @@ func NewExportError(err error, id entity.Id) ExportResult {
 	}
 }
 
+func NewExportWarning(err error, id entity.Id) ExportResult {
+	return ExportResult{
+		ID:    id,
+		Err:   err,
+		Event: ExportEventWarning,
+	}
+}
+
 func NewExportNothing(id entity.Id, reason string) ExportResult {
 	return ExportResult{
 		ID:     id,

bridge/core/import.go 🔗

@@ -2,6 +2,7 @@ package core
 
 import (
 	"fmt"
+	"strings"
 
 	"github.com/MichaelMure/git-bug/entity"
 )
@@ -31,6 +32,10 @@ const (
 
 	// Error happened during import
 	ImportEventError
+
+	// Something wrong happened during import that is worth notifying to the user
+	// but not severe enough to consider the import a failure.
+	ImportEventWarning
 )
 
 // ImportResult is an event that is emitted during the import process, to
@@ -69,6 +74,20 @@ func (er ImportResult) String() string {
 			return fmt.Sprintf("import error at id %s: %s", er.ID, er.Err.Error())
 		}
 		return fmt.Sprintf("import error: %s", er.Err.Error())
+	case ImportEventWarning:
+		parts := make([]string, 0, 4)
+		parts = append(parts, "warning:")
+		if er.ID != "" {
+			parts = append(parts, fmt.Sprintf("at id %s", er.ID))
+		}
+		if er.Reason != "" {
+			parts = append(parts, fmt.Sprintf("reason: %s", er.Reason))
+		}
+		if er.Err != nil {
+			parts = append(parts, fmt.Sprintf("err: %s", er.Err))
+		}
+		return strings.Join(parts, " ")
+
 	default:
 		panic("unknown import result")
 	}
@@ -82,6 +101,14 @@ func NewImportError(err error, id entity.Id) ImportResult {
 	}
 }
 
+func NewImportWarning(err error, id entity.Id) ImportResult {
+	return ImportResult{
+		Err:   err,
+		ID:    id,
+		Event: ImportEventWarning,
+	}
+}
+
 func NewImportNothing(id entity.Id, reason string) ImportResult {
 	return ImportResult{
 		ID:     id,

bridge/github/import.go 🔗

@@ -201,6 +201,11 @@ func (gi *githubImporter) ensureIssue(repo *cache.RepoCache, issue issueTimeline
 
 			// other edits will be added as CommentEdit operations
 			target, err := b.ResolveOperationWithMetadata(metaKeyGithubId, parseId(issue.Id))
+			if err == cache.ErrNoMatchingOp {
+				// original comment is missing somehow, issuing a warning
+				gi.out <- core.NewImportWarning(fmt.Errorf("comment ID %s to edit is missing", parseId(issue.Id)), b.Id())
+				continue
+			}
 			if err != nil {
 				return nil, err
 			}

repository/config_git.go 🔗

@@ -66,11 +66,7 @@ func (gc *gitConfig) ReadAll(keyPrefix string) (map[string]string, error) {
 			continue
 		}
 
-		parts := strings.Fields(line)
-		if len(parts) != 2 {
-			return nil, fmt.Errorf("bad git config: %s", line)
-		}
-
+		parts := strings.SplitN(line, " ", 2)
 		result[parts[0]] = parts[1]
 	}