1package core
2
3import (
4 "fmt"
5
6 "github.com/MichaelMure/git-bug/entity"
7)
8
9type ExportEvent int
10
11const (
12 _ ExportEvent = iota
13 ExportEventBug
14 ExportEventComment
15 ExportEventCommentEdition
16 ExportEventStatusChange
17 ExportEventTitleEdition
18 ExportEventLabelChange
19 ExportEventNothing
20)
21
22// ExportResult is an event that is emitted during the export process, to
23// allow calling code to report on what is happening, collect metrics or
24// display meaningful errors if something went wrong.
25type ExportResult struct {
26 Err error
27 Event ExportEvent
28 ID entity.Id
29 Reason string
30}
31
32func (er ExportResult) String() string {
33 switch er.Event {
34 case ExportEventBug:
35 return "new issue"
36 case ExportEventComment:
37 return "new comment"
38 case ExportEventCommentEdition:
39 return "updated comment"
40 case ExportEventStatusChange:
41 return "changed status"
42 case ExportEventTitleEdition:
43 return "changed title"
44 case ExportEventLabelChange:
45 return "changed label"
46 case ExportEventNothing:
47 return fmt.Sprintf("no event: %v", er.Reason)
48 default:
49 panic("unknown export result")
50 }
51}
52
53func NewExportError(err error, id entity.Id) ExportResult {
54 return ExportResult{
55 ID: id,
56 Err: err,
57 }
58}
59
60func NewExportNothing(id entity.Id, reason string) ExportResult {
61 return ExportResult{
62 ID: id,
63 Reason: reason,
64 Event: ExportEventNothing,
65 }
66}
67
68func NewExportBug(id entity.Id) ExportResult {
69 return ExportResult{
70 ID: id,
71 Event: ExportEventBug,
72 }
73}
74
75func NewExportComment(id entity.Id) ExportResult {
76 return ExportResult{
77 ID: id,
78 Event: ExportEventComment,
79 }
80}
81
82func NewExportCommentEdition(id entity.Id) ExportResult {
83 return ExportResult{
84 ID: id,
85 Event: ExportEventCommentEdition,
86 }
87}
88
89func NewExportStatusChange(id entity.Id) ExportResult {
90 return ExportResult{
91 ID: id,
92 Event: ExportEventStatusChange,
93 }
94}
95
96func NewExportLabelChange(id entity.Id) ExportResult {
97 return ExportResult{
98 ID: id,
99 Event: ExportEventLabelChange,
100 }
101}
102
103func NewExportTitleEdition(id entity.Id) ExportResult {
104 return ExportResult{
105 ID: id,
106 Event: ExportEventTitleEdition,
107 }
108}