2021-06-24 14:38:04 +02:00
|
|
|
package sonarqube
|
|
|
|
|
|
|
|
import (
|
|
|
|
"bytes"
|
|
|
|
"log"
|
|
|
|
|
|
|
|
"github.com/spf13/viper"
|
|
|
|
)
|
|
|
|
|
|
|
|
type Webhook struct {
|
|
|
|
ServerUrl string `mapstructure:"serverUrl"`
|
|
|
|
Revision string
|
2021-06-29 08:07:28 +02:00
|
|
|
Branch branch
|
|
|
|
QualityGate qualityGate `mapstructure:"qualityGate"`
|
2021-06-24 14:38:04 +02:00
|
|
|
}
|
|
|
|
|
2021-06-29 08:07:28 +02:00
|
|
|
type branch struct {
|
2021-06-24 14:38:04 +02:00
|
|
|
Name string
|
|
|
|
Type string
|
|
|
|
Url string
|
|
|
|
}
|
|
|
|
|
2021-06-29 08:07:28 +02:00
|
|
|
type qualityGate struct {
|
2021-06-24 14:38:04 +02:00
|
|
|
Status string
|
2021-06-29 08:07:28 +02:00
|
|
|
Conditions []condition
|
2021-06-24 14:38:04 +02:00
|
|
|
}
|
|
|
|
|
2021-06-29 08:07:28 +02:00
|
|
|
type condition struct {
|
2021-06-24 14:38:04 +02:00
|
|
|
Metric string
|
|
|
|
Status string
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewWebhook(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 nil, false
|
|
|
|
}
|
|
|
|
|
|
|
|
return &w, true
|
|
|
|
}
|