export.go

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