-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement latest core tag and release fetching with GitHub client
- Loading branch information
Showing
3 changed files
with
65 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package client | ||
|
||
import ( | ||
"context" | ||
"net/http" | ||
|
||
// import for side effect of sql packages | ||
_ "github.com/lib/pq" | ||
|
||
"github.com/google/go-github/v41/github" | ||
"golang.org/x/oauth2" | ||
) | ||
|
||
type GithubClient struct { | ||
client *github.Client | ||
} | ||
|
||
func NewGithubClient(token string) *GithubClient { | ||
// Optional: Authenticate with a personal access token if necessary | ||
// This is recommended to avoid rate limits for unauthenticated requests | ||
var tc *http.Client | ||
if token != "" { | ||
ctx := context.Background() | ||
ts := oauth2.StaticTokenSource( | ||
&oauth2.Token{AccessToken: token}, | ||
) | ||
tc = oauth2.NewClient(ctx, ts) | ||
} | ||
|
||
client := github.NewClient(tc) | ||
|
||
return &GithubClient{ | ||
client: client, | ||
} | ||
} | ||
|
||
func (g *GithubClient) ListLatestCLCoreReleases(count int) ([]*github.RepositoryRelease, error) { | ||
ctx := context.Background() | ||
releases, _, err := g.client.Repositories.ListReleases(ctx, "smartcontractkit", "chainlink", &github.ListOptions{PerPage: count}) | ||
return releases, err | ||
} | ||
|
||
func (g *GithubClient) ListLatestCLCoreTags(count int) ([]*github.RepositoryTag, error) { | ||
ctx := context.Background() | ||
tags, _, err := g.client.Repositories.ListTags(ctx, "smartcontractkit", "chainlink", &github.ListOptions{PerPage: count}) | ||
return tags, err | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters