/
repo.go
44 lines (34 loc) · 1.04 KB
/
repo.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 libgh
import (
"context"
"fmt"
"github.com/google/go-github/github"
)
// GetRepositoryRequest are the parameters for a get repository GitHub API request
type GetRepositoryRequest struct {
// ctx is context
ctx context.Context
// client is a GitHub API client
client *github.Client
// owner is the name of the GitHub user who owns the repository
owner string
// name is the GitHub repository to retrieve information about
name string
}
// NewGetRepositoryRequest creates a new GetRepositoryRequest
func NewGetRepositoryRequest(ctx context.Context, client *github.Client, owner, name string) GetRepositoryRequest {
return GetRepositoryRequest{
ctx: ctx,
client: client,
owner: owner,
name: name,
}
}
// GetRepository makes a get repository GitHub API request
func (r GetRepositoryRequest) Do() (*github.Repository, error) {
repo, _, err := r.client.Repositories.Get(r.ctx, r.owner, r.name)
if err != nil {
return nil, fmt.Errorf("error making get repository GitHub API request: %s", err.Error())
}
return repo, nil
}