2019-06-25 02:33:48 +03:00
|
|
|
package core
|
|
|
|
|
2019-08-12 17:12:14 +03:00
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
|
|
|
|
"github.com/MichaelMure/git-bug/entity"
|
|
|
|
)
|
2019-06-25 02:33:48 +03:00
|
|
|
|
2019-07-05 21:55:24 +03:00
|
|
|
type ExportEvent int
|
2019-06-25 02:33:48 +03:00
|
|
|
|
|
|
|
const (
|
2019-07-05 21:55:24 +03:00
|
|
|
_ ExportEvent = iota
|
2019-11-19 21:03:38 +03:00
|
|
|
|
|
|
|
// Bug has been exported on the remote tracker
|
2019-07-05 21:55:24 +03:00
|
|
|
ExportEventBug
|
2019-11-19 21:03:38 +03:00
|
|
|
// Comment has been exported on the remote tracker
|
2019-07-05 21:55:24 +03:00
|
|
|
ExportEventComment
|
2019-11-19 21:03:38 +03:00
|
|
|
// Comment has been edited on the remote tracker
|
2019-07-05 21:55:24 +03:00
|
|
|
ExportEventCommentEdition
|
2019-11-19 21:03:38 +03:00
|
|
|
// Bug's status has been changed on on the remote tracker
|
2019-07-05 21:55:24 +03:00
|
|
|
ExportEventStatusChange
|
2019-11-19 21:03:38 +03:00
|
|
|
// Bug's title has been changed on the remote tracker
|
2019-07-05 21:55:24 +03:00
|
|
|
ExportEventTitleEdition
|
2019-11-19 21:03:38 +03:00
|
|
|
// Bug's labels have been changed on the remote tracker
|
2019-07-05 21:55:24 +03:00
|
|
|
ExportEventLabelChange
|
2019-11-19 21:03:38 +03:00
|
|
|
|
|
|
|
// Nothing changed on the bug
|
2019-07-05 21:55:24 +03:00
|
|
|
ExportEventNothing
|
2019-11-19 21:03:38 +03:00
|
|
|
|
|
|
|
// Error happened during export
|
2019-08-13 20:51:14 +03:00
|
|
|
ExportEventError
|
2019-06-25 02:33:48 +03:00
|
|
|
)
|
|
|
|
|
2019-07-07 13:15:01 +03:00
|
|
|
// ExportResult is an event that is emitted during the export process, to
|
|
|
|
// allow calling code to report on what is happening, collect metrics or
|
|
|
|
// display meaningful errors if something went wrong.
|
2019-06-25 02:33:48 +03:00
|
|
|
type ExportResult struct {
|
|
|
|
Err error
|
2019-07-05 21:55:24 +03:00
|
|
|
Event ExportEvent
|
2019-08-12 17:12:14 +03:00
|
|
|
ID entity.Id
|
2019-06-25 02:33:48 +03:00
|
|
|
Reason string
|
|
|
|
}
|
|
|
|
|
|
|
|
func (er ExportResult) String() string {
|
|
|
|
switch er.Event {
|
2019-07-05 21:55:24 +03:00
|
|
|
case ExportEventBug:
|
2019-08-13 20:51:14 +03:00
|
|
|
return fmt.Sprintf("new issue: %s", er.ID)
|
2019-07-05 21:55:24 +03:00
|
|
|
case ExportEventComment:
|
2019-08-13 20:51:14 +03:00
|
|
|
return fmt.Sprintf("new comment: %s", er.ID)
|
2019-07-05 21:55:24 +03:00
|
|
|
case ExportEventCommentEdition:
|
2019-08-13 20:51:14 +03:00
|
|
|
return fmt.Sprintf("updated comment: %s", er.ID)
|
2019-07-05 21:55:24 +03:00
|
|
|
case ExportEventStatusChange:
|
2019-08-13 20:51:14 +03:00
|
|
|
return fmt.Sprintf("changed status: %s", er.ID)
|
2019-07-05 21:55:24 +03:00
|
|
|
case ExportEventTitleEdition:
|
2019-08-13 20:51:14 +03:00
|
|
|
return fmt.Sprintf("changed title: %s", er.ID)
|
2019-07-05 21:55:24 +03:00
|
|
|
case ExportEventLabelChange:
|
2019-08-13 20:51:14 +03:00
|
|
|
return fmt.Sprintf("changed label: %s", er.ID)
|
2019-07-05 21:55:24 +03:00
|
|
|
case ExportEventNothing:
|
2019-08-13 20:51:14 +03:00
|
|
|
if er.ID != "" {
|
2019-08-18 00:46:10 +03:00
|
|
|
return fmt.Sprintf("no actions taken for event %s: %s", er.ID, er.Reason)
|
2019-08-13 20:51:14 +03:00
|
|
|
}
|
2019-08-18 00:46:10 +03:00
|
|
|
return fmt.Sprintf("no actions taken: %s", er.Reason)
|
2019-08-13 20:51:14 +03:00
|
|
|
case ExportEventError:
|
|
|
|
if er.ID != "" {
|
|
|
|
return fmt.Sprintf("export error at %s: %s", er.ID, er.Err.Error())
|
|
|
|
}
|
|
|
|
return fmt.Sprintf("export error: %s", er.Err.Error())
|
|
|
|
|
2019-06-25 02:33:48 +03:00
|
|
|
default:
|
|
|
|
panic("unknown export result")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-08-12 17:12:14 +03:00
|
|
|
func NewExportError(err error, id entity.Id) ExportResult {
|
2019-06-25 02:33:48 +03:00
|
|
|
return ExportResult{
|
2019-08-19 15:09:31 +03:00
|
|
|
ID: id,
|
|
|
|
Err: err,
|
|
|
|
Event: ExportEventError,
|
2019-06-25 02:33:48 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-08-12 17:12:14 +03:00
|
|
|
func NewExportNothing(id entity.Id, reason string) ExportResult {
|
2019-06-25 02:33:48 +03:00
|
|
|
return ExportResult{
|
|
|
|
ID: id,
|
|
|
|
Reason: reason,
|
2019-07-05 21:55:24 +03:00
|
|
|
Event: ExportEventNothing,
|
2019-06-25 02:33:48 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-08-12 17:12:14 +03:00
|
|
|
func NewExportBug(id entity.Id) ExportResult {
|
2019-06-25 02:33:48 +03:00
|
|
|
return ExportResult{
|
|
|
|
ID: id,
|
2019-07-05 21:55:24 +03:00
|
|
|
Event: ExportEventBug,
|
2019-06-25 02:33:48 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-08-12 17:12:14 +03:00
|
|
|
func NewExportComment(id entity.Id) ExportResult {
|
2019-06-25 02:33:48 +03:00
|
|
|
return ExportResult{
|
|
|
|
ID: id,
|
2019-07-05 21:55:24 +03:00
|
|
|
Event: ExportEventComment,
|
2019-06-25 02:33:48 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-08-12 17:12:14 +03:00
|
|
|
func NewExportCommentEdition(id entity.Id) ExportResult {
|
2019-06-25 02:33:48 +03:00
|
|
|
return ExportResult{
|
|
|
|
ID: id,
|
2019-07-05 21:55:24 +03:00
|
|
|
Event: ExportEventCommentEdition,
|
2019-06-25 02:33:48 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-08-12 17:12:14 +03:00
|
|
|
func NewExportStatusChange(id entity.Id) ExportResult {
|
2019-06-25 02:33:48 +03:00
|
|
|
return ExportResult{
|
|
|
|
ID: id,
|
2019-07-05 21:55:24 +03:00
|
|
|
Event: ExportEventStatusChange,
|
2019-06-25 02:33:48 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-08-12 17:12:14 +03:00
|
|
|
func NewExportLabelChange(id entity.Id) ExportResult {
|
2019-06-25 02:33:48 +03:00
|
|
|
return ExportResult{
|
|
|
|
ID: id,
|
2019-07-05 21:55:24 +03:00
|
|
|
Event: ExportEventLabelChange,
|
2019-06-25 02:33:48 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-08-12 17:12:14 +03:00
|
|
|
func NewExportTitleEdition(id entity.Id) ExportResult {
|
2019-06-25 02:33:48 +03:00
|
|
|
return ExportResult{
|
|
|
|
ID: id,
|
2019-07-05 21:55:24 +03:00
|
|
|
Event: ExportEventTitleEdition,
|
2019-06-25 02:33:48 +03:00
|
|
|
}
|
|
|
|
}
|