-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathquery.go
More file actions
61 lines (51 loc) · 1.65 KB
/
Copy pathquery.go
File metadata and controls
61 lines (51 loc) · 1.65 KB
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
package gorgojo
// Query to Bugzilla on various attributes. It is chainable,
// so you can do:
// query := client.Query().Summary("crashed").AssignedTo("john")
type Query struct {
Client *Client
QueryMap map[string][]interface{}
}
func NewQuery(client *Client) *Query {
return &Query{Client: client, QueryMap: make(map[string][]interface{})}
}
func (q *Query) appendQuery(key string, value interface{}) *Query {
// key does not already exists
if _, ok := q.QueryMap[key]; !ok {
q.QueryMap[key] = make([]interface{}, 0)
}
q.QueryMap[key] = append(q.QueryMap[key], value)
return q
}
// arbitrary field name
func (q *Query) Field(key string, value interface{}) *Query {
return q.appendQuery(key, value)
}
// The login name of a user that a bug is assigned to.
func (q *Query) AssignedTo(who string) *Query {
return q.appendQuery("assigned_to", who)
}
// Searches for substrings in the single-line Summary field on bugs.
// If you specify an array, then bugs whose summaries match any of the passed
// substrings will be returned.
func (q *Query) Summary(what string) *Query {
return q.appendQuery("summary", what)
}
// The current status of a bug (not including its resolution,
// if it has one, which is a separate field above).
func (q *Query) Status(status string) *Query {
return q.appendQuery("status", status)
}
// Shortcut for all statuses that keep the bug "open"
func (q *Query) Open() *Query {
return q.Status("unconfirmed").Status("new").
Status("confirmed").Status("in_progress").
Status("reopened")
}
// L3 bugs
func (q *Query) L3() *Query {
return q.Summary("L3")
}
func (q *Query) Result() ([]Bug, error) {
return q.Client.Search(q.QueryMap)
}