Centralize bot actions

Signed-off-by: Steven Kriegler <61625851+justusbunsi@users.noreply.github.com>
This commit is contained in:
justusbunsi 2021-10-10 16:39:26 +02:00
parent c99925abb3
commit bf453c6c43
No known key found for this signature in database
GPG key ID: 990B348ECAC9C7DB
3 changed files with 12 additions and 8 deletions

View file

@ -0,0 +1,8 @@
package actions
type BotAction string
const (
ActionReview BotAction = "/sq-bot review"
ActionPrefix string = "/sq-bot"
)

View file

@ -8,6 +8,7 @@ import (
"net/http"
"strings"
"gitea-sonarqube-pr-bot/internal/actions"
giteaSdk "gitea-sonarqube-pr-bot/internal/clients/gitea"
sqSdk "gitea-sonarqube-pr-bot/internal/clients/sonarqube_sdk"
"gitea-sonarqube-pr-bot/internal/settings"
@ -31,7 +32,7 @@ func (h *SonarQubeWebhookHandler) composeGiteaComment(w *webhook.Webhook) (strin
message[1] = m.GetRenderedMarkdownTable()
message[2] = fmt.Sprintf("See [SonarQube](%s) for details.", w.Branch.Url)
message[3] = "---"
message[4] = "- If you want the bot to check again, post `/sq-bot review`"
message[4] = fmt.Sprintf("- If you want the bot to check again, post `%s`", actions.ActionReview)
return strings.Join(message, "\n\n"), nil
}

View file

@ -6,17 +6,12 @@ import (
"log"
"strings"
"gitea-sonarqube-pr-bot/internal/actions"
giteaSdk "gitea-sonarqube-pr-bot/internal/clients/gitea"
sqSdk "gitea-sonarqube-pr-bot/internal/clients/sonarqube_sdk"
"gitea-sonarqube-pr-bot/internal/settings"
)
type BotAction string
const (
ActionReview BotAction = "/pr-bot review"
)
type issue struct {
Number int64 `json:"number"`
Repository settings.GiteaRepository `json:"repository"`
@ -60,7 +55,7 @@ func (w *Webhook) Validate() error {
return fmt.Errorf("ignore hook for action others than created")
}
if !strings.HasPrefix(w.Comment.Body, "/pr-bot") {
if !strings.HasPrefix(w.Comment.Body, actions.ActionPrefix) {
return fmt.Errorf("ignore hook for non-bot action comment")
}