-
Notifications
You must be signed in to change notification settings - Fork 0
/
fetcher.go
52 lines (42 loc) · 1.02 KB
/
fetcher.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
package main
import (
"encoding/json"
"io/ioutil"
"log"
"net/http"
"net/url"
)
type IFetcher interface {
fetchIssues(issueID string) []Issue
}
type Fetcher struct {
userEmail string
userToken string
}
func (f Fetcher) fetchIssues(issueID string) []Issue {
templatePreface := " SYM AND issueBlocks "
encodedPreface := url.PathEscape(templatePreface)
// puking emoji face
prefacePreface := "project%20="
queryString := prefacePreface + encodedPreface + "=" + issueID
urlString := "https://bsn.atlassian.net/rest/api/latest/search?jql=" + queryString
client := &http.Client{}
req, err := http.NewRequest("GET", urlString, nil)
req.SetBasicAuth(f.userEmail, f.userToken)
req.Header.Add("Content-Type", "application/json")
if err != nil {
log.Fatal(err)
}
resp, err := client.Do(req)
if err != nil {
log.Fatal(err)
}
bodyText, err := ioutil.ReadAll(resp.Body)
s := string(bodyText)
if err != nil {
log.Fatal(err)
}
var response JiraResponse
json.Unmarshal([]byte(s), &response)
return response.Issues
}