From e29b66f3535297fcf1704568e337f0957d2ac0f4 Mon Sep 17 00:00:00 2001 From: Shinji Nakamatsu <19329+snaka@users.noreply.github.com> Date: Fri, 20 Sep 2024 17:21:37 +0900 Subject: [PATCH 1/3] Add ratelimit --- github.go | 7 ++++++- go.mod | 1 + go.sum | 2 ++ 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/github.go b/github.go index 8f3fdd4..e287748 100644 --- a/github.go +++ b/github.go @@ -6,6 +6,7 @@ import ( "net/url" "github.com/Songmu/gitconfig" + "github.com/gofri/go-github-ratelimit/github_ratelimit" "github.com/google/go-github/v57/github" "golang.org/x/oauth2" ) @@ -20,7 +21,11 @@ func ghClient(ctx context.Context, token, host string) (*github.Client, error) { } ts := oauth2.StaticTokenSource(&oauth2.Token{AccessToken: token}) oauthClient := oauth2.NewClient(ctx, ts) - client := github.NewClient(oauthClient) + rateLimiter, err := github_ratelimit.NewRateLimitWaiterClient(oauthClient.Transport) + if err != nil { + return nil, err + } + client := github.NewClient(rateLimiter) if host != "" && host != "github.com" { // ref. https://github.com/google/go-github/issues/958 diff --git a/go.mod b/go.mod index 2a62ea9..c244767 100644 --- a/go.mod +++ b/go.mod @@ -7,6 +7,7 @@ require ( github.com/Songmu/gh2changelog v0.0.5 github.com/Songmu/gitconfig v0.2.0 github.com/Songmu/gitsemvers v0.0.3 + github.com/gofri/go-github-ratelimit v1.1.0 github.com/google/go-github/v57 v57.0.0 github.com/saracen/walker v0.1.3 golang.org/x/oauth2 v0.15.0 diff --git a/go.sum b/go.sum index 8b82def..2f99902 100644 --- a/go.sum +++ b/go.sum @@ -34,6 +34,8 @@ github.com/go-playground/validator/v10 v10.4.1/go.mod h1:nlOn6nFhuKACm19sB/8EGNn github.com/goccy/go-yaml v1.9.5/go.mod h1:U/jl18uSupI5rdI2jmuCswEA2htH9eXfferR3KfscvA= github.com/goccy/go-yaml v1.11.2 h1:joq77SxuyIs9zzxEjgyLBugMQ9NEgTWxXfz2wVqwAaQ= github.com/goccy/go-yaml v1.11.2/go.mod h1:wKnAMd44+9JAAnGQpWVEgBzGt3YuTaQ4uXoHvE4m7WU= +github.com/gofri/go-github-ratelimit v1.1.0 h1:ijQ2bcv5pjZXNil5FiwglCg8wc9s8EgjTmNkqjw8nuk= +github.com/gofri/go-github-ratelimit v1.1.0/go.mod h1:OnCi5gV+hAG/LMR7llGhU7yHt44se9sYgKPnafoL7RY= github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk= github.com/golang/protobuf v1.5.2/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY= github.com/golang/protobuf v1.5.3 h1:KhyjKVUg7Usr/dYsdSqoFveMYd5ko72D+zANwlG1mmg= From a683c021bc318a880f9e1c769473458c46d1ab5e Mon Sep 17 00:00:00 2001 From: Shinji Nakamatsu <19329+snaka@users.noreply.github.com> Date: Fri, 20 Sep 2024 19:09:44 +0900 Subject: [PATCH 2/3] fix: typo --- semver.go | 4 ++-- tagpr.go | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/semver.go b/semver.go index 388f884..1cea8f9 100644 --- a/semver.go +++ b/semver.go @@ -34,9 +34,9 @@ func (sv *semv) GuessNext(labels []string) *semv { var isMajor, isMinor bool for _, l := range labels { switch l { - case autoLableName + ":major", autoLableName + "/major": + case autoLabelName + ":major", autoLabelName + "/major": isMajor = true - case autoLableName + ":minor", autoLableName + "/minor": + case autoLabelName + ":minor", autoLabelName + "/minor": isMinor = true } } diff --git a/tagpr.go b/tagpr.go index 3bccb9a..5248a34 100644 --- a/tagpr.go +++ b/tagpr.go @@ -27,7 +27,7 @@ const ( defaultReleaseBranch = "main" autoCommitMessage = "[tagpr] prepare for the next release" autoChangelogMessage = "[tagpr] update CHANGELOG.md" - autoLableName = "tagpr" + autoLabelName = "tagpr" branchPrefix = "tagpr-from-" ) @@ -111,7 +111,7 @@ func isTagPR(pr *github.PullRequest) bool { return false } for _, label := range pr.Labels { - if label.GetName() == autoLableName { + if label.GetName() == autoLabelName { return true } } @@ -473,7 +473,7 @@ OUT: showGHError(err, resp) return err } - addingLabels = append(addingLabels, autoLableName) + addingLabels = append(addingLabels, autoLabelName) _, resp, err = tp.gh.Issues.AddLabelsToIssue( ctx, tp.owner, tp.repo, *pr.Number, addingLabels) if err != nil { From a898dad4e5a4a1d71d4fd737986a9853875fc4ef Mon Sep 17 00:00:00 2001 From: Shinji Nakamatsu <19329+snaka@users.noreply.github.com> Date: Fri, 20 Sep 2024 19:11:11 +0900 Subject: [PATCH 3/3] fix: typo --- config.go | 2 +- config_test.go | 2 +- tagpr.go | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/config.go b/config.go index 1ee428a..72b1e9a 100644 --- a/config.go +++ b/config.go @@ -224,7 +224,7 @@ func (cfg *config) initializeFile() error { return nil } -func (cfg *config) SetRelaseBranch(br string) error { +func (cfg *config) SetReleaseBranch(br string) error { if err := cfg.set(configReleaseBranch, br); err != nil { return err } diff --git a/config_test.go b/config_test.go index 0ac6289..abd0286 100644 --- a/config_test.go +++ b/config_test.go @@ -24,7 +24,7 @@ func TestConfig(t *testing.T) { if e, g := "", cfg.ReleaseBranch(); e != g { t.Errorf("got: %s, expext: %s", g, e) } - if err := cfg.SetRelaseBranch("main"); err != nil { + if err := cfg.SetReleaseBranch("main"); err != nil { t.Error(err) } if e, g := "main", cfg.ReleaseBranch(); e != g { diff --git a/tagpr.go b/tagpr.go index 5248a34..7c21b2d 100644 --- a/tagpr.go +++ b/tagpr.go @@ -149,7 +149,7 @@ func (tp *tagpr) Run(ctx context.Context) error { if releaseBranch == "" { releaseBranch = defaultReleaseBranch } - if err := tp.cfg.SetRelaseBranch(releaseBranch); err != nil { + if err := tp.cfg.SetReleaseBranch(releaseBranch); err != nil { return err } }