forked from adamm/autogits
57 lines
1.3 KiB
Go
57 lines
1.3 KiB
Go
package main
|
|
|
|
import (
|
|
"fmt"
|
|
"slices"
|
|
|
|
"src.opensuse.org/autogits/common"
|
|
)
|
|
|
|
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
|
|
}
|