Skip to content

Commit f54a75f

Browse files
author
Raghav Aggarwal
authored
Fix discussion event notification (#894)
* Fix issue with getting same msg for different discussion events * Fix comment events * Handle discussion edited event
1 parent f12d4e7 commit f54a75f

File tree

2 files changed

+12
-7
lines changed

2 files changed

+12
-7
lines changed

server/plugin/template.go

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -486,13 +486,22 @@ Step failed: {{.GetWorkflowJob.Steps | workflowJobFailedStep}}
486486
{{- end -}}`))
487487

488488
template.Must(masterTemplate.New("newDiscussion").Funcs(funcMap).Parse(`
489-
{{template "user" .GetSender}} started a new discussion [#{{.GetDiscussion.GetNumber}} {{.GetDiscussion.GetTitle}}]({{.GetDiscussion.GetHTMLURL}}) on {{template "repo" .GetRepo}}
489+
{{template "user" .GetSender}}
490+
{{- if eq .GetAction "created" }} started a new
491+
{{- else if eq .GetAction "closed" }} closed a
492+
{{- else if eq .GetAction "reopened" }} reopened a
493+
{{- else if eq .GetAction "edited" }} edited a
494+
{{- end }} discussion [#{{.GetDiscussion.GetNumber}} {{.GetDiscussion.GetTitle}}]({{.GetDiscussion.GetHTMLURL}}) on {{template "repo" .GetRepo}}
490495
`))
491496

492497
template.Must(masterTemplate.New("newDiscussionComment").Funcs(funcMap).Parse(`
493-
{{template "repo" .GetRepo}} New comment by {{template "user" .GetSender}} on discussion [#{{.GetDiscussion.GetNumber}} {{.GetDiscussion.GetTitle}}]({{.GetDiscussion.GetHTMLURL}}):
498+
{{template "repo" .GetRepo}}
499+
{{- if eq .GetAction "created" }} New comment
500+
{{- else if eq .GetAction "edited" }} Comment edited
501+
{{- else if eq .GetAction "deleted" }} Comment deleted
502+
{{- end }} by {{template "user" .GetSender}} on discussion [#{{.GetDiscussion.GetNumber}} {{.GetDiscussion.GetTitle}}]({{.GetDiscussion.GetHTMLURL}}):
494503
495-
{{.GetComment.GetBody | trimBody | replaceAllGitHubUsernames}}
504+
> {{.GetComment.GetBody | trimBody | replaceAllGitHubUsernames}}
496505
`))
497506
}
498507

server/plugin/webhook.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1508,10 +1508,6 @@ func (p *Plugin) postDiscussionCommentEvent(event *github.DiscussionCommentEvent
15081508
return
15091509
}
15101510

1511-
if event.GetAction() != actionCreated {
1512-
return
1513-
}
1514-
15151511
newDiscussionCommentMessage, err := renderTemplate("newDiscussionComment", event)
15161512
if err != nil {
15171513
p.client.Log.Warn("Failed to render template", "error", err.Error())

0 commit comments

Comments
 (0)