Skip to content

Commit 03fff0d

Browse files
QUick look
Signed-off-by: Carlos Eduardo Arango Gutierrez <[email protected]>
1 parent 2abb3b9 commit 03fff0d

File tree

1 file changed

+14
-7
lines changed

1 file changed

+14
-7
lines changed

cmd/nv-ci-bot/retitle/retitle.go

+14-7
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020
"regexp"
2121
"strings"
2222

23+
"golang.org/x/oauth2"
2324
"k8s.io/klog/v2"
2425

2526
"github.com/google/go-github/v59/github"
@@ -69,11 +70,11 @@ func (m command) run(c *cli.Context) error {
6970
m.log.Error(err, "Failed to get action context")
7071
return err
7172
}
72-
7373
var newTitle string
74-
var issueNumber int
74+
var issueNumber float64
7575
if context.Event != nil {
7676
if comment, ok := context.Event["comment"].(map[string]any); ok {
77+
// Extract the comment body
7778
if body, ok := comment["body"].(string); ok {
7879
// Make sure they are requesting a re-title
7980
if !retitleRe.MatchString(body) {
@@ -83,24 +84,30 @@ func (m command) run(c *cli.Context) error {
8384
newTitle = getNewTitle(body)
8485
}
8586
}
87+
// get the issue number
8688
if issue, ok := context.Event["issue"].(map[string]any); ok {
87-
if num, ok := issue["number"].(int); ok {
89+
if num, ok := issue["number"].(float64); ok {
8890
issueNumber = num
8991
}
9092
}
9193
}
9294
m.log.Info("New title", "title", newTitle)
9395
m.log.Info("Issue number", "number", issueNumber)
9496

95-
org, repo := context.Repo()
96-
ghToken := action.Getenv("GITHUB_TOKEN")
97-
gh := github.NewClient(nil).WithAuthToken(ghToken)
97+
// Create the GitHub client
98+
accessToken := action.GetInput("GITHUB_TOKEN")
99+
ts := oauth2.StaticTokenSource(
100+
&oauth2.Token{AccessToken: accessToken},
101+
)
102+
tc := oauth2.NewClient(c.Context, ts)
103+
gh := github.NewClient(tc)
98104

99105
// Update the title
106+
org, repo := context.Repo()
100107
req := &github.IssueRequest{
101108
Title: &newTitle,
102109
}
103-
_, _, err = gh.Issues.Edit(c.Context, org, repo, issueNumber, req)
110+
_, _, err = gh.Issues.Edit(c.Context, org, repo, int(issueNumber), req)
104111
if err != nil {
105112
m.log.Error(err, "Failed to update issue")
106113
return err

0 commit comments

Comments
 (0)