@@ -20,6 +20,7 @@ import (
20
20
"regexp"
21
21
"strings"
22
22
23
+ "golang.org/x/oauth2"
23
24
"k8s.io/klog/v2"
24
25
25
26
"github.com/google/go-github/v59/github"
@@ -69,11 +70,11 @@ func (m command) run(c *cli.Context) error {
69
70
m .log .Error (err , "Failed to get action context" )
70
71
return err
71
72
}
72
-
73
73
var newTitle string
74
- var issueNumber int
74
+ var issueNumber float64
75
75
if context .Event != nil {
76
76
if comment , ok := context .Event ["comment" ].(map [string ]any ); ok {
77
+ // Extract the comment body
77
78
if body , ok := comment ["body" ].(string ); ok {
78
79
// Make sure they are requesting a re-title
79
80
if ! retitleRe .MatchString (body ) {
@@ -83,24 +84,30 @@ func (m command) run(c *cli.Context) error {
83
84
newTitle = getNewTitle (body )
84
85
}
85
86
}
87
+ // get the issue number
86
88
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 {
88
90
issueNumber = num
89
91
}
90
92
}
91
93
}
92
94
m .log .Info ("New title" , "title" , newTitle )
93
95
m .log .Info ("Issue number" , "number" , issueNumber )
94
96
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 )
98
104
99
105
// Update the title
106
+ org , repo := context .Repo ()
100
107
req := & github.IssueRequest {
101
108
Title : & newTitle ,
102
109
}
103
- _ , _ , err = gh .Issues .Edit (c .Context , org , repo , issueNumber , req )
110
+ _ , _ , err = gh .Issues .Edit (c .Context , org , repo , int ( issueNumber ) , req )
104
111
if err != nil {
105
112
m .log .Error (err , "Failed to update issue" )
106
113
return err
0 commit comments