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

Github import error
This commit is contained in:
Michael Muré 2020-01-07 19:05:45 +01:00 committed by GitHub
commit ead3fdd074
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 51 additions and 6 deletions

View File

@ -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 // relay all events while checking that everything went well
for event := range events { for event := range events {
if event.Err != nil { if event.Event == ImportEventError {
noError = false noError = false
} }
out <- event out <- event

View File

@ -29,6 +29,10 @@ const (
// Error happened during export // Error happened during export
ExportEventError 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 // 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 at %s: %s", er.ID, er.Err.Error())
} }
return fmt.Sprintf("export error: %s", 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: default:
panic("unknown export result") 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 { func NewExportNothing(id entity.Id, reason string) ExportResult {
return ExportResult{ return ExportResult{
ID: id, ID: id,

View File

@ -2,6 +2,7 @@ package core
import ( import (
"fmt" "fmt"
"strings"
"github.com/MichaelMure/git-bug/entity" "github.com/MichaelMure/git-bug/entity"
) )
@ -31,6 +32,10 @@ const (
// Error happened during import // Error happened during import
ImportEventError 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 // 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 at id %s: %s", er.ID, er.Err.Error())
} }
return fmt.Sprintf("import error: %s", 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: default:
panic("unknown import result") 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 { func NewImportNothing(id entity.Id, reason string) ImportResult {
return ImportResult{ return ImportResult{
ID: id, ID: id,

View File

@ -201,6 +201,11 @@ func (gi *githubImporter) ensureIssue(repo *cache.RepoCache, issue issueTimeline
// other edits will be added as CommentEdit operations // other edits will be added as CommentEdit operations
target, err := b.ResolveOperationWithMetadata(metaKeyGithubId, parseId(issue.Id)) 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 { if err != nil {
return nil, err return nil, err
} }

View File

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