@@ -101,7 +101,7 @@ func (v *Provider) CreateComment(_ context.Context, event *info.Event, commit, u
101101 return err
102102 }
103103
104- re := regexp .MustCompile (updateMarker )
104+ re := regexp .MustCompile (regexp . QuoteMeta ( updateMarker ) )
105105 for _ , comment := range comments {
106106 if re .MatchString (comment .Body ) {
107107 // Get the UserID for the PAC user.
@@ -229,7 +229,7 @@ func (v *Provider) SetClient(_ context.Context, run *params.Run, runevent *info.
229229 return nil
230230}
231231
232- func (v * Provider ) CreateStatus (_ context.Context , event * info.Event , statusOpts providerstatus.StatusOpts ) error {
232+ func (v * Provider ) CreateStatus (ctx context.Context , event * info.Event , statusOpts providerstatus.StatusOpts ) error {
233233 if v .giteaClient == nil {
234234 return fmt .Errorf ("cannot set status on gitea no token or url set" )
235235 }
@@ -265,10 +265,10 @@ func (v *Provider) CreateStatus(_ context.Context, event *info.Event, statusOpts
265265 // gitea show weirdly the <br>
266266 statusOpts .Summary = fmt .Sprintf ("%s%s %s" , v .pacInfo .ApplicationName , onPr , statusOpts .Summary )
267267
268- return v .createStatusCommit (event , v .pacInfo , statusOpts )
268+ return v .createStatusCommit (ctx , event , v .pacInfo , statusOpts )
269269}
270270
271- func (v * Provider ) createStatusCommit (event * info.Event , pacopts * info.PacOpts , status providerstatus.StatusOpts ) error {
271+ func (v * Provider ) createStatusCommit (ctx context. Context , event * info.Event , pacopts * info.PacOpts , status providerstatus.StatusOpts ) error {
272272 state := forgejo .StatusState (status .Conclusion )
273273 switch status .Conclusion {
274274 case providerstatus .ConclusionNeutral :
@@ -315,15 +315,45 @@ func (v *Provider) createStatusCommit(event *info.Event, pacopts *info.PacOpts,
315315 if opscomments .IsAnyOpsEventType (eventType .String ()) {
316316 eventType = triggertype .PullRequest
317317 }
318- if status .Text != "" && (eventType == triggertype .PullRequest || event .TriggerTarget == triggertype .PullRequest ) {
319- status .Text = strings .ReplaceAll (strings .TrimSpace (status .Text ), "<br>" , "\n " )
320- _ , _ , err := v .Client ().CreateIssueComment (event .Organization , event .Repository ,
321- int64 (event .PullRequestNumber ), forgejo.CreateIssueCommentOption {
322- Body : fmt .Sprintf ("%s\n %s" , status .Summary , status .Text ),
323- },
324- )
325- if err != nil {
326- return err
318+
319+ var commentStrategy string
320+ if v .repo != nil && v .repo .Spec .Settings != nil && v .repo .Spec .Settings .Forgejo != nil {
321+ commentStrategy = v .repo .Spec .Settings .Forgejo .CommentStrategy
322+ }
323+ switch commentStrategy {
324+ case provider .DisableAllCommentStrategy :
325+ v .Logger .Warn ("Comments related to PipelineRuns status have been disabled for Gitea/Forgejo pull requests" )
326+ return nil
327+ case provider .UpdateCommentStrategy :
328+ if eventType == triggertype .PullRequest || event .TriggerTarget == triggertype .PullRequest {
329+ status .Text = strings .ReplaceAll (strings .TrimSpace (status .Text ), "<br>" , "\n " )
330+ statusComment := v .formatPipelineComment (event .SHA , status )
331+ // Creating the prefix that is added to the status comment for a pipeline run.
332+ plrStatusCommentPrefix := fmt .Sprintf (provider .PlrStatusCommentPrefixTemplate , status .OriginalPipelineRunName )
333+ // The entire markdown comment, including the prefix that is added to the pull request for the pipelinerun.
334+ markdownStatusComment := fmt .Sprintf ("%s\n %s" , plrStatusCommentPrefix , statusComment )
335+
336+ if err := v .CreateComment (ctx , event , markdownStatusComment , plrStatusCommentPrefix ); err != nil {
337+ v .eventEmitter .EmitMessage (
338+ v .repo ,
339+ zap .ErrorLevel ,
340+ "PipelineRunCommentCreationError" ,
341+ fmt .Sprintf ("failed to create comment: %s" , err .Error ()),
342+ )
343+ return err
344+ }
345+ }
346+ default :
347+ if status .Text != "" && (eventType == triggertype .PullRequest || event .TriggerTarget == triggertype .PullRequest ) {
348+ status .Text = strings .ReplaceAll (strings .TrimSpace (status .Text ), "<br>" , "\n " )
349+ _ , _ , err := v .Client ().CreateIssueComment (event .Organization , event .Repository ,
350+ int64 (event .PullRequestNumber ), forgejo.CreateIssueCommentOption {
351+ Body : fmt .Sprintf ("%s\n %s" , status .Summary , status .Text ),
352+ },
353+ )
354+ if err != nil {
355+ return err
356+ }
327357 }
328358 }
329359 return nil
@@ -570,3 +600,25 @@ func (v *Provider) CreateToken(_ context.Context, _ []string, _ *info.Event) (st
570600func (v * Provider ) GetTemplate (commentType provider.CommentType ) string {
571601 return provider .GetHTMLTemplate (commentType )
572602}
603+
604+ func (v * Provider ) formatPipelineComment (sha string , status providerstatus.StatusOpts ) string {
605+ var emoji string
606+
607+ if status .Status == "in_progress" {
608+ emoji = "🚀"
609+ } else {
610+ switch status .Conclusion {
611+ case providerstatus .ConclusionCancelled :
612+ emoji = "⚠️"
613+ case providerstatus .ConclusionFailure :
614+ emoji = "❌"
615+ case providerstatus .ConclusionSuccess :
616+ emoji = "✅"
617+ default :
618+ emoji = "ℹ️"
619+ }
620+ }
621+
622+ return fmt .Sprintf ("%s **%s: %s/%s for %s**\n \n %s\n \n <small>Full log available [here](%s)</small>" ,
623+ emoji , status .Title , v .pacInfo .ApplicationName , status .OriginalPipelineRunName , sha , status .Text , status .DetailsURL )
624+ }
0 commit comments