-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgithub.go
More file actions
55 lines (48 loc) · 1.84 KB
/
github.go
File metadata and controls
55 lines (48 loc) · 1.84 KB
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
package github
import (
"context"
"fmt"
"github.com/google/go-github/v86/github"
)
// CreateGitHubRepository creates a new GitHub repository
func CreateGitHubRepository(ctx context.Context, client *github.Client, owner, name string) (*github.Repository, *github.Response, error) {
repo := &github.Repository{
Name: github.Ptr(name),
Private: github.Ptr(true),
}
repo, res, err := client.Repositories.Create(ctx, owner, repo)
if err != nil {
return nil, nil, err
}
return repo, res, nil
}
// gets a release from GitHub by tag
func GetReleaseByTag(ctx context.Context, client *github.Client, owner, repo, tag string) (*github.RepositoryRelease, *github.Response, error) {
release, res, err := client.Repositories.GetReleaseByTag(ctx, owner, repo, tag)
if err != nil {
return nil, nil, fmt.Errorf(`getting release tagged %q: %w`, tag, err)
}
return release, res, nil
}
// gets the latest release from GitHub
func GetLatestRelease(ctx context.Context, client *github.Client, owner, repo string) (*github.RepositoryRelease, *github.Response, error) {
release, res, err := client.Repositories.GetLatestRelease(ctx, owner, repo)
if err != nil {
return nil, nil, fmt.Errorf("getting latest release: %w", err)
}
return release, res, nil
}
// get a release by tag or get latest release
func GetReleaseByTagOrLatest(ctx context.Context, client *github.Client, owner, repo, tag string) (*github.RepositoryRelease, *github.Response, error) {
if tag == "" {
return GetLatestRelease(ctx, client, owner, repo)
}
return GetReleaseByTag(ctx, client, owner, repo, tag)
}
func GetOrganizationTeams(ctx context.Context, client *github.Client, org string) ([]*github.Team, *github.Response, error) {
teams, res, err := client.Teams.ListTeams(ctx, org, nil)
if err != nil {
return nil, nil, fmt.Errorf("getting teams: %w", err)
}
return teams, res, nil
}