mirror of
https://github.com/appleboy/drone-discord.git
synced 2026-06-04 10:23:47 +08:00
rename content to message
Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
This commit is contained in:
@@ -18,7 +18,7 @@ pipeline:
|
||||
image: appleboy/drone-discord
|
||||
webhook_id: xxxxxxxxxx
|
||||
webhook_token: xxxxxxxxxx
|
||||
content: "Testing from drone image"
|
||||
message: "Testing from drone image"
|
||||
```
|
||||
|
||||
Example configuration with TTS message:
|
||||
@@ -30,7 +30,7 @@ pipeline:
|
||||
webhook_id: xxxxxxxxxx
|
||||
webhook_token: xxxxxxxxxx
|
||||
+ tts: true
|
||||
content: "Testing from drone image"
|
||||
message: "Testing from drone image"
|
||||
```
|
||||
|
||||
Example configuration with override the default username of the webhook:
|
||||
@@ -42,7 +42,7 @@ pipeline:
|
||||
webhook_id: xxxxxxxxxx
|
||||
webhook_token: xxxxxxxxxx
|
||||
+ username: appleboy
|
||||
content: "Testing from drone image"
|
||||
message: "Testing from drone image"
|
||||
```
|
||||
|
||||
Example configuration with override the default avatar of the webhook:
|
||||
@@ -54,7 +54,7 @@ pipeline:
|
||||
webhook_id: xxxxxxxxxx
|
||||
webhook_token: xxxxxxxxxx
|
||||
+ avatar_url: http://exampple.com/appleboy.png
|
||||
content: "Testing from drone image"
|
||||
message: "Testing from drone image"
|
||||
```
|
||||
|
||||
Example configuration with a custom message template:
|
||||
@@ -65,7 +65,7 @@ pipeline:
|
||||
image: appleboy/drone-discord
|
||||
webhook_id: xxxxxxxxxx
|
||||
webhook_token: xxxxxxxxxx
|
||||
+ content: |
|
||||
+ messageq: |
|
||||
+ {{ #success build.status }}
|
||||
+ build {{ build.number }} succeeded. Good job.
|
||||
+ {{ else }}
|
||||
@@ -90,7 +90,7 @@ username
|
||||
tts
|
||||
: true if this is a TTS message
|
||||
|
||||
content
|
||||
message
|
||||
: the message contents (up to 2000 characters)
|
||||
|
||||
# Template Reference
|
||||
|
||||
@@ -69,7 +69,7 @@ There are three ways to send notification.
|
||||
drone-discord \
|
||||
--webhook-id xxxx \
|
||||
--webhook-token xxxx \
|
||||
--content "Test Message"
|
||||
--message "Test Message"
|
||||
```
|
||||
|
||||
<a name="usage-from-docker"></a>
|
||||
@@ -85,7 +85,7 @@ docker run --rm \
|
||||
-e TTS=false \
|
||||
-e USERNAME=test \
|
||||
-e AVATAR_URL=http://example.com/xxxx.png \
|
||||
-e CONTENT=test \
|
||||
-e MESSAGE=test \
|
||||
appleboy/drone-discord
|
||||
```
|
||||
|
||||
@@ -104,7 +104,7 @@ docker run --rm \
|
||||
-e TTS=false \
|
||||
-e USERNAME=test \
|
||||
-e AVATAR_URL=http://example.com/xxxx.png \
|
||||
-e CONTENT=test \
|
||||
-e MESSAGE=test \
|
||||
-e DRONE_REPO_OWNER=appleboy \
|
||||
-e DRONE_REPO_NAME=go-hello \
|
||||
-e DRONE_COMMIT_SHA=e5e82b5eb3737205c25955dcc3dcacc839b7be52 \
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
// --webhook-token xxxx \
|
||||
// --username value \
|
||||
// --avatar-url value \
|
||||
// --content "Test Message"
|
||||
// --message "Test Message"
|
||||
//
|
||||
// For more details, see the documentation and example.
|
||||
//
|
||||
|
||||
@@ -36,9 +36,9 @@ func main() {
|
||||
EnvVar: "PLUGIN_WEBHOOK_TOKEN,WEBHOOK_TOKEN",
|
||||
},
|
||||
cli.StringSliceFlag{
|
||||
Name: "content",
|
||||
Name: "message",
|
||||
Usage: "the message contents (up to 2000 characters)",
|
||||
EnvVar: "PLUGIN_CONTENT,CONTENT",
|
||||
EnvVar: "PLUGIN_MESSAGE,MESSAGE",
|
||||
},
|
||||
cli.BoolFlag{
|
||||
Name: "wait",
|
||||
@@ -170,7 +170,7 @@ func run(c *cli.Context) error {
|
||||
WebhookID: c.String("webhook-id"),
|
||||
WebhookToken: c.String("webhook-token"),
|
||||
Wait: c.Bool("wait"),
|
||||
Content: c.StringSlice("content"),
|
||||
Message: c.StringSlice("message"),
|
||||
Username: c.String("username"),
|
||||
AvatarURL: c.String("avatar-url"),
|
||||
TTS: c.Bool("tts"),
|
||||
|
||||
@@ -38,11 +38,12 @@ type (
|
||||
Config struct {
|
||||
WebhookID string
|
||||
WebhookToken string
|
||||
Wait bool
|
||||
Content []string
|
||||
Username string
|
||||
AvatarURL string
|
||||
TTS bool
|
||||
Message []string
|
||||
Wait bool `json:"wait"`
|
||||
Content string `json:"content"`
|
||||
Username string `json:"username"`
|
||||
AvatarURL string `json:"avatar_url"`
|
||||
TTS bool `json:"tts"`
|
||||
}
|
||||
|
||||
// Plugin values.
|
||||
@@ -64,8 +65,8 @@ func (p Plugin) Exec() error {
|
||||
webhookURL := fmt.Sprintf("https://discordapp.com/api/webhooks/%s/%s", p.Config.WebhookID, p.Config.WebhookToken)
|
||||
|
||||
var messages []string
|
||||
if len(p.Config.Content) > 0 {
|
||||
messages = p.Config.Content
|
||||
if len(p.Config.Message) > 0 {
|
||||
messages = p.Config.Message
|
||||
} else {
|
||||
messages = p.Message(p.Repo, p.Build)
|
||||
}
|
||||
@@ -76,15 +77,10 @@ func (p Plugin) Exec() error {
|
||||
return err
|
||||
}
|
||||
|
||||
content := map[string]interface{}{
|
||||
"wait": p.Config.Wait,
|
||||
"content": txt,
|
||||
"username": p.Config.Username,
|
||||
"avatar_url": p.Config.AvatarURL,
|
||||
"tts": p.Config.TTS,
|
||||
}
|
||||
//
|
||||
p.Config.Content = txt
|
||||
b := new(bytes.Buffer)
|
||||
json.NewEncoder(b).Encode(content)
|
||||
json.NewEncoder(b).Encode(p.Config)
|
||||
_, err = http.Post(webhookURL, "application/json; charset=utf-8", b)
|
||||
|
||||
if err != nil {
|
||||
|
||||
+9
-3
@@ -37,7 +37,7 @@ func TestDefaultMessageFormat(t *testing.T) {
|
||||
assert.Equal(t, []string{"[success] <https://github.com/appleboy/go-hello> (master)『update by drone line plugin.』by Bo-Yi Wu"}, message)
|
||||
}
|
||||
|
||||
func TestErrorSendMessage(t *testing.T) {
|
||||
func TestSendMessage(t *testing.T) {
|
||||
plugin := Plugin{
|
||||
Repo: Repo{
|
||||
Name: "go-hello",
|
||||
@@ -57,7 +57,7 @@ func TestErrorSendMessage(t *testing.T) {
|
||||
WebhookID: os.Getenv("WEBHOOK_ID"),
|
||||
WebhookToken: os.Getenv("WEBHOOK_TOKEN"),
|
||||
Wait: false,
|
||||
Content: []string{"test one message from drone testing", "test two message from drone testing"},
|
||||
Message: []string{"test one message from drone testing", "test two message from drone testing"},
|
||||
Username: "drone-ci",
|
||||
TTS: false,
|
||||
},
|
||||
@@ -66,7 +66,13 @@ func TestErrorSendMessage(t *testing.T) {
|
||||
err := plugin.Exec()
|
||||
assert.Nil(t, err)
|
||||
|
||||
plugin.Config.Content = []string{}
|
||||
plugin.Config.Message = []string{}
|
||||
err = plugin.Exec()
|
||||
assert.Nil(t, err)
|
||||
|
||||
plugin.Config.Message = []string{"I am appleboy"}
|
||||
plugin.Config.TTS = true
|
||||
plugin.Config.Wait = true
|
||||
err = plugin.Exec()
|
||||
assert.Nil(t, err)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user