From 3fb4bf5d54ed7b4c7e4cf0fe8cdfff6d42cfd02bd9bd5f551949d8756680a5ba Mon Sep 17 00:00:00 2001 From: Adam Majer Date: Wed, 28 Aug 2024 17:53:15 +0200 Subject: [PATCH] . --- bots-common/git_utils.go | 2 +- bots-common/log_test.go | 9 ++++----- bots-common/request_pr.go | 5 ++++- bots-common/request_pr_test.go | 2 +- bots-common/request_push.go | 5 ++++- bots-common/request_push_test.go | 2 ++ bots-common/request_repo.go | 2 +- prjgit-updater/main.go | 11 ++++++----- 8 files changed, 23 insertions(+), 15 deletions(-) diff --git a/bots-common/git_utils.go b/bots-common/git_utils.go index 6871bc8..fc834e8 100644 --- a/bots-common/git_utils.go +++ b/bots-common/git_utils.go @@ -628,7 +628,7 @@ func (e *GitHandler) GitSubmoduleCommitId(cwd, packageName, commitId string) (su data_out.ch <- '\x00' c, err := parseGitCommit(data_in.ch) if err != nil { - log.Panic("Error parsing git commit: %v\n", err) + log.Panicf("Error parsing git commit: %v\n", err) } data_out.Write([]byte(c.Tree)) data_out.ch <- '\x00' diff --git a/bots-common/log_test.go b/bots-common/log_test.go index 4331a13..f1b1acb 100644 --- a/bots-common/log_test.go +++ b/bots-common/log_test.go @@ -22,14 +22,14 @@ func TestLogging(t *testing.T) { stdLogger.Printf("OKA %d Done\n", 77) stdLogger.Println("Another line") - const prefixMatch = `\[\d+\]: ` + const prefixMatch = `\[\d+\] ` - err := errWriter.String() - if ok, err := regexp.MatchString("^"+prefixMatch+"100\n$", err); !ok { + errStr := errWriter.String() + if ok, err := regexp.MatchString("^"+prefixMatch+"100\n$", errStr); !ok { if err != nil { t.Logf("err: %v", err) } - t.Fatal(err) + t.Fatal(errStr) } str := strWriter.String() if ok, err := regexp.MatchString("^"+prefixMatch+"OKA 77 Done\n"+prefixMatch+"Another line\n$", str); !ok { @@ -40,4 +40,3 @@ func TestLogging(t *testing.T) { } }) } - diff --git a/bots-common/request_pr.go b/bots-common/request_pr.go index 7dbbc48..6355119 100644 --- a/bots-common/request_pr.go +++ b/bots-common/request_pr.go @@ -58,7 +58,10 @@ func (h *RequestHandler) parsePullRequest(data io.Reader) (action *PullRequestWe return nil, fmt.Errorf("Got error while parsing json: %w", err) } - h.Request.Data = action + h.Request = &Request { + Data: action, + Type: RequestType_PR, + } return } diff --git a/bots-common/request_pr_test.go b/bots-common/request_pr_test.go index 636aceb..da696f0 100644 --- a/bots-common/request_pr_test.go +++ b/bots-common/request_pr_test.go @@ -16,7 +16,7 @@ func TestPrParsing(t *testing.T) { t.Fatalf("error parsing PR: %v\n", err) } if pr == nil { - t.Fatalf("parsing PR failed without error?: %v") + t.Fatal("parsing PR failed without error?") } _, err = h.parsePullRequest(strings.NewReader(samplePRsync_JSON)) diff --git a/bots-common/request_push.go b/bots-common/request_push.go index a6032db..d9cb71c 100644 --- a/bots-common/request_push.go +++ b/bots-common/request_push.go @@ -40,7 +40,10 @@ func (h *RequestHandler) parsePushRequest(data io.Reader) (*PushWebhookEvent, er } h.StdLogger.Printf("Request push for repo: %s\n", action.Repository.Full_Name) - h.Request.Data = action + h.Request = &Request { + Type: RequestType_Push, + Data: action, + } if len(action.Commits) < 1 || len(action.Head_Commit.Id) != 64 { return nil, fmt.Errorf("Request has no action .... skipping") } diff --git a/bots-common/request_push_test.go b/bots-common/request_push_test.go index 476bab9..ea83689 100644 --- a/bots-common/request_push_test.go +++ b/bots-common/request_push_test.go @@ -1,6 +1,7 @@ package common import ( + "os" "strings" "testing" ) @@ -9,6 +10,7 @@ func TestPushRequestParsing(t *testing.T) { t.Run("parsing repo creation message", func(t *testing.T) { var h RequestHandler + h.StdLogger, h.ErrLogger = CreateStdoutLogger(os.Stdout, os.Stderr) json, err := h.parsePushRequest(strings.NewReader(examplePushJSON)) if err != nil { t.Fatalf("failed to parser push request: %v", err) diff --git a/bots-common/request_repo.go b/bots-common/request_repo.go index 50f3133..47af70d 100644 --- a/bots-common/request_repo.go +++ b/bots-common/request_repo.go @@ -54,7 +54,7 @@ func (h *RequestHandler) parseRepositoryRequest(dataReader io.Reader) (data *Rep repoIdx := strings.LastIndex(data.Repository.Ssh_Url, "/") if repoIdx == -1 || data.Repository.Ssh_Url[repoIdx+1:] != data.Repository.Name+".git" { - return nil, fmt.Errorf("Unexpected URL for SSH repository: %w", data.Repository.Name) + return nil, fmt.Errorf("Unexpected URL for SSH repository: %s", data.Repository.Name) } data.PrjGit = data.Repository.Ssh_Url[:repoIdx+1] + DefaultGitPrj + ".git" diff --git a/prjgit-updater/main.go b/prjgit-updater/main.go index bf3fbeb..43b50c9 100644 --- a/prjgit-updater/main.go +++ b/prjgit-updater/main.go @@ -18,6 +18,7 @@ type ConfigRepos struct { prjgit string branch string // "" == default branch } + var configuredRepos map[string]ConfigRepos func processRepositoryAction(h *common.RequestHandler) error { @@ -81,21 +82,21 @@ func processPushAction(h *common.RequestHandler) error { } func verifyProjectState(org string, config ConfigRepos) error { -return nil + return nil } var checkOnStart bool -var checkInterval time.Duration +var checkInterval time.Duration func consistencyCheckProcess(repos map[string]ConfigRepos) { if checkOnStart { - var wg sync.WaitGroup + var wg sync.WaitGroup for org, conf := range repos { wg.Add(1) go func() { defer wg.Done() - + verifyProjectState(org, conf) }() } @@ -140,7 +141,7 @@ func main() { for _, c := range configs { if slices.Contains(c.Workflows, "push") { if debugMode { - log.Printf(" + adding org: '%s', branch: '%s', prjgit: '%s'\n", c.Organization, c.Branch, c.GitProjectName) + log.Printf(" + adding org: '%s', branch: '%s', prjgit: '%s'\n", c.Organization, c.Branch, c.GitProjectName) } configuredRepos[c.Organization] = ConfigRepos{ prjgit: c.GitProjectName,