Skip to content

Commit

Permalink
Release 2.1.8 (#720)
Browse files Browse the repository at this point in the history
* [GH-717] Implement subscription notification for pull request "reopened" event (#718)

* [MI-3808] Fix issue: Subscription notification not working for pull request "reopened" event.

* [MI-3808] Added test case for new template

* [MI-3808] Review fix

* bump version to 2.1.8

---------

Co-authored-by: Raghav Aggarwal <raghav.aggarwal@brightscout.com>
  • Loading branch information
mickmister and raghavaggarwal2308 authored Dec 13, 2023
1 parent 34e32c4 commit 0d7f8ee
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 3 deletions.
4 changes: 2 additions & 2 deletions plugin.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
"description": "GitHub plugin for Mattermost.",
"homepage_url": "https://github.com/mattermost/mattermost-plugin-github",
"support_url": "https://github.com/mattermost/mattermost-plugin-github/issues",
"release_notes_url": "https://github.com/mattermost/mattermost-plugin-github/releases/tag/v2.1.7",
"release_notes_url": "https://github.com/mattermost/mattermost-plugin-github/releases/tag/v2.1.8",
"icon_path": "assets/icon.svg",
"version": "2.1.7",
"version": "2.1.8",
"min_server_version": "6.5.0",
"server": {
"executables": {
Expand Down
4 changes: 4 additions & 0 deletions server/plugin/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,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 @@ -341,6 +341,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
17 changes: 16 additions & 1 deletion server/plugin/webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,12 @@ func (p *Plugin) postPullRequestEvent(event *github.PullRequestEvent) {
}

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

Expand Down Expand Up @@ -387,6 +392,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)
}

if action == actionClosed {
post.Message = closedPRMessage
}
Expand Down

0 comments on commit 0d7f8ee

Please sign in to comment.