Centralize bot actions
Signed-off-by: Steven Kriegler <61625851+justusbunsi@users.noreply.github.com>
This commit is contained in:
parent
c99925abb3
commit
bf453c6c43
8
internal/actions/actions.go
Normal file
8
internal/actions/actions.go
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
package actions
|
||||||
|
|
||||||
|
type BotAction string
|
||||||
|
|
||||||
|
const (
|
||||||
|
ActionReview BotAction = "/sq-bot review"
|
||||||
|
ActionPrefix string = "/sq-bot"
|
||||||
|
)
|
|
@ -8,6 +8,7 @@ import (
|
||||||
"net/http"
|
"net/http"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"gitea-sonarqube-pr-bot/internal/actions"
|
||||||
giteaSdk "gitea-sonarqube-pr-bot/internal/clients/gitea"
|
giteaSdk "gitea-sonarqube-pr-bot/internal/clients/gitea"
|
||||||
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"
|
||||||
|
@ -31,7 +32,7 @@ func (h *SonarQubeWebhookHandler) composeGiteaComment(w *webhook.Webhook) (strin
|
||||||
message[1] = m.GetRenderedMarkdownTable()
|
message[1] = m.GetRenderedMarkdownTable()
|
||||||
message[2] = fmt.Sprintf("See [SonarQube](%s) for details.", w.Branch.Url)
|
message[2] = fmt.Sprintf("See [SonarQube](%s) for details.", w.Branch.Url)
|
||||||
message[3] = "---"
|
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
|
return strings.Join(message, "\n\n"), nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,17 +6,12 @@ import (
|
||||||
"log"
|
"log"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"gitea-sonarqube-pr-bot/internal/actions"
|
||||||
giteaSdk "gitea-sonarqube-pr-bot/internal/clients/gitea"
|
giteaSdk "gitea-sonarqube-pr-bot/internal/clients/gitea"
|
||||||
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"
|
||||||
)
|
)
|
||||||
|
|
||||||
type BotAction string
|
|
||||||
|
|
||||||
const (
|
|
||||||
ActionReview BotAction = "/pr-bot review"
|
|
||||||
)
|
|
||||||
|
|
||||||
type issue struct {
|
type issue struct {
|
||||||
Number int64 `json:"number"`
|
Number int64 `json:"number"`
|
||||||
Repository settings.GiteaRepository `json:"repository"`
|
Repository settings.GiteaRepository `json:"repository"`
|
||||||
|
@ -60,7 +55,7 @@ func (w *Webhook) Validate() error {
|
||||||
return fmt.Errorf("ignore hook for action others than created")
|
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")
|
return fmt.Errorf("ignore hook for non-bot action comment")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue