Linting fixes.

This commit is contained in:
Stanislav Nikitin 2019-10-16 23:29:53 +05:00
parent 008908029b
commit 99f305ddff
No known key found for this signature in database
GPG Key ID: 106900B32F8192EE
7 changed files with 41 additions and 5 deletions

26
.golangci.yml Normal file
View File

@ -0,0 +1,26 @@
run:
deadline: 5m
linters:
enable-all: true
disable:
# Because globals might exist, but according to our codestyle they
# should be lowercased and considered as unexported.
- gochecknoglobals
# While it might be useful it'll create more problems that will solve.
- gocritic
# Complains about main() lengths, which isn't an issue.
- funlen
linters-settings:
lll:
line-length: 420
gocyclo:
min-complexity: 40
issues:
exclude-rules:
# gosec says that there is a "Potential HTTP request made with
# variable URL". Well, he's right, we're composing webhook URL
# based on user's input. We do not need that linting here.
- linters:
- gosec
text: "G107: "

1
env/env.go vendored
View File

@ -140,6 +140,7 @@ type environmentData struct {
func ParseEnv() {
Data = &environmentData{}
err := envconfig.Init(Data)
if err != nil {
fmt.Println(err)

View File

@ -12,6 +12,7 @@ import (
func main() {
env.ParseEnv()
if env.Data.Debug {
log.Printf("Starting Discordrone with parameters: %+v\n", env.Data)
}

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