package main import ( "fmt" "slices" "src.opensuse.org/autogits/common" ) type IssueCommentProcessor struct{} 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 := 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 ProcessPR(pr) } type ConfigUpdatePush struct { 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 := 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 configs { if o, r, _ := config.GetPrjGit(); o == org && r == repo { s.config_modified <- config } } } return nil }