-
Notifications
You must be signed in to change notification settings - Fork 0
/
case.go
97 lines (84 loc) · 3.29 KB
/
case.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
// Copyright 2015 Craig Nicholson. All rights reserved.
// Use of this source code is governed by the Apache 2.0
// license that can be found in the LICENSE file.
// Package cases implements the interface to the fogbugz api
// to pull cases using the search command. TODO:To extend the data
// pulled add additional columns and remove the custom fields.
// cols:{"sTitle,ixProject,sProject,sArea,sCategory,sFixFor,ixFixFor,
// cols: sStartNote,tags,plugin_customfields_at_fogcreek_com_customere1c"}}
package cases
import (
"encoding/xml"
"fmt"
"io/ioutil"
"net/http"
"net/url"
)
// Response contains the array of intervals.
type Response struct {
XMLName xml.Name `xml:"response"`
Cases Cases
}
// Cases holds the count of cases and the cases.
type Cases struct {
XMLName xml.Name `xml:"cases"`
Count string `xml:"count,attr"`
Case []Case `xml:"case"`
}
// Case holds metadata about a case. Customer is a customer field and
// might need to be removed for other users of this software.
type Case struct {
Bug int `xml:"ixBug,attr"`
Operations string `xml:"operations,attr"`
Title string `xml:"sTitle"`
ProjectID int `xml:"ixProject"`
Project string `xml:"sProject"`
Area string `xml:"sArea"`
FixFor string `xml:"sFixFor"`
FixForID int `xml:"ixFixFor"`
StartNote string `xml:"sStartNote"`
Category string `xml:"sCategory"`
Customer string `xml:"plugin_customfields_at_fogcreek_com_customere1c"`
Tags Tags
}
// Tags holds all the tags assigned to a case.
type Tags struct {
XMLName xml.Name `xml:"tags"`
Tag []string `xml:"tag"`
}
// ListCases takes in a comma seperated list of strings and returns a list
// of cases, cases can be comma separated list of case numbers without spaces.
// Using a map allows us to search to find the Bug/Case by the ixBug
// For example, interval.go has a reference only to ixBug.
// https://company.fogbugz.com/api.asp?token=csjm9ljou4q4fkc3tgepgm2nm0vmfk&cmd=search&q=7880&cols=tags,sTitle,ixProject,sProject,sArea,sCategory,sFixFor,ixFixFor,sStartNote,plugin_customfields_at_fogcreek_com_customere1c,plugin_customfields_at_fogcreek_com_taskxordert0e
// Notes: The query term you are searching for can be a string, a case number, a
// comma separated list of case numbers without spaces, e.g. 12,25,556.
// The last cols in the list of values are a custom fields, these might need
// to be removed for other users.
func ListCases(token string, root *url.URL, casescsv string) map[int]Case {
v := url.Values{"token": {token}, "cmd": {"search"}, "q": {casescsv}, "cols": {"sTitle,ixProject,sProject,sArea,sCategory,sFixFor,ixFixFor,sStartNote,tags,plugin_customfields_at_fogcreek_com_customere1c"}}
resp, err := http.PostForm(root.String(), v)
if err != nil {
fmt.Println(err)
}
// Read the response into the data { []byte }.
defer resp.Body.Close()
data, err2 := ioutil.ReadAll(resp.Body)
if err2 != nil {
fmt.Println(err2)
}
// Load the xml data we collected into the object.
r := &Response{}
err3 := xml.Unmarshal(data, r)
if err3 != nil {
fmt.Println(err3)
}
// Create a map of cases to perform lookups
// using the BugIDs in interval.go package.
// Bug (ixBug) is the key in this map.
c := make(map[int]Case)
for i := 0; i < len(r.Cases.Case); i++ {
c[r.Cases.Case[i].Bug] = r.Cases.Case[i]
}
return c
}