Linting fixes.
This commit is contained in:
parent
008908029b
commit
99f305ddff
26
.golangci.yml
Normal file
26
.golangci.yml
Normal 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
1
env/env.go
vendored
@ -140,6 +140,7 @@ type environmentData struct {
|
|||||||
|
|
||||||
func ParseEnv() {
|
func ParseEnv() {
|
||||||
Data = &environmentData{}
|
Data = &environmentData{}
|
||||||
|
|
||||||
err := envconfig.Init(Data)
|
err := envconfig.Init(Data)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(err)
|
fmt.Println(err)
|
||||||
|
1
main.go
1
main.go
@ -12,6 +12,7 @@ import (
|
|||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
env.ParseEnv()
|
env.ParseEnv()
|
||||||
|
|
||||||
if env.Data.Debug {
|
if env.Data.Debug {
|
||||||
log.Printf("Starting Discordrone with parameters: %+v\n", env.Data)
|
log.Printf("Starting Discordrone with parameters: %+v\n", env.Data)
|
||||||
}
|
}
|
||||||
|
@ -3,11 +3,11 @@ package message
|
|||||||
type (
|
type (
|
||||||
// Payload that will be sent to Discord.
|
// Payload that will be sent to Discord.
|
||||||
payload struct {
|
payload struct {
|
||||||
|
TTS bool `json:"tts"`
|
||||||
Wait bool `json:"wait"`
|
Wait bool `json:"wait"`
|
||||||
|
AvatarURL string `json:"avatar_url"`
|
||||||
Content string `json:"content"`
|
Content string `json:"content"`
|
||||||
Username string `json:"username"`
|
Username string `json:"username"`
|
||||||
AvatarURL string `json:"avatar_url"`
|
|
||||||
TTS bool `json:"tts"`
|
|
||||||
Embeds []EmbedObject `json:"embeds"`
|
Embeds []EmbedObject `json:"embeds"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -44,7 +44,9 @@ func Process() error {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
p.Content = text
|
p.Content = text
|
||||||
|
|
||||||
err1 := sendMessage(p)
|
err1 := sendMessage(p)
|
||||||
if err1 != nil {
|
if err1 != nil {
|
||||||
return err1
|
return err1
|
||||||
|
@ -15,10 +15,14 @@ import (
|
|||||||
func sendMessage(message interface{}) error {
|
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)
|
webhookURL := fmt.Sprintf("https://discordapp.com/api/webhooks/%s/%s", env.Data.Plugin.Webhook.ID, env.Data.Plugin.Webhook.Token)
|
||||||
b := new(bytes.Buffer)
|
b := new(bytes.Buffer)
|
||||||
|
|
||||||
if err := json.NewEncoder(b).Encode(message); err != nil {
|
if err := json.NewEncoder(b).Encode(message); err != nil {
|
||||||
return err
|
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 {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -24,7 +24,7 @@ func createEmbed() EmbedObject {
|
|||||||
|
|
||||||
// Compose description.
|
// Compose description.
|
||||||
var description string
|
var description string
|
||||||
// ToDo: promote/rollback?
|
// Add promote/rollback?
|
||||||
switch env.Data.Drone.Build.Event {
|
switch env.Data.Drone.Build.Event {
|
||||||
case "pull_request":
|
case "pull_request":
|
||||||
var branch string
|
var branch string
|
||||||
@ -33,6 +33,7 @@ func createEmbed() EmbedObject {
|
|||||||
} else {
|
} else {
|
||||||
branch = env.Data.Drone.Commit.Branch
|
branch = env.Data.Drone.Commit.Branch
|
||||||
}
|
}
|
||||||
|
|
||||||
description = env.Data.Drone.Commit.Author.Name + " updated pull request " + branch
|
description = env.Data.Drone.Commit.Author.Name + " updated pull request " + branch
|
||||||
case "push":
|
case "push":
|
||||||
description = env.Data.Drone.Commit.Author.Name + " pushed to " + env.Data.Drone.Commit.Branch
|
description = env.Data.Drone.Commit.Author.Name + " pushed to " + env.Data.Drone.Commit.Branch
|
||||||
@ -44,14 +45,15 @@ func createEmbed() EmbedObject {
|
|||||||
|
|
||||||
// Compose color.
|
// Compose color.
|
||||||
var color int64
|
var color int64
|
||||||
|
|
||||||
if env.Data.Plugin.Color != "" {
|
if env.Data.Plugin.Color != "" {
|
||||||
env.Data.Plugin.Color = strings.Replace(env.Data.Plugin.Color, "#", "", -1)
|
env.Data.Plugin.Color = strings.Replace(env.Data.Plugin.Color, "#", "", -1)
|
||||||
|
|
||||||
s, err := strconv.ParseInt(env.Data.Plugin.Color, 16, 32)
|
s, err := strconv.ParseInt(env.Data.Plugin.Color, 16, 32)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
color = s
|
color = s
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
switch env.Data.Drone.Build.Status {
|
switch env.Data.Drone.Build.Status {
|
||||||
case "success":
|
case "success":
|
||||||
// green
|
// green
|
||||||
|
Reference in New Issue
Block a user