From 3df22a72bb5229635a6a679dfaea7a552be9f34127d4f3f66b7860e36eeb51c6 Mon Sep 17 00:00:00 2001 From: Adam Majer Date: Mon, 26 Aug 2024 17:07:52 +0200 Subject: [PATCH] . --- bots-common/listen.go | 13 +++++++++++-- bots-common/request_pr.go | 2 +- gitea-events-rabbitmq-publisher/main.go | 24 ++++++++++++------------ prjgit-updater/README.md | 2 +- prjgit-updater/main.go | 16 +++++++++++++--- 5 files changed, 38 insertions(+), 19 deletions(-) diff --git a/bots-common/listen.go b/bots-common/listen.go index b63f7b8..6bc7e0f 100644 --- a/bots-common/listen.go +++ b/bots-common/listen.go @@ -6,9 +6,19 @@ import ( "net/url" ) +const RequestType_CreateBrachTag = "create" +const RequestType_DeleteBranchTag = "delete" +const RequestType_Fork = "fork" +const RequestType_Issue = "issues" +const RequestType_IssueAssign = "issue_assign" +const RequestType_IssueComment = "issue_comment" +const RequestType_IssueLabel = "issue_label" +const RequestType_IssueMilestone = "issue_milestone" const RequestType_Push = "push" const RequestType_Repository = "repository" +const RequestType_Release = "release" const RequestType_PR = "pull_request" +const RequestType_PRComment = "pull_request_comment" const RequestType_PR_sync = "pull_request_sync" type RequestProcessor func(*RequestHandler) error @@ -18,8 +28,7 @@ type ListenDefinitions struct { Handlers map[string]RequestProcessor } -func StartServer(listenDefs ListenDefinitions) { - StartServerWithAddress(listenDefs, "[::1]:8000") +func StartServer(listenDefs ListenDefinitions, config []*AutogitConfig) { } func StartServerWithAddress(listenDefs ListenDefinitions, addr string) { diff --git a/bots-common/request_pr.go b/bots-common/request_pr.go index 7408c4f..8d9814b 100644 --- a/bots-common/request_pr.go +++ b/bots-common/request_pr.go @@ -42,7 +42,7 @@ type PullRequestWebhookEvent struct { Pull_Request PullRequest Repository Repository - Requested_reviewer User + Requested_reviewer *User Sender User } diff --git a/gitea-events-rabbitmq-publisher/main.go b/gitea-events-rabbitmq-publisher/main.go index 39ce588..3009819 100644 --- a/gitea-events-rabbitmq-publisher/main.go +++ b/gitea-events-rabbitmq-publisher/main.go @@ -43,28 +43,28 @@ func parseRequestJSON(reqType string, data []byte) (org *common.Organization, ex extraAction = "" switch reqType { - case "create", "delete": + case common.RequestType_CreateBrachTag, common.RequestType_DeleteBranchTag: create := common.CreateWebhookEvent{} if err = json.Unmarshal(data, &create); err != nil { return } org = create.Repository.Owner - case "fork": + case common.RequestType_Fork: fork := common.ForkWebhookEvent{} if err = json.Unmarshal(data, &fork); err != nil { return } org = fork.Forkee.Owner - case "push": + case common.RequestType_Push: push := common.PushRequest{} if err = json.Unmarshal(data, &push); err != nil { return } org = push.Repository.Owner - case "repository": + case common.RequestType_Repository: repoAction := common.RepositoryAction{} if err = json.Unmarshal(data, &repoAction); err != nil { return @@ -79,7 +79,7 @@ func parseRequestJSON(reqType string, data []byte) (org *common.Organization, ex org = repoAction.Organization extraAction = repoAction.Action - case "release": + case common.RequestType_Release: release := common.ReleaseWebhookEvent{} if err = json.Unmarshal(data, &release); err != nil { return @@ -95,7 +95,7 @@ func parseRequestJSON(reqType string, data []byte) (org *common.Organization, ex org = release.Repository.Owner extraAction = release.Action - case "issues": + case common.RequestType_Issue: issue := common.IssueWebhookEvent{} if err = json.Unmarshal(data, &issue); err != nil { return @@ -110,7 +110,7 @@ func parseRequestJSON(reqType string, data []byte) (org *common.Organization, ex org = issue.Repository.Owner extraAction = issue.Action - case "issue_assign": + case common.RequestType_IssueAssign: issue := common.IssueWebhookEvent{} if err = json.Unmarshal(data, &issue); err != nil { return @@ -125,7 +125,7 @@ func parseRequestJSON(reqType string, data []byte) (org *common.Organization, ex org = issue.Repository.Owner extraAction = issue.Action - case "issue_comment", "pull_request_comment": + case common.RequestType_IssueComment, common.RequestType_PRComment: issue := common.IssueCommentWebhookEvent{} if err = json.Unmarshal(data, &issue); err != nil { return @@ -140,7 +140,7 @@ func parseRequestJSON(reqType string, data []byte) (org *common.Organization, ex org = issue.Repository.Owner extraAction = issue.Action - case "issue_label": + case common.RequestType_IssueLabel: issue := common.IssueWebhookEvent{} if err = json.Unmarshal(data, &issue); err != nil { return @@ -155,7 +155,7 @@ func parseRequestJSON(reqType string, data []byte) (org *common.Organization, ex org = issue.Repository.Owner extraAction = issue.Action - case "issue_milestone": + case common.RequestType_IssueMilestone: issue := common.IssueWebhookEvent{} if err = json.Unmarshal(data, &issue); err != nil { return @@ -170,7 +170,7 @@ func parseRequestJSON(reqType string, data []byte) (org *common.Organization, ex org = issue.Repository.Owner extraAction = issue.Action - case "pull_request": + case common.RequestType_PR: pr := common.PullRequestWebhookEvent{} if err = json.Unmarshal(data, &pr); err != nil { return @@ -260,7 +260,7 @@ func parseRequestJSON(reqType string, data []byte) (org *common.Organization, ex org = pr.Repository.Owner extraAction = "" - case "pull_request_sync": + case common.RequestType_PR_sync: pr := common.PullRequestWebhookEvent{} if err = json.Unmarshal(data, &pr); err != nil { return diff --git a/prjgit-updater/README.md b/prjgit-updater/README.md index 57abd2d..7fafe79 100644 --- a/prjgit-updater/README.md +++ b/prjgit-updater/README.md @@ -11,7 +11,7 @@ Areas of responsibility * on package removal, removes the submodule 2. Assumes: - * _ObsPrj = project git + * config.GitProjectName == project name (default: _ObsPrj) * Other repositories == packages (similar to OBS project) diff --git a/prjgit-updater/main.go b/prjgit-updater/main.go index b30ea15..4e868c6 100644 --- a/prjgit-updater/main.go +++ b/prjgit-updater/main.go @@ -1,7 +1,9 @@ package main import ( + "flag" "fmt" + "log" "os" "path/filepath" @@ -43,7 +45,7 @@ func processPushAction(h *common.RequestHandler) error { action := h.Request.Data.(common.PushRequest) if action.Repository.Name == common.DefaultGitPrj { - h.Log("push to %s -- ignoring", common.DefaultGitPrj) + h.StdLogger.Printf("push to %s -- ignoringi\n", common.DefaultGitPrj) return nil } @@ -63,11 +65,19 @@ func processPushAction(h *common.RequestHandler) error { } } - h.Log("push of refs not on the main branch. ignoring.") + h.StdLogger.Println("push of refs not on the main branch. ignoring.") return nil } func main() { + workflowConfig := flag.String("config", "", "Repository and workflow definition file") + flag.Parse() + + configs, err := common.ReadWorkflowConfigsFile(*workflowConfig) + if err != nil { + log.Fatalf("Error reading config file. err: %v", err) + } + var defs common.ListenDefinitions defs.Url = "prjgit-updater" @@ -78,5 +88,5 @@ func main() { defs.Handlers[common.RequestType_Repository] = processRepositoryAction common.RequireGiteaSecretToken() - common.StartServer(defs) + common.StartServer(defs, configs) }