/
jaggr.go
55 lines (42 loc) · 1.23 KB
/
jaggr.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
package models
import (
"encoding/json"
"fmt"
"github.com/Noah-Huppert/jira-to-github/hash"
"github.com/fatih/structs"
)
// JiraAggregateStore indicates the store name to save JiraAggregates into
const JiraAggregateStore string = "jira_aggregates"
// JiraAggregateStoreKey is the key Jira Aggregates will always be stored under
const JiraAggregateStoreKey string = "main"
// JiraAggregate provides an overview of all the retrieved Jira models
type JiraAggregate struct {
// Issues holds the JiraIssuesAggregate
Issues *JiraIssuesAggregate
// aggregated indicates if the data has been populated
aggregated bool
}
// NewJiraAggregate creates a new JiraAggregate
func NewJiraAggregate() *JiraAggregate {
// Issues
issues := NewJiraIssuesAggregate()
return &JiraAggregate{
Issues: issues,
aggregated: false,
}
}
func (a JiraAggregate) String() string {
return fmt.Sprintf("Issues: {%s}\n"+
"aggregated: %t",
a.Issues, a.aggregated)
}
// Hash implements hash.Hashable.Hash
func (a JiraAggregate) Hash() string {
return hash.HashStr(a.String())
}
// MarshalJSON implements json.Marshaler.MarshalJSON
func (a JiraAggregate) MarshalJSON() ([]byte, error) {
m := structs.Map(a)
m["hash"] = a.Hash()
return json.Marshal(m)
}