Skip to content

Commit 271bf17

Browse files
author
Your Name
committed
feat: Add GITHUB_API_KEY support for rate limiting
1 parent 5ca86d9 commit 271bf17

File tree

4 files changed

+21
-2
lines changed

4 files changed

+21
-2
lines changed

.github/workflows/generate.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ jobs:
2121

2222
- name: Generate files
2323
run: go run .
24+
env:
25+
GITHUB_API_KEY: ${{ secrets.GITHUB_TOKEN }}
2426

2527
- uses: EndBug/add-and-commit@v9
2628
with:

go.mod

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,7 @@ require (
1010
github.com/shyim/go-version v0.0.0-20250828113848-97ec77491b32
1111
)
1212

13-
require github.com/google/go-querystring v1.1.0 // indirect
13+
require (
14+
github.com/google/go-querystring v1.1.0 // indirect
15+
golang.org/x/oauth2 v0.34.0 // indirect
16+
)

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,6 @@ github.com/google/go-querystring v1.1.0 h1:AnCroh3fv4ZBgVIf1Iwtovgjaw/GiKJo8M8yD
99
github.com/google/go-querystring v1.1.0/go.mod h1:Kcdr2DB4koayq7X8pmAG4sNG59So17icRSOU623lUBU=
1010
github.com/shyim/go-version v0.0.0-20250828113848-97ec77491b32 h1:LEMavffuqxLwefNTQYlTNj/d9yAg5zVPCKvQrtt1/l4=
1111
github.com/shyim/go-version v0.0.0-20250828113848-97ec77491b32/go.mod h1:z47ygE4N7EC0H58FP5j5cXZtl1pSnfjwYJsHtiVtcwU=
12+
golang.org/x/oauth2 v0.34.0 h1:hqK/t4AKgbqWkdkcAeI8XLmbK+4m4G5YeQRrmiotGlw=
13+
golang.org/x/oauth2 v0.34.0/go.mod h1:lzm5WQJQwKZ3nwavOZ3IS5Aulzxi68dUSgRHujetwEA=
1214
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=

main.go

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,25 @@ package main
22

33
import (
44
"context"
5+
"os"
56

67
"github.com/google/go-github/v80/github"
8+
"golang.org/x/oauth2"
79
)
810

911
func main() {
1012
ctx := context.Background()
11-
client := github.NewClient(nil)
13+
var client *github.Client
14+
15+
if token := os.Getenv("GITHUB_API_KEY"); token != "" {
16+
ts := oauth2.StaticTokenSource(
17+
&oauth2.Token{AccessToken: token},
18+
)
19+
tc := oauth2.NewClient(ctx, ts)
20+
client = github.NewClient(tc)
21+
} else {
22+
client = github.NewClient(nil)
23+
}
1224

1325
tags, err := getRepositoryTags(ctx, client)
1426

0 commit comments

Comments
 (0)