forked from gnolang/blog
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgithub.go
63 lines (52 loc) · 1.74 KB
/
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
package main
import (
"context"
"time"
"github.com/google/go-github/v50/github"
"golang.org/x/oauth2"
)
func initGithubClient() *github.Client {
ts := oauth2.StaticTokenSource(&oauth2.Token{AccessToken: opts.githubToken})
tc := oauth2.NewClient(context.Background(), ts)
client := github.NewClient(tc)
return client
}
func githubFetchIssues(client *github.Client, opts *github.IssueListByRepoOptions, owner string, repository string) ([]*github.Issue, error) {
issues, _, err := client.Issues.ListByRepo(context.Background(), owner, repository, opts)
if err != nil {
return nil, err
}
return issues, nil
}
func githubFetchCommits(client *github.Client, opts *github.CommitsListOptions, owner string, repository string) ([]*github.RepositoryCommit, error) {
commits, _, err := client.Repositories.ListCommits(context.Background(), owner, repository, opts)
if err != nil {
return nil, err
}
return commits, nil
}
func githubFetchPullRequests(client *github.Client, opts *github.PullRequestListOptions, owner string, repository string) ([]*github.PullRequest, error) {
pullRequests, _, err := client.PullRequests.List(context.Background(), owner, repository, opts)
if err != nil {
return nil, err
}
return pullRequests, nil
}
func filterPullRequestByTime(pullRequests []*github.PullRequest, since time.Time) []*github.PullRequest {
var filtered []*github.PullRequest
for _, pullRequest := range pullRequests {
if pullRequest.UpdatedAt.After(since) {
filtered = append(filtered, pullRequest)
}
}
return filtered
}
func filterIssueNotPR(issues []*github.Issue) []*github.Issue {
var filtered []*github.Issue
for _, issue := range issues {
if issue.PullRequestLinks == nil {
filtered = append(filtered, issue)
}
}
return filtered
}