refactor
This commit is contained in:
@@ -56,31 +56,31 @@ func concatenateErrors(err1, err2 error) error {
|
||||
return fmt.Errorf("%w\n%w", err1, err2)
|
||||
}
|
||||
|
||||
func processRepositoryAction(h *common.RequestHandler) error {
|
||||
action := h.Request.Data.(*common.RepositoryWebhookEvent)
|
||||
func processRepositoryAction(request *common.Request) error {
|
||||
action := request.Data.(*common.RepositoryWebhookEvent)
|
||||
configs, configFound := configuredRepos[action.Organization.Username]
|
||||
|
||||
if !configFound {
|
||||
h.StdLogger.Printf("Repository event for %s. Not configured. Ignoring.\n", action.Organization.Username)
|
||||
log.Printf("Repository event for %s. Not configured. Ignoring.\n", action.Organization.Username)
|
||||
return nil
|
||||
}
|
||||
|
||||
for _, config := range configs {
|
||||
if config.GitProjectName == action.Repository.Name {
|
||||
h.StdLogger.Println("+ ignoring repo event for PrjGit repository", config.GitProjectName)
|
||||
log.Println("+ ignoring repo event for PrjGit repository", config.GitProjectName)
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
var err error
|
||||
for _, config := range configs {
|
||||
err = concatenateErrors(err, processConfiguredRepositoryAction(h, action, config))
|
||||
err = concatenateErrors(err, processConfiguredRepositoryAction(action, config))
|
||||
}
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
func processConfiguredRepositoryAction(h *common.RequestHandler, action *common.RepositoryWebhookEvent, config *common.AutogitConfig) error {
|
||||
func processConfiguredRepositoryAction(action *common.RepositoryWebhookEvent, config *common.AutogitConfig) error {
|
||||
prjgit := config.GitProjectName
|
||||
git, err := common.CreateGitHandler(GitAuthor, GitEmail, AppName)
|
||||
common.PanicOnError(err)
|
||||
@@ -114,7 +114,7 @@ func processConfiguredRepositoryAction(h *common.RequestHandler, action *common.
|
||||
case "deleted":
|
||||
if stat, err := os.Stat(filepath.Join(git.GitPath, prjgit, action.Repository.Name)); err != nil || !stat.IsDir() {
|
||||
if git.DebugLogger {
|
||||
h.StdLogger.Printf("delete event for %s -- not in project. Ignoring\n", action.Repository.Name)
|
||||
log.Println("delete event for", action.Repository.Name, "-- not in project. Ignoring")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -129,31 +129,31 @@ func processConfiguredRepositoryAction(h *common.RequestHandler, action *common.
|
||||
return nil
|
||||
}
|
||||
|
||||
func processPushAction(h *common.RequestHandler) error {
|
||||
action := h.Request.Data.(*common.PushWebhookEvent)
|
||||
func processPushAction(request *common.Request) error {
|
||||
action := request.Data.(*common.PushWebhookEvent)
|
||||
configs, configFound := configuredRepos[action.Repository.Owner.Username]
|
||||
|
||||
if !configFound {
|
||||
h.StdLogger.Printf("Repository event for %s. Not configured. Ignoring.\n", action.Repository.Owner.Username)
|
||||
log.Printf("Repository event for %s. Not configured. Ignoring.\n", action.Repository.Owner.Username)
|
||||
return nil
|
||||
}
|
||||
|
||||
for _, config := range configs {
|
||||
if config.GitProjectName == action.Repository.Name {
|
||||
h.StdLogger.Println("+ ignoring push to PrjGit repository", config.GitProjectName)
|
||||
log.Println("+ ignoring push to PrjGit repository", config.GitProjectName)
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
var err error
|
||||
for _, config := range configs {
|
||||
err = concatenateErrors(err, processConfiguredPushAction(h, action, config))
|
||||
err = concatenateErrors(err, processConfiguredPushAction(action, config))
|
||||
}
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
func processConfiguredPushAction(h *common.RequestHandler, action *common.PushWebhookEvent, config *common.AutogitConfig) error {
|
||||
func processConfiguredPushAction(action *common.PushWebhookEvent, config *common.AutogitConfig) error {
|
||||
prjgit := config.GitProjectName
|
||||
git, err := common.CreateGitHandler(GitAuthor, GitEmail, AppName)
|
||||
common.PanicOnError(err)
|
||||
@@ -173,7 +173,7 @@ func processConfiguredPushAction(h *common.RequestHandler, action *common.PushWe
|
||||
common.PanicOnError(git.GitExec("", "clone", "--depth", "1", prjGitRepo.SSHURL, prjgit))
|
||||
if stat, err := os.Stat(filepath.Join(git.GitPath, prjgit, action.Repository.Name)); err != nil || !stat.IsDir() {
|
||||
if git.DebugLogger {
|
||||
h.StdLogger.Println("Pushed to package that is not part of the project. Ignoring:", err)
|
||||
log.Println("Pushed to package that is not part of the project. Ignoring:", err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -193,7 +193,7 @@ func processConfiguredPushAction(h *common.RequestHandler, action *common.PushWe
|
||||
}
|
||||
}
|
||||
|
||||
h.StdLogger.Println("push of refs the configured branch", config.Branch, ". ignoring.")
|
||||
log.Println("push of refs the configured branch", config.Branch, ". ignoring.")
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user