@@ -9,10 +9,12 @@ import (
99 "strconv"
1010 "strings"
1111
12- "github.com/google/go-github/github"
12+ "github.com/google/go-github/v68/github"
13+
1314 ldapi "github.com/launchdarkly/api-client-go/v15"
1415 lcr "github.com/launchdarkly/find-code-references-in-pull-request/config"
1516 gha "github.com/launchdarkly/find-code-references-in-pull-request/internal/github_actions"
17+ "github.com/launchdarkly/find-code-references-in-pull-request/internal/utils"
1618 "github.com/launchdarkly/find-code-references-in-pull-request/internal/version"
1719
1820 flags "github.com/launchdarkly/find-code-references-in-pull-request/internal/references"
@@ -100,23 +102,24 @@ func makeFlagLinkRep(event *github.PullRequestEvent, flagKey, message string) *l
100102 return nil
101103 }
102104
105+ authorLogin := utils .SafeString (pr .User .Login )
103106 metadata := map [string ]string {
104107 "message" : message ,
105108 "prNumber" : strconv .Itoa (* pr .Number ),
106- "prTitle" : * pr .Title ,
107- "prBody" : * pr .Body ,
108- "state" : * pr .State ,
109- "avatarUrl" : * pr .User .AvatarURL ,
110- "repoName" : * event .Repo .FullName ,
111- "repoUrl" : * event .Repo .HTMLURL ,
109+ "prTitle" : utils . SafeString ( pr .Title ) ,
110+ "prBody" : utils . SafeString ( pr .Body ) ,
111+ "state" : utils . SafeString ( pr .State ) ,
112+ "avatarUrl" : utils . SafeString ( pr .User .AvatarURL ) ,
113+ "repoName" : utils . SafeString ( event .Repo .FullName ) ,
114+ "repoUrl" : utils . SafeString ( event .Repo .HTMLURL ) ,
112115 }
113116
114117 if pr .User .Name != nil {
115- metadata ["authorName" ] = * pr .User .Name
116- metadata ["authorDisplayName" ] = * pr .User .Name
118+ metadata ["authorName" ] = utils . SafeString ( pr .User .Name )
119+ metadata ["authorDisplayName" ] = utils . SafeString ( pr .User .Name )
117120 } else {
118- metadata ["authorDisplayName" ] = * pr . User . Login
119- metadata ["authorLogin" ] = * pr . User . Login
121+ metadata ["authorDisplayName" ] = authorLogin
122+ metadata ["authorLogin" ] = authorLogin
120123 }
121124
122125 var timestamp * int64
@@ -130,25 +133,30 @@ func makeFlagLinkRep(event *github.PullRequestEvent, flagKey, message string) *l
130133 // key must be unique
131134 key := fmt .Sprintf ("github-pr-%s-%s" , id , flagKey )
132135
136+ description := utils .SafeString (pr .Body )
137+ // Flag links require a description
138+ if description == "" {
139+ description = "Empty PR Body"
140+ }
133141 return & ldapi.FlagLinkPost {
134142 DeepLink : pr .HTMLURL ,
135143 Key : & key ,
136144 IntegrationKey : & integration ,
137145 Timestamp : timestamp ,
138146 Title : getLinkTitle (event ),
139- Description : pr . Body ,
147+ Description : & description ,
140148 Metadata : & metadata ,
141149 }
142150}
143151
144152func getLinkTitle (event * github.PullRequestEvent ) * string {
145153 builder := new (strings.Builder )
146- builder .WriteString (fmt .Sprintf ("[%s]" , * event .Repo .FullName ))
154+ builder .WriteString (fmt .Sprintf ("[%s]" , utils . SafeString ( event .Repo .FullName ) ))
147155
148156 pr := event .PullRequest
149157 if pr .Title != nil {
150158 builder .WriteString (" " )
151- builder .WriteString (* pr .Title )
159+ builder .WriteString (utils . SafeString ( pr .Title ) )
152160 if pr .Number != nil {
153161 builder .WriteString (fmt .Sprintf (" (#%d)" , * pr .Number ))
154162 }
0 commit comments