Linting fixes.

This commit is contained in:
2019-10-16 23:29:53 +05:00
parent 008908029b
commit 99f305ddff
7 changed files with 41 additions and 5 deletions

View File

@@ -3,11 +3,11 @@ package message
type (
// Payload that will be sent to Discord.
payload struct {
TTS bool `json:"tts"`
Wait bool `json:"wait"`
AvatarURL string `json:"avatar_url"`
Content string `json:"content"`
Username string `json:"username"`
AvatarURL string `json:"avatar_url"`
TTS bool `json:"tts"`
Embeds []EmbedObject `json:"embeds"`
}

View File

@@ -44,7 +44,9 @@ func Process() error {
if err != nil {
return err
}
p.Content = text
err1 := sendMessage(p)
if err1 != nil {
return err1

View File

@@ -15,10 +15,14 @@ import (
func sendMessage(message interface{}) error {
webhookURL := fmt.Sprintf("https://discordapp.com/api/webhooks/%s/%s", env.Data.Plugin.Webhook.ID, env.Data.Plugin.Webhook.Token)
b := new(bytes.Buffer)
if err := json.NewEncoder(b).Encode(message); err != nil {
return err
}
_, err := http.Post(webhookURL, "application/json; charset=utf-8", b)
resp, err := http.Post(webhookURL, "application/json; charset=utf-8", b)
// We do not need response's body.
resp.Body.Close()
if err != nil {
return err

View File

@@ -24,7 +24,7 @@ func createEmbed() EmbedObject {
// Compose description.
var description string
// ToDo: promote/rollback?
// Add promote/rollback?
switch env.Data.Drone.Build.Event {
case "pull_request":
var branch string
@@ -33,6 +33,7 @@ func createEmbed() EmbedObject {
} else {
branch = env.Data.Drone.Commit.Branch
}
description = env.Data.Drone.Commit.Author.Name + " updated pull request " + branch
case "push":
description = env.Data.Drone.Commit.Author.Name + " pushed to " + env.Data.Drone.Commit.Branch
@@ -44,14 +45,15 @@ func createEmbed() EmbedObject {
// Compose color.
var color int64
if env.Data.Plugin.Color != "" {
env.Data.Plugin.Color = strings.Replace(env.Data.Plugin.Color, "#", "", -1)
s, err := strconv.ParseInt(env.Data.Plugin.Color, 16, 32)
if err == nil {
color = s
}
} else {
switch env.Data.Drone.Build.Status {
case "success":
// green