Browse Source

Improve message formatting

tags/v0.3.2
Russ Garrett 5 years ago
parent
commit
8bfd0e6d75
No account linked to committer's email address
2 changed files with 10 additions and 3 deletions
  1. 2
    2
      httplistener/templates.go
  2. 8
    1
      util/string.go

+ 2
- 2
httplistener/templates.go View File

11
 
11
 
12
 var defaultTemplates = map[string]string{
12
 var defaultTemplates = map[string]string{
13
 	"github.release": "[{{b .Repository.Name}}] release {{h .Release.TagName}} has been published by {{g .Release.Author.Login}}: {{.Release.HTMLURL}}",
13
 	"github.release": "[{{b .Repository.Name}}] release {{h .Release.TagName}} has been published by {{g .Release.Author.Login}}: {{.Release.HTMLURL}}",
14
-	"github.push": `[{{b .Repository.Name}}] {{g .Sender.Login}} pushed {{.Commits|len}} commits to {{.Ref|refType}} {{.Ref|refName|h}}: {{.Compare}}
14
+	"github.push": `[{{b .Repository.Name}}] {{g .Sender.Login}} {{if .Forced}}force-{{end}}pushed {{if .Commits}}{{.Commits|len}} commit{{if .Commits|len|lt 1}}s{{end}} to {{end}}{{.Ref|refType}} {{.Ref|refName|h}}: {{.Compare}}
15
 {{range commitLimit . 3}}
15
 {{range commitLimit . 3}}
16
-	{{g .Username}} ({{.Sha|truncateSha|h}}): {{.Message}}
16
+	{{g .Username}} ({{.Sha|truncateSha|h}}): {{trunc .Message 150}}
17
 {{end}}`,
17
 {{end}}`,
18
 	"github.issue":        "[{{b .Repository.Name}}] {{g .Sender.Login}} {{.Action}} issue #{{.Issue.Number}}: {{.Issue.Title}} {{.Issue.HTMLURL}}",
18
 	"github.issue":        "[{{b .Repository.Name}}] {{g .Sender.Login}} {{.Action}} issue #{{.Issue.Number}}: {{.Issue.Title}} {{.Issue.HTMLURL}}",
19
 	"github.issuecomment": "[{{b .Repository.Name}}] {{g .Comment.User.Login}} commented on issue #{{.Issue.Number}}: {{trunc .Comment.Body 150}} {{.Issue.HTMLURL}}",
19
 	"github.issuecomment": "[{{b .Repository.Name}}] {{g .Comment.User.Login}} commented on issue #{{.Issue.Number}}: {{trunc .Comment.Body 150}} {{.Issue.HTMLURL}}",

+ 8
- 1
util/string.go View File

1
 package util
1
 package util
2
 
2
 
3
 import (
3
 import (
4
+	"strings"
4
 	"unicode"
5
 	"unicode"
5
 )
6
 )
6
 
7
 
7
 func Truncate(in string, length int) string {
8
 func Truncate(in string, length int) string {
9
+	parts := strings.Split(in, "\n")
10
+	in = parts[0]
8
 	if len(in) <= length {
11
 	if len(in) <= length {
9
-		return in
12
+		if len(parts) > 1 {
13
+			return in + "…"
14
+		} else {
15
+			return in
16
+		}
10
 	}
17
 	}
11
 
18
 
12
 	runes := []rune(in)
19
 	runes := []rune(in)

Loading…
Cancel
Save