Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[GH-717] Implement subscription notification for pull request "reopened" event #718

Merged
merged 3 commits into from
Dec 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions server/plugin/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,10 @@ Assignees: {{range $i, $el := .Assignees -}} {{- if $i}}, {{end}}{{template "use
{{- if .GetPullRequest.GetMerged }} merged
{{- else }} closed
{{- end }} by {{template "user" .GetSender}}.
`))

template.Must(masterTemplate.New("reopenedPR").Funcs(funcMap).Parse(`
{{template "repo" .GetRepo}} Pull request {{template "pullRequest" .GetPullRequest}} was reopened by {{template "user" .GetSender}}.
`))

template.Must(masterTemplate.New("pullRequestLabelled").Funcs(funcMap).Parse(`
Expand Down
16 changes: 16 additions & 0 deletions server/plugin/template_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -393,6 +393,22 @@ func TestClosedPRMessageTemplate(t *testing.T) {
})
}

func TestReopenedPRMessageTemplate(t *testing.T) {
t.Run("reopened", func(t *testing.T) {
expected := `
[\[mattermost-plugin-github\]](https://github.com/mattermost/mattermost-plugin-github) Pull request [#42 Leverage git-get-head](https://github.com/mattermost/mattermost-plugin-github/pull/42) was reopened by [panda](https://github.com/panda).
`

actual, err := renderTemplate("reopenedPR", &github.PullRequestEvent{
Repo: &repo,
PullRequest: &pullRequest,
Sender: &user,
})
require.NoError(t, err)
require.Equal(t, expected, actual)
})
}

func TestPullRequestLabelledTemplate(t *testing.T) {
expected := `
#### Leverage git-get-head
Expand Down
19 changes: 18 additions & 1 deletion server/plugin/webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -353,9 +353,16 @@ func (p *Plugin) postPullRequestEvent(event *github.PullRequestEvent) {
}

action := event.GetAction()
if action != actionOpened && action != actionMarkedReadyForReview && action != actionLabeled && action != actionClosed {
switch action {
case actionOpened,
actionReopened,
actionMarkedReadyForReview,
actionLabeled,
actionClosed:
default:
return
}

pr := event.GetPullRequest()
isPRInDraftState := pr.GetDraft()
eventLabel := event.GetLabel().GetName()
Expand Down Expand Up @@ -436,6 +443,16 @@ func (p *Plugin) postPullRequestEvent(event *github.PullRequestEvent) {
post.Message = p.sanitizeDescription(newPRMessage)
}

if action == actionReopened {
reopenedPRMessage, err := renderTemplate("reopenedPR", event)
if err != nil {
p.client.Log.Warn("Failed to render template", "error", err.Error())
return
}

post.Message = p.sanitizeDescription(reopenedPRMessage)
}

raghavaggarwal2308 marked this conversation as resolved.
Show resolved Hide resolved
if action == actionMarkedReadyForReview {
markedReadyToReviewPRMessage, err := renderTemplate("markedReadyToReviewPR", GetEventWithRenderConfig(event, sub))
if err != nil {
Expand Down
Loading