Add status-check to PR/commit

Signed-off-by: Steven Kriegler <61625851+justusbunsi@users.noreply.github.com>
This commit is contained in:
justusbunsi 2021-10-09 20:45:21 +02:00
parent d24bfdad4f
commit 34dbd4f609
No known key found for this signature in database
GPG key ID: 990B348ECAC9C7DB
2 changed files with 27 additions and 0 deletions

View file

@ -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 {

View file

@ -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())