-
Notifications
You must be signed in to change notification settings - Fork 2
/
github.go
44 lines (35 loc) · 951 Bytes
/
github.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
package service
import (
"encoding/json"
"time"
"github.com/abgeo/mailtm/pkg/dto"
"github.com/abgeo/mailtm/pkg/errors"
"github.com/abgeo/mailtm/pkg/types"
"github.com/go-resty/resty/v2"
)
type GitHubService struct {
client *resty.Client
}
func NewGitHubService() *GitHubService {
const timeout = 30 * time.Second
client := resty.New()
client.SetBaseURL("https://api.github.com/").
SetTimeout(timeout).
SetHeader("Accept", "application/vnd.github+json").
SetError(&errors.HTTPError{})
client.JSONMarshal = json.Marshal
client.JSONUnmarshal = json.Unmarshal
return &GitHubService{
client: client,
}
}
func (svc *GitHubService) GetLatestRelease(owner, repo string) (release *dto.Release, err error) {
_, err = svc.client.R().
SetPathParams(types.StrMap{"owner": owner, "repo": repo}).
SetResult(&release).
Get("/repos/{owner}/{repo}/releases/latest")
if err != nil {
return release, err
}
return release, nil
}