Skip to content

Commit 2b8ff41

Browse files
authored
Add gh-access-token flag into backport script (#32283)
The current backport script does not have github access token flag. This patch will be useful when encountered rate limit issue.
1 parent 0196b35 commit 2b8ff41

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

contrib/backport/backport.go

+11-2
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,11 @@ func main() {
6464
Value: "",
6565
Usage: "Forked user name on Github",
6666
},
67+
&cli.StringFlag{
68+
Name: "gh-access-token",
69+
Value: "",
70+
Usage: "Access token for GitHub api request",
71+
},
6772
&cli.BoolFlag{
6873
Name: "no-fetch",
6974
Usage: "Set this flag to prevent fetch of remote branches",
@@ -169,9 +174,10 @@ func runBackport(c *cli.Context) error {
169174
fmt.Printf("* Backporting %s to %s as %s\n", pr, localReleaseBranch, backportBranch)
170175

171176
sha := c.String("cherry-pick")
177+
accessToken := c.String("gh-access-token")
172178
if sha == "" {
173179
var err error
174-
sha, err = determineSHAforPR(ctx, pr)
180+
sha, err = determineSHAforPR(ctx, pr, accessToken)
175181
if err != nil {
176182
return err
177183
}
@@ -427,13 +433,16 @@ func readVersion() string {
427433
return strings.Join(split[:2], ".")
428434
}
429435

430-
func determineSHAforPR(ctx context.Context, prStr string) (string, error) {
436+
func determineSHAforPR(ctx context.Context, prStr, accessToken string) (string, error) {
431437
prNum, err := strconv.Atoi(prStr)
432438
if err != nil {
433439
return "", err
434440
}
435441

436442
client := github.NewClient(http.DefaultClient)
443+
if accessToken != "" {
444+
client = client.WithAuthToken(accessToken)
445+
}
437446

438447
pr, _, err := client.PullRequests.Get(ctx, "go-gitea", "gitea", prNum)
439448
if err != nil {

0 commit comments

Comments
 (0)