Removes ticket duplicates
This commit is contained in:
parent
e12f6087af
commit
2360320cf6
2 changed files with 19 additions and 0 deletions
|
@ -116,6 +116,7 @@ func addCmdF(cmd *cobra.Command, _ []string) {
|
||||||
|
|
||||||
// ToDo: make this skip duplicates
|
// ToDo: make this skip duplicates
|
||||||
cmp.Tickets = append(cmp.Tickets, tickets...)
|
cmp.Tickets = append(cmp.Tickets, tickets...)
|
||||||
|
cmp.Tickets = model.RemoveDuplicateTickets(cmp.Tickets)
|
||||||
|
|
||||||
if err := campaign.Save(cmp); err != nil {
|
if err := campaign.Save(cmp); err != nil {
|
||||||
ErrorAndExit(cmd, err)
|
ErrorAndExit(cmd, err)
|
||||||
|
|
|
@ -1,7 +1,25 @@
|
||||||
package model
|
package model
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
)
|
||||||
|
|
||||||
type Ticket struct {
|
type Ticket struct {
|
||||||
Filename string `json:"filename"`
|
Filename string `json:"filename"`
|
||||||
LineNo int `json:"line_no"`
|
LineNo int `json:"line_no"`
|
||||||
Text string `json:"text"` // needed??
|
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
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue