chore: remove trim \n from message (#105)
This commit is contained in:
parent
2dfbc98fdd
commit
ab44454733
4
DOCS.md
4
DOCS.md
@ -122,7 +122,7 @@ Example configuration with video message:
|
|||||||
+ - tests/video2.mp4
|
+ - tests/video2.mp4
|
||||||
```
|
```
|
||||||
|
|
||||||
Example configuration with message format:
|
Example configuration with message format (`Markdown` or `HTML`), default as `Markdown`:
|
||||||
|
|
||||||
```diff
|
```diff
|
||||||
- name: send telegram notification
|
- name: send telegram notification
|
||||||
@ -130,7 +130,7 @@ Example configuration with message format:
|
|||||||
settings:
|
settings:
|
||||||
token: xxxxxxxxxx
|
token: xxxxxxxxxx
|
||||||
to: telegram_user_id
|
to: telegram_user_id
|
||||||
+ format: markdown
|
+ format: Markdown
|
||||||
```
|
```
|
||||||
|
|
||||||
Example configuration with a custom message template:
|
Example configuration with a custom message template:
|
||||||
|
2
main.go
2
main.go
@ -122,7 +122,7 @@ func main() {
|
|||||||
cli.StringFlag{
|
cli.StringFlag{
|
||||||
Name: "format",
|
Name: "format",
|
||||||
Value: formatMarkdown,
|
Value: formatMarkdown,
|
||||||
Usage: "telegram message format",
|
Usage: "telegram message format (Markdown or HTML)",
|
||||||
EnvVar: "PLUGIN_FORMAT,FORMAT,INPUT_FORMAT",
|
EnvVar: "PLUGIN_FORMAT,FORMAT,INPUT_FORMAT",
|
||||||
},
|
},
|
||||||
cli.StringFlag{
|
cli.StringFlag{
|
||||||
|
@ -20,7 +20,8 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
formatMarkdown = "markdown"
|
formatMarkdown = "Markdown"
|
||||||
|
formatHTML = "HTML"
|
||||||
)
|
)
|
||||||
|
|
||||||
type (
|
type (
|
||||||
@ -259,6 +260,10 @@ func parseTo(to []string, authorEmail string, matchEmail bool) []int64 {
|
|||||||
return ids
|
return ids
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func templateMessage(t string, plugin Plugin) (string, error) {
|
||||||
|
return template.RenderTrim(t, plugin)
|
||||||
|
}
|
||||||
|
|
||||||
// Exec executes the plugin.
|
// Exec executes the plugin.
|
||||||
func (p Plugin) Exec() (err error) {
|
func (p Plugin) Exec() (err error) {
|
||||||
if len(p.Config.Token) == 0 || len(p.Config.To) == 0 {
|
if len(p.Config.Token) == 0 || len(p.Config.To) == 0 {
|
||||||
@ -356,7 +361,7 @@ func (p Plugin) Exec() (err error) {
|
|||||||
// send message.
|
// send message.
|
||||||
for _, user := range ids {
|
for _, user := range ids {
|
||||||
for _, value := range message {
|
for _, value := range message {
|
||||||
txt, err := template.RenderTrim(value, p)
|
txt, err := templateMessage(value, p)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -353,7 +353,7 @@ func TestHTMLMessage(t *testing.T) {
|
|||||||
Sha: "e7c4f0a63ceeb42a39ac7806f7b51f3f0d204fd2",
|
Sha: "e7c4f0a63ceeb42a39ac7806f7b51f3f0d204fd2",
|
||||||
Author: "Bo-Yi Wu",
|
Author: "Bo-Yi Wu",
|
||||||
Branch: "master",
|
Branch: "master",
|
||||||
Message: "Freakin' macOS isn't fully case-sensitive..",
|
Message: "test",
|
||||||
},
|
},
|
||||||
Build: Build{
|
Build: Build{
|
||||||
Number: 101,
|
Number: 101,
|
||||||
@ -364,11 +364,20 @@ func TestHTMLMessage(t *testing.T) {
|
|||||||
Config: Config{
|
Config: Config{
|
||||||
Token: os.Getenv("TELEGRAM_TOKEN"),
|
Token: os.Getenv("TELEGRAM_TOKEN"),
|
||||||
To: []string{os.Getenv("TELEGRAM_TO")},
|
To: []string{os.Getenv("TELEGRAM_TO")},
|
||||||
|
Message: `
|
||||||
|
Test HTML Format
|
||||||
|
<a href='https://google.com'>Google .com 1</a>
|
||||||
|
<a href='https://google.com'>Google .com 2</a>
|
||||||
|
<a href='https://google.com'>Google .com 3</a>
|
||||||
|
`,
|
||||||
|
Format: formatHTML,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
err := plugin.Exec()
|
assert.Nil(t, plugin.Exec())
|
||||||
assert.Nil(t, err)
|
|
||||||
|
plugin.Config.MessageFile = "tests/message_html.txt"
|
||||||
|
assert.Nil(t, plugin.Exec())
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestMessageFile(t *testing.T) {
|
func TestMessageFile(t *testing.T) {
|
||||||
|
5
tests/message_html.txt
Normal file
5
tests/message_html.txt
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
Test HTML Format from file
|
||||||
|
<a href='https://google.com'>Google .com 1</a>
|
||||||
|
<a href='https://google.com'>Google .com 2</a>
|
||||||
|
<a href='https://google.com'>Google .com 3</a>
|
||||||
|
<a href='https://google.com'>Google .com 4</a>
|
Loading…
Reference in New Issue
Block a user