diff --git a/plugin.json b/plugin.json index d2799cefe..2b9205ff4 100644 --- a/plugin.json +++ b/plugin.json @@ -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": { diff --git a/server/plugin/template.go b/server/plugin/template.go index 7ec52bc89..26b50063e 100644 --- a/server/plugin/template.go +++ b/server/plugin/template.go @@ -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(` diff --git a/server/plugin/template_test.go b/server/plugin/template_test.go index 833ab6445..eb0ea68cd 100644 --- a/server/plugin/template_test.go +++ b/server/plugin/template_test.go @@ -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 diff --git a/server/plugin/webhook.go b/server/plugin/webhook.go index d86c82534..5c64abf72 100644 --- a/server/plugin/webhook.go +++ b/server/plugin/webhook.go @@ -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 } @@ -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 }