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