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 {
|
||||
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)
|
||||
}
|
||||
|
||||
|
@ -28,14 +28,16 @@ func (sdk *GiteaSdk) PostComment(repo settings.GiteaRepository, idx int, msg str
|
|||
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{
|
||||
TargetURL: targetUrl,
|
||||
TargetURL: details.Url,
|
||||
Context: "gitea-sonarqube-pr-bot",
|
||||
Description: description,
|
||||
State: status,
|
||||
Description: details.Message,
|
||||
State: gitea.StatusState(details.State),
|
||||
}
|
||||
|
||||
opt.TargetURL = "gitea-sonarqube-pr-bot"
|
||||
|
||||
_, _, err := sdk.client.CreateStatus(repo.Owner, repo.Name, ref, opt)
|
||||
if err != nil {
|
||||
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"
|
||||
"gitea-sonarqube-pr-bot/internal/settings"
|
||||
webhook "gitea-sonarqube-pr-bot/internal/webhooks/sonarqube"
|
||||
|
||||
"code.gitea.io/sdk/gitea"
|
||||
)
|
||||
|
||||
type SonarQubeWebhookHandler struct {
|
||||
|
@ -56,14 +54,15 @@ func (h *SonarQubeWebhookHandler) processData(w *webhook.Webhook, repo settings.
|
|||
|
||||
h.fetchDetails(w)
|
||||
|
||||
status := gitea.StatusPending
|
||||
switch w.QualityGate.Status {
|
||||
case "OK":
|
||||
status = gitea.StatusSuccess
|
||||
case "ERROR":
|
||||
status = gitea.StatusFailure
|
||||
status := giteaSdk.StatusOK
|
||||
if w.QualityGate.Status != "OK" {
|
||||
status = giteaSdk.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)
|
||||
if err != nil {
|
||||
|
|
|
@ -6,11 +6,11 @@ import (
|
|||
"net/http/httptest"
|
||||
"testing"
|
||||
|
||||
giteaSDK "gitea-sonarqube-pr-bot/internal/clients/gitea_sdk"
|
||||
sqSDK "gitea-sonarqube-pr-bot/internal/clients/sonarqube_sdk"
|
||||
"gitea-sonarqube-pr-bot/internal/settings"
|
||||
webhook "gitea-sonarqube-pr-bot/internal/webhooks/sonarqube"
|
||||
|
||||
"code.gitea.io/sdk/gitea"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/mock"
|
||||
)
|
||||
|
@ -35,7 +35,7 @@ func (h *GiteaSdkMock) DetermineHEAD(_ settings.GiteaRepository, _ int64) (strin
|
|||
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
|
||||
}
|
||||
|
||||
|
|
|
@ -9,8 +9,6 @@ import (
|
|||
giteaSdk "gitea-sonarqube-pr-bot/internal/clients/gitea_sdk"
|
||||
sqSdk "gitea-sonarqube-pr-bot/internal/clients/sonarqube_sdk"
|
||||
"gitea-sonarqube-pr-bot/internal/settings"
|
||||
|
||||
"code.gitea.io/sdk/gitea"
|
||||
)
|
||||
|
||||
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())
|
||||
return
|
||||
}
|
||||
_ = gSDK.UpdateStatus(w.ConfiguredProject.Gitea, headRef, "", "Analysis pending...", gitea.StatusPending)
|
||||
|
||||
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) {
|
||||
|
|
Loading…
Reference in a new issue