This repository has been archived by the owner on Sep 2, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
jira.go
79 lines (62 loc) · 1.85 KB
/
jira.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
package main
import (
"encoding/json"
"fmt"
"strings"
)
var jiraVersionsCache []string
//Set the initial jira versions in the cache
func populateInitialJiraVersions() error {
versions, err := getJiraVersions()
if err != nil {
return err
}
for _, version := range versions {
jiraVersionsCache = append(jiraVersionsCache, version.Name)
}
fmt.Printf("Loaded %d initial jira versions\n", len(jiraVersionsCache))
return nil
}
func jiraUpdateCheck(callback func(message string) error) error {
currentVersions, err := getJiraVersions()
if err != nil {
return err
}
for _, version := range currentVersions {
if !contains(jiraVersionsCache, version.Name) {
jiraVersionsCache = append(jiraVersionsCache, version.Name)
if !strings.Contains(version.Name, "Future Version") {
err = callback(jiraAsString(version))
if err != nil {
return err
}
}
}
}
return nil
}
func jiraAsString(version JiraVersion) string {
return fmt.Sprintf("A new version (%s) has been added to the minecraft issue tracker!", version.Name)
}
func getJiraVersions() ([]JiraVersion, error) {
jsonStr, err := getJson("https://bugs.mojang.com/rest/api/latest/project/MC/versions")
if err != nil {
return nil, err
}
var versions []JiraVersion
err = json.Unmarshal([]byte(jsonStr), &versions)
return versions, err
}
type JiraVersion struct {
Self string `json:"self"`
ID string `json:"id"`
Description string `json:"description,omitempty"`
Name string `json:"name"`
Archived bool `json:"archived"`
Released bool `json:"released"`
ReleaseDate string `json:"releaseDate,omitempty"`
UserReleaseDate string `json:"userReleaseDate,omitempty"`
ProjectID int `json:"projectId"`
StartDate string `json:"startDate,omitempty"`
UserStartDate string `json:"userStartDate,omitempty"`
}