Files
autogits/group-review/rabbit.go
2026-01-07 10:27:12 +01:00

79 lines
1.9 KiB
Go

package main
import (
"fmt"
"slices"
"src.opensuse.org/autogits/common"
)
type IssueCommentProcessor struct {
bot *ReviewBot
}
func (s *IssueCommentProcessor) ProcessFunc(req *common.Request) error {
if req.Type != common.RequestType_IssueComment {
return fmt.Errorf("Unhandled, ignored request type: %s", req.Type)
}
data := req.Data.(*common.IssueCommentWebhookEvent)
org := data.Repository.Owner.Username
repo := data.Repository.Name
index := int64(data.Issue.Number)
pr, err := s.bot.gitea.GetPullRequest(org, repo, index)
if err != nil {
return fmt.Errorf("Failed to fetch PullRequest from event: %s/%s!%d Error: %w", org, repo, index, err)
}
return s.bot.ProcessPR(pr)
}
type ConfigUpdatePush struct {
bot *ReviewBot
config_modified chan *common.AutogitConfig
}
func (s *ConfigUpdatePush) ProcessFunc(req *common.Request) error {
if req.Type != common.RequestType_Push {
return fmt.Errorf("Unhandled, ignored request type: %s", req.Type)
}
data := req.Data.(*common.PushWebhookEvent)
org := data.Repository.Owner.Username
repo := data.Repository.Name
const branch_ref = "refs/heads/"
if data.Ref[:len(branch_ref)] != branch_ref {
return fmt.Errorf("No branch updated. Ref: %s", data.Ref)
}
branch := data.Ref[len(branch_ref):]
c := s.bot.configs.GetPrjGitConfig(org, repo, branch)
if c == nil {
return nil
}
if o, p, b := c.GetPrjGit(); o != org || p != repo || b != branch {
return nil
}
modified_config := false
for _, commit := range data.Commits {
modified_config = modified_config ||
slices.Contains(commit.Modified, common.ProjectConfigFile) ||
slices.Contains(commit.Added, common.ProjectConfigFile) ||
slices.Contains(commit.Removed, common.ProjectConfigFile)
}
if modified_config {
for _, config := range s.bot.configs {
if o, r, _ := config.GetPrjGit(); o == org && r == repo {
s.config_modified <- config
}
}
}
return nil
}