summaryrefslogtreecommitdiffstats
path: root/contrib
diff options
context:
space:
mode:
authorcloudchamb3r <jizon0123@protonmail.com>2024-10-17 14:43:48 +0900
committerGitHub <noreply@github.com>2024-10-17 01:43:48 -0400
commit2b8ff419a75afd81b9902c4964e9ad9475000825 (patch)
tree3fa973529b3f92a1fa67382653ba931d020df3b9 /contrib
parent0196b3583a09131f42dd0a364ad46babd5f12e04 (diff)
downloadgitea-2b8ff419a75afd81b9902c4964e9ad9475000825.tar.gz
gitea-2b8ff419a75afd81b9902c4964e9ad9475000825.zip
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.
Diffstat (limited to 'contrib')
-rw-r--r--contrib/backport/backport.go13
1 files changed, 11 insertions, 2 deletions
diff --git a/contrib/backport/backport.go b/contrib/backport/backport.go
index 9ae4483d8b..eb19437445 100644
--- a/contrib/backport/backport.go
+++ b/contrib/backport/backport.go
@@ -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",
@@ -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
}
@@ -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 {