Removes ticket duplicates

This commit is contained in:
Miguel de la Cruz 2020-02-29 14:17:34 +01:00
parent e12f6087af
commit 2360320cf6
2 changed files with 19 additions and 0 deletions

View file

@ -116,6 +116,7 @@ func addCmdF(cmd *cobra.Command, _ []string) {
// ToDo: make this skip duplicates
cmp.Tickets = append(cmp.Tickets, tickets...)
cmp.Tickets = model.RemoveDuplicateTickets(cmp.Tickets)
if err := campaign.Save(cmp); err != nil {
ErrorAndExit(cmd, err)

View file

@ -1,7 +1,25 @@
package model
import (
"fmt"
)
type Ticket struct {
Filename string `json:"filename"`
LineNo int `json:"line_no"`
Text string `json:"text"` // needed??
}
func RemoveDuplicateTickets(tickets []*Ticket) []*Ticket {
ticketMap := map[string]*Ticket{}
for _, t := range tickets {
ticketMap[fmt.Sprintf("%s:%d", t.Filename, t.LineNo)] = t
}
cleanTickets := []*Ticket{}
for _, t := range ticketMap {
cleanTickets = append(cleanTickets, t)
}
return cleanTickets
}