Add status-check to PR/commit
Signed-off-by: Steven Kriegler <61625851+justusbunsi@users.noreply.github.com>
This commit is contained in:
parent
d24bfdad4f
commit
34dbd4f609
|
@ -3,12 +3,14 @@ package gitea_sdk
|
|||
import (
|
||||
"fmt"
|
||||
"gitea-sonarqube-pr-bot/internal/settings"
|
||||
webhook "gitea-sonarqube-pr-bot/internal/webhooks/sonarqube"
|
||||
|
||||
"code.gitea.io/sdk/gitea"
|
||||
)
|
||||
|
||||
type GiteaSdkInterface interface {
|
||||
PostComment(settings.GiteaRepository, int, string) error
|
||||
UpdateStatus(settings.GiteaRepository, *webhook.Webhook) error
|
||||
}
|
||||
|
||||
type GiteaSdk struct {
|
||||
|
@ -25,6 +27,26 @@ func (sdk *GiteaSdk) PostComment(repo settings.GiteaRepository, idx int, msg str
|
|||
return err
|
||||
}
|
||||
|
||||
func (sdk *GiteaSdk) UpdateStatus(repo settings.GiteaRepository, w *webhook.Webhook) error {
|
||||
status := gitea.StatusPending
|
||||
switch w.QualityGate.Status {
|
||||
case "OK":
|
||||
status = gitea.StatusSuccess
|
||||
case "ERROR":
|
||||
status = gitea.StatusFailure
|
||||
}
|
||||
opt := gitea.CreateStatusOption{
|
||||
TargetURL: w.Branch.Url,
|
||||
Context: "gitea-sonarqube-pr-bot",
|
||||
Description: w.QualityGate.Status,
|
||||
State: status,
|
||||
}
|
||||
|
||||
_, _, err := sdk.client.CreateStatus(repo.Owner, repo.Name, w.Revision, opt)
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
func New() *GiteaSdk {
|
||||
client, err := gitea.NewClient(settings.Gitea.Url, gitea.SetToken(settings.Gitea.Token.Value))
|
||||
if err != nil {
|
||||
|
|
|
@ -54,6 +54,11 @@ func (h *SonarQubeWebhookHandler) processData(w *webhook.Webhook, repo settings.
|
|||
|
||||
h.fetchDetails(w)
|
||||
|
||||
err := h.giteaSdk.UpdateStatus(repo, w)
|
||||
if err != nil {
|
||||
log.Printf("Error updating status: %s", err.Error())
|
||||
}
|
||||
|
||||
comment, err := h.composeGiteaComment(w)
|
||||
if err != nil {
|
||||
log.Printf("Error composing Gitea comment: %s", err.Error())
|
||||
|
|
Loading…
Reference in a new issue