-
Notifications
You must be signed in to change notification settings - Fork 1
/
teamcityparser.go
69 lines (58 loc) · 1.53 KB
/
teamcityparser.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
package goteamcity
import(
"encoding/json"
"io"
"log"
"strings"
)
const Success string = "Success"
const Fail string = "Fail"
const Investigating string = "Investigating"
type project struct {
Name string
WebUrl string
LastBuildTime string
LastBuildLabel string
LastBuildStatus string
}
type teamcityResponse struct {
Project []project
}
var investigationsPath string = "/httpAuth/app/rest/investigations?locator=buildType:(name:%s)"
func parseResponse(response io.ReadCloser, r investigationReader) string {
decoder := json.NewDecoder(response)
teamCityStatus := teamcityResponse{}
err := decoder.Decode(&teamCityStatus)
if err != nil {
log.Fatalf("Error: %s", err)
}
projectCount := len(teamCityStatus.Project)
successCount := 0
failureCount := 0
investigateCount := 0
for i := 0; i < projectCount; i++ {
buildStatus := teamCityStatus.Project[i].LastBuildStatus
if buildStatus == "Success" {
successCount++
} else if buildStatus == "Failure" {
name := parseName(teamCityStatus.Project[i].Name)
if r.IsInvestigating(name) {
investigateCount++
}
failureCount++
}
}
if successCount > 0 && failureCount == 0 {
return Success
} else if failureCount == investigateCount {
return Investigating
}
return Fail
}
func parseName(name string) string {
pos := strings.LastIndex(name, "::")
if pos < 0 {
return name
}
return strings.Trim(name[pos + 2:len(name)], " ")
}