@@ -14,6 +14,7 @@ import (
1414 ldapi "github.com/launchdarkly/api-client-go/v15"
1515 lcr "github.com/launchdarkly/find-code-references-in-pull-request/config"
1616 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"
1718 "github.com/launchdarkly/find-code-references-in-pull-request/internal/version"
1819
1920 flags "github.com/launchdarkly/find-code-references-in-pull-request/internal/references"
@@ -101,23 +102,24 @@ func makeFlagLinkRep(event *github.PullRequestEvent, flagKey, message string) *l
101102 return nil
102103 }
103104
105+ authorLogin := utils .SafeString (pr .User .Login )
104106 metadata := map [string ]string {
105107 "message" : message ,
106108 "prNumber" : strconv .Itoa (* pr .Number ),
107- "prTitle" : * pr .Title ,
108- "prBody" : * pr .Body ,
109- "state" : * pr .State ,
110- "avatarUrl" : * pr .User .AvatarURL ,
111- "repoName" : * event .Repo .FullName ,
112- "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 ) ,
113115 }
114116
115117 if pr .User .Name != nil {
116- metadata ["authorName" ] = * pr .User .Name
117- metadata ["authorDisplayName" ] = * pr .User .Name
118+ metadata ["authorName" ] = utils . SafeString ( pr .User .Name )
119+ metadata ["authorDisplayName" ] = utils . SafeString ( pr .User .Name )
118120 } else {
119- metadata ["authorDisplayName" ] = * pr . User . Login
120- metadata ["authorLogin" ] = * pr . User . Login
121+ metadata ["authorDisplayName" ] = authorLogin
122+ metadata ["authorLogin" ] = authorLogin
121123 }
122124
123125 var timestamp * int64
@@ -131,25 +133,30 @@ func makeFlagLinkRep(event *github.PullRequestEvent, flagKey, message string) *l
131133 // key must be unique
132134 key := fmt .Sprintf ("github-pr-%s-%s" , id , flagKey )
133135
136+ description := utils .SafeString (pr .Body )
137+ // Flag links require a description
138+ if description == "" {
139+ description = "Empty PR Body"
140+ }
134141 return & ldapi.FlagLinkPost {
135142 DeepLink : pr .HTMLURL ,
136143 Key : & key ,
137144 IntegrationKey : & integration ,
138145 Timestamp : timestamp ,
139146 Title : getLinkTitle (event ),
140- Description : pr . Body ,
147+ Description : & description ,
141148 Metadata : & metadata ,
142149 }
143150}
144151
145152func getLinkTitle (event * github.PullRequestEvent ) * string {
146153 builder := new (strings.Builder )
147- builder .WriteString (fmt .Sprintf ("[%s]" , * event .Repo .FullName ))
154+ builder .WriteString (fmt .Sprintf ("[%s]" , utils . SafeString ( event .Repo .FullName ) ))
148155
149156 pr := event .PullRequest
150157 if pr .Title != nil {
151158 builder .WriteString (" " )
152- builder .WriteString (* pr .Title )
159+ builder .WriteString (utils . SafeString ( pr .Title ) )
153160 if pr .Number != nil {
154161 builder .WriteString (fmt .Sprintf (" (#%d)" , * pr .Number ))
155162 }
0 commit comments