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 11:59:49 +02:00
|
|
|
Branch struct {
|
|
|
|
Name string
|
|
|
|
Type string
|
|
|
|
Url string
|
|
|
|
}
|
|
|
|
QualityGate struct {
|
|
|
|
Status string
|
|
|
|
Conditions []struct {
|
|
|
|
Metric string
|
|
|
|
Status string
|
|
|
|
}
|
|
|
|
} `mapstructure:"qualityGate"`
|
2021-06-24 14:38:04 +02:00
|
|
|
}
|
|
|
|
|
2021-06-29 11:59:49 +02:00
|
|
|
func New(raw []byte) (*Webhook, bool) {
|
2021-06-24 14:38:04 +02:00
|
|
|
v := viper.New()
|
|
|
|
v.SetConfigType("json")
|
|
|
|
v.ReadConfig(bytes.NewBuffer(raw))
|
|
|
|
|
2021-06-29 11:59:49 +02:00
|
|
|
w := &Webhook{}
|
2021-06-24 14:38:04 +02:00
|
|
|
|
|
|
|
err := v.Unmarshal(&w)
|
|
|
|
if err != nil {
|
|
|
|
log.Printf("Error parsing SonarQube webhook: %s", err.Error())
|
2021-06-29 11:59:49 +02:00
|
|
|
return w, false
|
2021-06-24 14:38:04 +02:00
|
|
|
}
|
|
|
|
|
2021-06-29 11:59:49 +02:00
|
|
|
return w, true
|
2021-06-24 14:38:04 +02:00
|
|
|
}
|