-
Notifications
You must be signed in to change notification settings - Fork 0
/
get.go
104 lines (95 loc) · 2.28 KB
/
get.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
96
97
98
99
100
101
102
103
104
package kw
import (
"bytes"
"encoding/json"
"fmt"
"io"
"log"
)
//Internal function to get a list of project names
// Input: Web API JSONResponse []byte
// Output: List of project names []string
func getProjects(aJSONResponse []byte, aType string) []string {
var result []string
dec := json.NewDecoder(bytes.NewReader(aJSONResponse))
for {
//Some variables we will need
var res Result
var err error
switch aType {
case "projects":
var doc Project
err = dec.Decode(&doc)
res = &doc
case "builds":
var doc Build
err = dec.Decode(&doc)
res = &doc
default:
log.Fatal("No implementation for JSON processing of type: " + aType + ". Exiting.")
}
//err := dec.Decode(&doc)
if err == io.EOF {
//fmt.Printf("EOF")
break
}
if err != nil {
log.Fatal(err)
}
if res != nil {
//fmt.Println(res.GetName())
result = append(result, res.GetName())
} else {
fmt.Println("WARNING: res is nil - error in JSON decoding loop?")
break
}
}
return result
}
func getBuilds(projectNames []string) {
for _, projectName := range projectNames {
data, klocworkURL := formBaseRequest("builds")
//data.Set("action", "builds")
data.Set("project", projectName)
fmt.Println("Retrieving builds for project " + projectName)
//Send it
_, body := sendRequest(klocworkURL, data)
buildNames := getProjects(body, "builds")
fmt.Println("Project: " + projectName)
fmt.Println("Builds: ")
for _, buildName := range buildNames {
fmt.Println(buildName)
}
}
return
}
/*
Implements:
search
Retrieve the list of detected issues.
Example: curl --data "action=search&user=myself&project=my_project&query=file:MyFile.c" http://127.0.0.1:8090/review/api
project*
project name
query
search query, such as narrowing by file (for example, 'file:MyFile.c')
view
view name
limit
search result limit
summary
include summary record to output stream
*/
func getIssues(args []string) {
data, klocworkURL := formBaseRequest("search")
project := args[0]
data.Set("project", project)
if len(args) > 1 {
query := args[1]
data.Set("query", query)
fmt.Println("Retrieving issues for project " + project + " matching search query " + data.Get("query"))
} else {
fmt.Println("Retrieving all issues for project " + project)
}
//Send it
sendRequest(klocworkURL, data)
}