gitea-sonarqube-bot/internal/webhooks/sonarqube/webhook.go
justusbunsi 5082e5d3f3
Use OOP-ish style for SonarQube webhook handling
Signed-off-by: Steven Kriegler <61625851+justusbunsi@users.noreply.github.com>
2021-06-29 12:27:01 +02:00

42 lines
640 B
Go

package sonarqube
import (
"bytes"
"log"
"github.com/spf13/viper"
)
type Webhook struct {
ServerUrl string `mapstructure:"serverUrl"`
Revision string
Branch struct {
Name string
Type string
Url string
}
QualityGate struct {
Status string
Conditions []struct {
Metric string
Status string
}
} `mapstructure:"qualityGate"`
}
func New(raw []byte) (*Webhook, bool) {
v := viper.New()
v.SetConfigType("json")
v.ReadConfig(bytes.NewBuffer(raw))
w := &Webhook{}
err := v.Unmarshal(&w)
if err != nil {
log.Printf("Error parsing SonarQube webhook: %s", err.Error())
return w, false
}
return w, true
}