Reduce UpdateStatus
parameter mess
Signed-off-by: Steven Kriegler <61625851+justusbunsi@users.noreply.github.com>
This commit is contained in:
parent
57fc8054b2
commit
e20b1469d3
|
@ -10,7 +10,7 @@ import (
|
||||||
|
|
||||||
type GiteaSdkInterface interface {
|
type GiteaSdkInterface interface {
|
||||||
PostComment(settings.GiteaRepository, int, string) error
|
PostComment(settings.GiteaRepository, int, string) error
|
||||||
UpdateStatus(settings.GiteaRepository, string, string, string, gitea.StatusState) error
|
UpdateStatus(settings.GiteaRepository, string, StatusDetails) error
|
||||||
DetermineHEAD(settings.GiteaRepository, int64) (string, error)
|
DetermineHEAD(settings.GiteaRepository, int64) (string, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -28,14 +28,16 @@ func (sdk *GiteaSdk) PostComment(repo settings.GiteaRepository, idx int, msg str
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (sdk *GiteaSdk) UpdateStatus(repo settings.GiteaRepository, ref string, targetUrl string, description string, status gitea.StatusState) error {
|
func (sdk *GiteaSdk) UpdateStatus(repo settings.GiteaRepository, ref string, details StatusDetails) error {
|
||||||
opt := gitea.CreateStatusOption{
|
opt := gitea.CreateStatusOption{
|
||||||
TargetURL: targetUrl,
|
TargetURL: details.Url,
|
||||||
Context: "gitea-sonarqube-pr-bot",
|
Context: "gitea-sonarqube-pr-bot",
|
||||||
Description: description,
|
Description: details.Message,
|
||||||
State: status,
|
State: gitea.StatusState(details.State),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
opt.TargetURL = "gitea-sonarqube-pr-bot"
|
||||||
|
|
||||||
_, _, err := sdk.client.CreateStatus(repo.Owner, repo.Name, ref, opt)
|
_, _, err := sdk.client.CreateStatus(repo.Owner, repo.Name, ref, opt)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("Error updating status: %s", err.Error())
|
log.Printf("Error updating status: %s", err.Error())
|
||||||
|
|
16
internal/clients/gitea_sdk/status.go
Normal file
16
internal/clients/gitea_sdk/status.go
Normal file
|
@ -0,0 +1,16 @@
|
||||||
|
package gitea_sdk
|
||||||
|
|
||||||
|
import "code.gitea.io/sdk/gitea"
|
||||||
|
|
||||||
|
type State gitea.StatusState
|
||||||
|
|
||||||
|
const (
|
||||||
|
StatusOK State = State(gitea.StatusSuccess)
|
||||||
|
StatusFailure State = State(gitea.StatusFailure)
|
||||||
|
)
|
||||||
|
|
||||||
|
type StatusDetails struct {
|
||||||
|
Url string
|
||||||
|
Message string
|
||||||
|
State State
|
||||||
|
}
|
|
@ -12,8 +12,6 @@ import (
|
||||||
sqSdk "gitea-sonarqube-pr-bot/internal/clients/sonarqube_sdk"
|
sqSdk "gitea-sonarqube-pr-bot/internal/clients/sonarqube_sdk"
|
||||||
"gitea-sonarqube-pr-bot/internal/settings"
|
"gitea-sonarqube-pr-bot/internal/settings"
|
||||||
webhook "gitea-sonarqube-pr-bot/internal/webhooks/sonarqube"
|
webhook "gitea-sonarqube-pr-bot/internal/webhooks/sonarqube"
|
||||||
|
|
||||||
"code.gitea.io/sdk/gitea"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type SonarQubeWebhookHandler struct {
|
type SonarQubeWebhookHandler struct {
|
||||||
|
@ -56,14 +54,15 @@ func (h *SonarQubeWebhookHandler) processData(w *webhook.Webhook, repo settings.
|
||||||
|
|
||||||
h.fetchDetails(w)
|
h.fetchDetails(w)
|
||||||
|
|
||||||
status := gitea.StatusPending
|
status := giteaSdk.StatusOK
|
||||||
switch w.QualityGate.Status {
|
if w.QualityGate.Status != "OK" {
|
||||||
case "OK":
|
status = giteaSdk.StatusFailure
|
||||||
status = gitea.StatusSuccess
|
|
||||||
case "ERROR":
|
|
||||||
status = gitea.StatusFailure
|
|
||||||
}
|
}
|
||||||
_ = h.giteaSdk.UpdateStatus(repo, w.Revision, w.Branch.Url, w.QualityGate.Status, status)
|
_ = h.giteaSdk.UpdateStatus(repo, w.Revision, giteaSdk.StatusDetails{
|
||||||
|
Url: w.Branch.Url,
|
||||||
|
Message: w.QualityGate.Status,
|
||||||
|
State: status,
|
||||||
|
})
|
||||||
|
|
||||||
comment, err := h.composeGiteaComment(w)
|
comment, err := h.composeGiteaComment(w)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -6,11 +6,11 @@ import (
|
||||||
"net/http/httptest"
|
"net/http/httptest"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
giteaSDK "gitea-sonarqube-pr-bot/internal/clients/gitea_sdk"
|
||||||
sqSDK "gitea-sonarqube-pr-bot/internal/clients/sonarqube_sdk"
|
sqSDK "gitea-sonarqube-pr-bot/internal/clients/sonarqube_sdk"
|
||||||
"gitea-sonarqube-pr-bot/internal/settings"
|
"gitea-sonarqube-pr-bot/internal/settings"
|
||||||
webhook "gitea-sonarqube-pr-bot/internal/webhooks/sonarqube"
|
webhook "gitea-sonarqube-pr-bot/internal/webhooks/sonarqube"
|
||||||
|
|
||||||
"code.gitea.io/sdk/gitea"
|
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
"github.com/stretchr/testify/mock"
|
"github.com/stretchr/testify/mock"
|
||||||
)
|
)
|
||||||
|
@ -35,7 +35,7 @@ func (h *GiteaSdkMock) DetermineHEAD(_ settings.GiteaRepository, _ int64) (strin
|
||||||
return "", nil
|
return "", nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *GiteaSdkMock) UpdateStatus(_ settings.GiteaRepository, _ string, _ string, _ string, _ gitea.StatusState) error {
|
func (h *GiteaSdkMock) UpdateStatus(_ settings.GiteaRepository, _ string, _ giteaSDK.StatusDetails) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -9,8 +9,6 @@ import (
|
||||||
giteaSdk "gitea-sonarqube-pr-bot/internal/clients/gitea_sdk"
|
giteaSdk "gitea-sonarqube-pr-bot/internal/clients/gitea_sdk"
|
||||||
sqSdk "gitea-sonarqube-pr-bot/internal/clients/sonarqube_sdk"
|
sqSdk "gitea-sonarqube-pr-bot/internal/clients/sonarqube_sdk"
|
||||||
"gitea-sonarqube-pr-bot/internal/settings"
|
"gitea-sonarqube-pr-bot/internal/settings"
|
||||||
|
|
||||||
"code.gitea.io/sdk/gitea"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type BotAction string
|
type BotAction string
|
||||||
|
@ -77,11 +75,13 @@ func (w *Webhook) ProcessData(gSDK giteaSdk.GiteaSdkInterface, sqSDK sqSdk.Sonar
|
||||||
log.Printf("Error retrieving HEAD ref: %s", err.Error())
|
log.Printf("Error retrieving HEAD ref: %s", err.Error())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
_ = gSDK.UpdateStatus(w.ConfiguredProject.Gitea, headRef, "", "Analysis pending...", gitea.StatusPending)
|
|
||||||
|
|
||||||
log.Printf("Fetching SonarQube data...")
|
log.Printf("Fetching SonarQube data...")
|
||||||
|
|
||||||
_ = gSDK.UpdateStatus(w.ConfiguredProject.Gitea, headRef, "", "OK", gitea.StatusSuccess)
|
_ = gSDK.UpdateStatus(w.ConfiguredProject.Gitea, headRef, giteaSdk.StatusDetails{
|
||||||
|
Url: "",
|
||||||
|
Message: "OK",
|
||||||
|
State: giteaSdk.StatusOK,
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func New(raw []byte) (*Webhook, bool) {
|
func New(raw []byte) (*Webhook, bool) {
|
||||||
|
|
Loading…
Reference in a new issue