This commit is contained in:
Adam Majer 2024-08-26 17:07:52 +02:00
parent 0473ef7c37
commit 3df22a72bb
5 changed files with 38 additions and 19 deletions

View File

@ -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) {

View File

@ -42,7 +42,7 @@ type PullRequestWebhookEvent struct {
Pull_Request PullRequest
Repository Repository
Requested_reviewer User
Requested_reviewer *User
Sender User
}

View File

@ -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

View File

@ -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)

View File

@ -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)
}