-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbug.go
95 lines (87 loc) · 1.93 KB
/
bug.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
package model
import (
"bytes"
"fmt"
"strings"
"sync"
"time"
"github.com/PuerkitoBio/goquery"
)
// Bug mysql bug information
type Bug struct {
ID int
URL string
Title string
SubmitTime time.Time
ModifiedTime time.Time
Reporter string
Status string
Category string
Version []string
Tags []string
Triage string
Severity string
OS string
CPUArch []string
}
const bugAPITemplate = "https://bugs.mysql.com/bug.php?id=%d"
const timeFMT = "2 Jan 2006 15:04"
// New prepare a new bug struct
func (bug *Bug) New(id int) *Bug {
bug.ID = id
bug.URL = fmt.Sprintf(bugAPITemplate, id)
return bug
}
// Analysis prepare a new bug struct
func (bug *Bug) Analysis(wg *sync.WaitGroup) *Bug {
wg.Add(1)
go func() {
defer wg.Done()
res, err := HTTPGetWithCache(bug.URL, CacheDir)
if err != nil {
Logger.Println("bug analysis get url: ", bug.URL, err)
return
}
doc, err := goquery.NewDocumentFromReader(bytes.NewReader(res))
if doc == nil {
Logger.Println("goquery.NewDocumentFromReader Error: ", err)
return
}
doc.Find("#bugheader").Find("td").Each(func(i int, selection *goquery.Selection) {
value := compressStr(strings.TrimSpace(selection.Text()))
switch i {
case 0:
bug.Title = value
case 1:
subTime, _ := time.Parse(timeFMT, value)
bug.SubmitTime = subTime
case 2:
mTime, _ := time.Parse(timeFMT, value)
bug.ModifiedTime = mTime
case 3:
bug.Reporter = value
case 5:
bug.Status = value
case 7:
bug.Category = value
case 8:
bug.Severity = value
case 9:
bug.Version = strings.Split(value, ",")
case 10:
bug.OS = value
case 12:
bug.CPUArch = strings.Split(value, ",")
case 13:
if strings.Index(value, "Triage") >= 0 {
bug.Triage = value
break
}
bug.Tags = strings.Split(value, ",")
case 14:
bug.Triage = value
}
})
}()
return bug
}