Skip to content

Commit

Permalink
Add gh-access-token flag into backport script (#32283)
Browse files Browse the repository at this point in the history
The current backport script does not have github access token flag. 
This patch will be useful when encountered rate limit issue.
  • Loading branch information
cloudchamb3r authored Oct 17, 2024
1 parent 0196b35 commit 2b8ff41
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions contrib/backport/backport.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,11 @@ func main() {
Value: "",
Usage: "Forked user name on Github",
},
&cli.StringFlag{
Name: "gh-access-token",
Value: "",
Usage: "Access token for GitHub api request",
},
&cli.BoolFlag{
Name: "no-fetch",
Usage: "Set this flag to prevent fetch of remote branches",
Expand Down Expand Up @@ -169,9 +174,10 @@ func runBackport(c *cli.Context) error {
fmt.Printf("* Backporting %s to %s as %s\n", pr, localReleaseBranch, backportBranch)

sha := c.String("cherry-pick")
accessToken := c.String("gh-access-token")
if sha == "" {
var err error
sha, err = determineSHAforPR(ctx, pr)
sha, err = determineSHAforPR(ctx, pr, accessToken)
if err != nil {
return err
}
Expand Down Expand Up @@ -427,13 +433,16 @@ func readVersion() string {
return strings.Join(split[:2], ".")
}

func determineSHAforPR(ctx context.Context, prStr string) (string, error) {
func determineSHAforPR(ctx context.Context, prStr, accessToken string) (string, error) {
prNum, err := strconv.Atoi(prStr)
if err != nil {
return "", err
}

client := github.NewClient(http.DefaultClient)
if accessToken != "" {
client = client.WithAuthToken(accessToken)
}

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

0 comments on commit 2b8ff41

Please sign in to comment.