/
repos.go
60 lines (49 loc) · 1.18 KB
/
repos.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
package client
import (
"encoding/json"
"fmt"
"net/http"
"net/url"
"strconv"
"github.com/pkg/errors"
)
// Repository is a repository.
type Repository struct {
Name string
}
// HandlerRepo is a handler for repos.
type HandlerRepo struct {
httpClient *HTTPClient
}
// GetOrgRepoParams is parameters for GetOrgRepos.
type GetOrgRepoParams struct {
PerPage int
Page int
}
// NewHandlerRepo creates a handler.
func NewHandlerRepo(httpClient *HTTPClient) *HandlerRepo {
return &HandlerRepo{
httpClient: httpClient,
}
}
// GetOrgsRepos get organization repositories.
func (hr *HandlerRepo) GetOrgRepos(org string, params GetOrgRepoParams) ([]*Repository, error) {
url := &url.URL{}
query := url.Query()
query.Add("per_page", strconv.Itoa(params.PerPage))
query.Add("page", strconv.Itoa(params.Page))
// TODO:
req, err := hr.httpClient.NewRequest(http.MethodGet, nil, nil, fmt.Sprintf("orgs/%v/repos?%v", org, query.Encode()))
if err != nil {
return nil, errors.WithStack(err)
}
body, err := hr.httpClient.Do(req)
if err != nil {
return nil, errors.WithStack(err)
}
var r []*Repository
if err := json.Unmarshal(body, &r); err != nil {
return nil, err
}
return r, nil
}