Skip to content

Commit 803494b

Browse files
[MM-742]: added a note about the label of pr/issue if subscription is specific to a label (#839)
1 parent bd358a6 commit 803494b

File tree

2 files changed

+16
-6
lines changed

2 files changed

+16
-6
lines changed

server/plugin/template.go

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,12 @@ func init() {
205205
{{- if .Labels }}
206206
Labels: {{range $i, $el := .Labels -}}` + "{{- if $i}}, {{end}}[`{{ $el.Name }}`]({{ $.RepositoryURL }}/labels/{{ $el.Name | pathEscape }})" + `{{end -}}
207207
{{ end -}}
208+
`))
209+
210+
template.Must(masterTemplate.New("subscriptionLabel").Funcs(funcMap).Parse(`
211+
{{- if . }}
212+
{{- if ne . "" }} with the label ` + "`{{.}}`" + `{{- end }}
213+
{{- end -}}
208214
`))
209215

210216
template.Must(masterTemplate.New("assignee").Funcs(funcMap).Parse(`
@@ -219,11 +225,11 @@ Assignees: {{range $i, $el := .Assignees -}} {{- if $i}}, {{end}}{{template "use
219225

220226
template.Must(masterTemplate.New("newPR").Funcs(funcMap).Parse(`
221227
{{ if eq .Config.Style "collapsed" -}}
222-
{{template "repo" .Event.GetRepo}} New pull request {{template "pullRequest" .Event.GetPullRequest}} was opened by {{template "user" .Event.GetSender}}.
228+
{{template "repo" .Event.GetRepo}} New pull request {{template "pullRequest" .Event.GetPullRequest}} was opened by {{template "user" .Event.GetSender}}{{template "subscriptionLabel" .Label}}.
223229
{{- else -}}
224230
#### {{.Event.GetPullRequest.GetTitle}}
225231
##### {{template "eventRepoPullRequest" .Event}}
226-
#new-pull-request by {{template "user" .Event.GetSender}}
232+
#new-pull-request by {{template "user" .Event.GetSender}}{{template "subscriptionLabel" .Label}}
227233
{{- if ne .Config.Style "skip-body" -}}
228234
{{- template "labels" dict "Labels" .Event.GetPullRequest.Labels "RepositoryURL" .Event.GetRepo.GetHTMLURL }}
229235
{{- template "assignee" .Event.GetPullRequest }}
@@ -235,11 +241,11 @@ Assignees: {{range $i, $el := .Assignees -}} {{- if $i}}, {{end}}{{template "use
235241

236242
template.Must(masterTemplate.New("markedReadyToReviewPR").Funcs(funcMap).Parse(`
237243
{{ if eq .Config.Style "collapsed" -}}
238-
{{template "repo" .Event.GetRepo}} Pull request {{template "pullRequest" .Event.GetPullRequest}} was marked ready for review by {{template "user" .Event.GetSender}}.
244+
{{template "repo" .Event.GetRepo}} Pull request {{template "pullRequest" .Event.GetPullRequest}} was marked ready for review by {{template "user" .Event.GetSender}}{{template "subscriptionLabel" (dict "Label" .Label)}}.
239245
{{- else -}}
240246
#### {{.Event.GetPullRequest.GetTitle}}
241247
##### {{template "eventRepoPullRequest" .Event}}
242-
#new-pull-request by {{template "user" .Event.PullRequest.User}}
248+
#new-pull-request by {{template "user" .Event.PullRequest.User}}{{template "subscriptionLabel" .Label}}
243249
{{- if ne .Config.Style "skip-body" -}}
244250
{{- template "labels" dict "Labels" .Event.GetPullRequest.Labels "RepositoryURL" .Event.GetRepo.GetHTMLURL }}
245251
{{- template "assignee" .Event.GetPullRequest }}
@@ -272,11 +278,11 @@ Assignees: {{range $i, $el := .Assignees -}} {{- if $i}}, {{end}}{{template "use
272278

273279
template.Must(masterTemplate.New("newIssue").Funcs(funcMap).Parse(`
274280
{{ if eq .Config.Style "collapsed" -}}
275-
{{template "repo" .Event.GetRepo}} New issue {{template "issue" .Event.GetIssue}} opened by {{template "user" .Event.GetSender}}.
281+
{{template "repo" .Event.GetRepo}} New issue {{template "issue" .Event.GetIssue}} opened by {{template "user" .Event.GetSender}}{{template "subscriptionLabel" .Label}}.
276282
{{- else -}}
277283
#### {{.Event.GetIssue.GetTitle}}
278284
##### {{template "eventRepoIssue" .Event}}
279-
#new-issue by {{template "user" .Event.GetSender}}
285+
#new-issue by {{template "user" .Event.GetSender}}{{template "subscriptionLabel" .Label}}
280286
{{- if ne .Config.Style "skip-body" -}}
281287
{{- template "labels" dict "Labels" .Event.GetIssue.Labels "RepositoryURL" .Event.GetRepo.GetHTMLURL }}
282288
{{- template "assignee" .Event.GetIssue }}

server/plugin/webhook.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ type RenderConfig struct {
5757
type EventWithRenderConfig struct {
5858
Event interface{}
5959
Config RenderConfig
60+
Label string
6061
}
6162

6263
func verifyWebhookSignature(secret []byte, signature string, body []byte) (bool, error) {
@@ -95,15 +96,18 @@ func signBody(secret, body []byte) ([]byte, error) {
9596
// which also contains per-subscription configuration options.
9697
func GetEventWithRenderConfig(event interface{}, sub *Subscription) *EventWithRenderConfig {
9798
style := ""
99+
subscriptionLabel := ""
98100
if sub != nil {
99101
style = sub.RenderStyle()
102+
subscriptionLabel = sub.Label()
100103
}
101104

102105
return &EventWithRenderConfig{
103106
Event: event,
104107
Config: RenderConfig{
105108
Style: style,
106109
},
110+
Label: subscriptionLabel,
107111
}
108112
}
109113

0 commit comments

Comments
 (0)