From 1a5b8eaa1fbc64de0fdebdd7285e239dd3088242 Mon Sep 17 00:00:00 2001 From: Bo-Yi Wu Date: Sat, 17 Jun 2017 00:37:22 +0800 Subject: [PATCH] update discord default template. Signed-off-by: Bo-Yi Wu --- plugin.go | 23 ++++++++++++++++++----- plugin_test.go | 5 +++-- 2 files changed, 21 insertions(+), 7 deletions(-) diff --git a/plugin.go b/plugin.go index 3312e0b..558a6e5 100644 --- a/plugin.go +++ b/plugin.go @@ -47,7 +47,8 @@ type ( // EmbedFooterObject for Embed Footer Structure. EmbedFooterObject struct { - Text string `json:"text"` + Text string `json:"text"` + IconURL string `json:"icon_url"` } // EmbedAuthorObject for Embed Author Structure @@ -145,17 +146,29 @@ func (p *Plugin) Send() error { // Message is plugin default message. func (p *Plugin) Message() { + description := "" + switch p.Build.Event { + case "push": + description = fmt.Sprintf("%s pushed to %s", p.Build.Author, p.Build.Branch) + case "pull_request": + description = fmt.Sprintf("%s created pull request %s", p.Build.Author, p.Build.Branch) + case "tag": + description = fmt.Sprintf("%s pushed tag %s", p.Build.Author, p.Build.Branch) + } + p.Payload.Embeds = []EmbedObject{ { - Title: p.Build.Message, - URL: p.Build.Link, - Color: p.Color(), + Title: p.Build.Message, + Description: description, + URL: p.Build.Link, + Color: p.Color(), Author: EmbedAuthorObject{ Name: p.Build.Author, IconURL: p.Build.Avatar, }, Footer: EmbedFooterObject{ - Text: "Powered by Drone Discord Plugin", + Text: "Powered by Drone Discord Plugin", + IconURL: "https://c1.staticflickr.com/5/4236/34957940160_435d83114f_z.jpg", }, }, } diff --git a/plugin_test.go b/plugin_test.go index 8398726..cc19198 100644 --- a/plugin_test.go +++ b/plugin_test.go @@ -26,9 +26,10 @@ func TestSendMessage(t *testing.T) { Number: 101, Status: "success", Link: "https://github.com/appleboy/go-hello", - Author: "Bo-Yi Wu", + Author: "appleboy", Branch: "master", - Message: "update by drone discord plugin. \n update by drone discord plugin.", + Event: "tag", + Message: "update by drone discord plugin. \r\n update by drone discord plugin.", Commit: "e7c4f0a63ceeb42a39ac7806f7b51f3f0d204fd2", Avatar: "https://avatars0.githubusercontent.com/u/21979?v=3&s=100", },