2020-02-29 01:20:46 +01:00
|
|
|
package model
|
|
|
|
|
2020-02-29 14:17:34 +01:00
|
|
|
import (
|
|
|
|
"fmt"
|
2020-03-06 19:54:52 +01:00
|
|
|
"io"
|
2020-02-29 14:17:34 +01:00
|
|
|
)
|
|
|
|
|
2020-03-04 23:07:26 +01:00
|
|
|
type Ticket struct {
|
2020-04-27 11:42:29 +02:00
|
|
|
GithubLink int64 `json:"github_link,omitempty"`
|
|
|
|
GithubStatus string `json:"github_status,omitempty"`
|
|
|
|
JiraLink string `json:"jira_link,omitempty"`
|
|
|
|
JiraStatus string `json:"jira_status,omitempty"`
|
|
|
|
Summary string `json:"summary,omitempty"`
|
|
|
|
Description string `json:"description,omitempty"`
|
|
|
|
Data map[string]interface{} `json:"data,omitempty"`
|
2020-03-04 23:07:26 +01:00
|
|
|
}
|
2020-02-29 14:17:34 +01:00
|
|
|
|
2020-03-01 13:21:10 +01:00
|
|
|
func RemoveDuplicateTickets(tickets []*Ticket, fileOnly bool) []*Ticket {
|
2020-02-29 14:17:34 +01:00
|
|
|
ticketMap := map[string]*Ticket{}
|
|
|
|
for _, t := range tickets {
|
2020-03-04 23:07:26 +01:00
|
|
|
filename, _ := t.Data["filename"].(string)
|
|
|
|
lineNo, _ := t.Data["lineNo"].(int)
|
2020-03-01 13:21:10 +01:00
|
|
|
if fileOnly {
|
2020-03-04 21:57:16 +01:00
|
|
|
ticketMap[filename] = t
|
2020-03-01 13:21:10 +01:00
|
|
|
} else {
|
2020-03-04 21:57:16 +01:00
|
|
|
ticketMap[fmt.Sprintf("%s:%d", filename, lineNo)] = t
|
2020-03-01 13:21:10 +01:00
|
|
|
}
|
2020-02-29 14:17:34 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
cleanTickets := []*Ticket{}
|
|
|
|
for _, t := range ticketMap {
|
|
|
|
cleanTickets = append(cleanTickets, t)
|
|
|
|
}
|
|
|
|
|
|
|
|
return cleanTickets
|
|
|
|
}
|
2020-03-06 19:54:52 +01:00
|
|
|
|
|
|
|
func (t *Ticket) PrintStatus(w io.Writer) {
|
2020-04-27 11:42:29 +02:00
|
|
|
if t.Summary != "" {
|
|
|
|
fmt.Fprintf(w, "[%s] %s\n", t.JiraLink, t.Summary)
|
|
|
|
}
|
2020-03-06 19:54:52 +01:00
|
|
|
}
|