.
This commit is contained in:
parent
a4d2010ca0
commit
c380674a71
@ -10,10 +10,10 @@ import (
|
||||
)
|
||||
|
||||
type AutogitConfig struct {
|
||||
Workflows []string
|
||||
Workflows []string // [pr, direct, test]
|
||||
Organization string
|
||||
GitProjectName string
|
||||
Branch string
|
||||
GitProjectName string // Organization/GitProjectName.git is PrjGit
|
||||
Branch string // branch name of PkgGit that aligns with PrjGit submodules
|
||||
}
|
||||
|
||||
func ReadWorkflowConfigs(reader io.Reader) ([]*AutogitConfig, error) {
|
||||
@ -27,7 +27,7 @@ func ReadWorkflowConfigs(reader io.Reader) ([]*AutogitConfig, error) {
|
||||
return nil, fmt.Errorf("Error parsing config file. err: %w", err)
|
||||
}
|
||||
|
||||
availableWorkflows := []string{"pr", "push", "test"}
|
||||
availableWorkflows := []string{"pr", "direct", "test"}
|
||||
for _, workflow := range config {
|
||||
for _, w := range workflow.Workflows {
|
||||
if !slices.Contains(availableWorkflows, w) {
|
||||
|
@ -21,30 +21,53 @@ type ConfigRepos struct {
|
||||
|
||||
var configuredRepos map[string]ConfigRepos
|
||||
|
||||
func isConfiguredOrg(org *common.Organization) bool {
|
||||
_, found := configuredRepos[org.Username]
|
||||
return found
|
||||
}
|
||||
|
||||
func processRepositoryAction(h *common.RequestHandler) error {
|
||||
action := h.Request.Data.(*common.RepositoryWebhookEvent)
|
||||
config, configFound := configuredRepos[action.Organization.Username]
|
||||
|
||||
if action.Repository.Name == common.DefaultGitPrj {
|
||||
h.StdLogger.Printf("repository event %s for %s. Ignoring\n", common.DefaultGitPrj, action.Action)
|
||||
if !configFound {
|
||||
if h.Git.DebugLogger {
|
||||
h.StdLogger.Printf("Repository event for %s. Not configured. Ignoring.\n", action.Organization.Username)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
h.CreateRepositoryIfNotExist(*action.Organization, h.PrjGit)
|
||||
h.Git.GitExec("", "clone", "--depth", "1", action.PrjGit, h.PrjGit)
|
||||
prjgit := config.prjgit
|
||||
if action.Repository.Name == prjgit {
|
||||
if h.Git.DebugLogger {
|
||||
h.StdLogger.Printf("repository event %s for PrjGit '%s'. Ignoring\n", common.DefaultGitPrj, action.Action)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
prjGitRepo, err := h.CreateRepositoryIfNotExist(*action.Organization, prjgit)
|
||||
if err != nil {
|
||||
return fmt.Errorf("Error accessing/creating prjgit: %s err: %w", prjgit, err)
|
||||
}
|
||||
h.Git.GitExec("", "clone", "--depth", "1", prjGitRepo.SSHURL, common.DefaultGitPrj)
|
||||
|
||||
switch action.Action {
|
||||
case "created":
|
||||
h.Git.GitExec(common.DefaultGitPrj, "submodule", "--quiet", "add", "--depth", "1", action.Repository.Clone_Url)
|
||||
h.Git.GitExec(common.DefaultGitPrj, "commit", "-m", "Automatic package inclusion")
|
||||
h.Git.GitExec(common.DefaultGitPrj, "commit", "-m", "Automatic package inclusion via Direct Workflow")
|
||||
h.Git.GitExec(common.DefaultGitPrj, "push")
|
||||
|
||||
case "deleted":
|
||||
if stat, err := os.Stat(filepath.Join(h.Git.GitPath, common.DefaultGitPrj, action.Repository.Name)); err != nil || !stat.IsDir() {
|
||||
h.StdLogger.Printf("delete event for %s -- not in project. Ignoring\n", action.Repository.Name)
|
||||
if h.Git.DebugLogger {
|
||||
h.StdLogger.Printf("delete event for %s -- not in project. Ignoring\n", action.Repository.Name)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
h.Git.GitExec(common.DefaultGitPrj, "rm", action.Repository.Name)
|
||||
h.Git.GitExec(common.DefaultGitPrj, "commit", "-m", "Automatic package removal")
|
||||
h.Git.GitExec(common.DefaultGitPrj, "commit", "-m", "Automatic package removal via Direct Workflow")
|
||||
h.Git.GitExec(common.DefaultGitPrj, "push")
|
||||
|
||||
default:
|
||||
return fmt.Errorf("%s: %s", "Unknown action type", action.Action)
|
||||
}
|
||||
@ -54,15 +77,32 @@ func processRepositoryAction(h *common.RequestHandler) error {
|
||||
|
||||
func processPushAction(h *common.RequestHandler) error {
|
||||
action := h.Request.Data.(*common.PushWebhookEvent)
|
||||
config, configFound := configuredRepos[action.Repository.Owner.Username]
|
||||
|
||||
if action.Repository.Name == common.DefaultGitPrj {
|
||||
h.StdLogger.Printf("push to %s -- ignoringi\n", common.DefaultGitPrj)
|
||||
if !configFound {
|
||||
if h.Git.DebugLogger {
|
||||
h.StdLogger.Printf("Push event to Organizationr '%s'. Not configured. Ignoring.\n", action.Repository.Owner.Username)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
h.Git.GitExec("", "clone", "--depth", "1", h.PrjGit, common.DefaultGitPrj)
|
||||
prjgit := config.prjgit
|
||||
if action.Repository.Name == prjgit {
|
||||
if h.Git.DebugLogger {
|
||||
h.StdLogger.Printf("push to %s -- ignoring\n", prjgit)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
prjGitRepo, err := h.CreateRepositoryIfNotExist(*action.Repository.Owner, prjgit)
|
||||
if err != nil {
|
||||
return fmt.Errorf("Error accessing/creating prjgit: %s err: %w", prjgit, err)
|
||||
}
|
||||
h.Git.GitExec("", "clone", "--depth", "1", prjGitRepo.SSHURL, common.DefaultGitPrj)
|
||||
if stat, err := os.Stat(filepath.Join(h.Git.GitPath, common.DefaultGitPrj, action.Repository.Name)); err != nil || !stat.IsDir() {
|
||||
h.StdLogger.Printf("Pushed to package that is not part of the project. Ignoring. : %v\n", err)
|
||||
if h.Git.DebugLogger {
|
||||
h.StdLogger.Printf("Pushed to package that is not part of the project. Ignoring: %v\n", err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
h.Git.GitExec(common.DefaultGitPrj, "submodule", "update", "--init", "--depth", "1", "--checkout", action.Repository.Name)
|
||||
@ -71,7 +111,7 @@ func processPushAction(h *common.RequestHandler) error {
|
||||
if commitId.Id == id {
|
||||
h.Git.GitExec(filepath.Join(common.DefaultGitPrj, action.Repository.Name), "fetch", "--depth", "1", "origin", id)
|
||||
h.Git.GitExec(filepath.Join(common.DefaultGitPrj, action.Repository.Name), "checkout", id)
|
||||
h.Git.GitExec(common.DefaultGitPrj, "commit", "-a", "-m", "Automatic update via push")
|
||||
h.Git.GitExec(common.DefaultGitPrj, "commit", "-a", "-m", "Automatic update via push via Direct Workflow")
|
||||
h.Git.GitExec(common.DefaultGitPrj, "push")
|
||||
return nil
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user