.
This commit is contained in:
parent
0473ef7c37
commit
3df22a72bb
@ -6,9 +6,19 @@ import (
|
|||||||
"net/url"
|
"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_Push = "push"
|
||||||
const RequestType_Repository = "repository"
|
const RequestType_Repository = "repository"
|
||||||
|
const RequestType_Release = "release"
|
||||||
const RequestType_PR = "pull_request"
|
const RequestType_PR = "pull_request"
|
||||||
|
const RequestType_PRComment = "pull_request_comment"
|
||||||
const RequestType_PR_sync = "pull_request_sync"
|
const RequestType_PR_sync = "pull_request_sync"
|
||||||
|
|
||||||
type RequestProcessor func(*RequestHandler) error
|
type RequestProcessor func(*RequestHandler) error
|
||||||
@ -18,8 +28,7 @@ type ListenDefinitions struct {
|
|||||||
Handlers map[string]RequestProcessor
|
Handlers map[string]RequestProcessor
|
||||||
}
|
}
|
||||||
|
|
||||||
func StartServer(listenDefs ListenDefinitions) {
|
func StartServer(listenDefs ListenDefinitions, config []*AutogitConfig) {
|
||||||
StartServerWithAddress(listenDefs, "[::1]:8000")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func StartServerWithAddress(listenDefs ListenDefinitions, addr string) {
|
func StartServerWithAddress(listenDefs ListenDefinitions, addr string) {
|
||||||
|
@ -42,7 +42,7 @@ type PullRequestWebhookEvent struct {
|
|||||||
|
|
||||||
Pull_Request PullRequest
|
Pull_Request PullRequest
|
||||||
Repository Repository
|
Repository Repository
|
||||||
Requested_reviewer User
|
Requested_reviewer *User
|
||||||
Sender User
|
Sender User
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -43,28 +43,28 @@ func parseRequestJSON(reqType string, data []byte) (org *common.Organization, ex
|
|||||||
extraAction = ""
|
extraAction = ""
|
||||||
|
|
||||||
switch reqType {
|
switch reqType {
|
||||||
case "create", "delete":
|
case common.RequestType_CreateBrachTag, common.RequestType_DeleteBranchTag:
|
||||||
create := common.CreateWebhookEvent{}
|
create := common.CreateWebhookEvent{}
|
||||||
if err = json.Unmarshal(data, &create); err != nil {
|
if err = json.Unmarshal(data, &create); err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
org = create.Repository.Owner
|
org = create.Repository.Owner
|
||||||
|
|
||||||
case "fork":
|
case common.RequestType_Fork:
|
||||||
fork := common.ForkWebhookEvent{}
|
fork := common.ForkWebhookEvent{}
|
||||||
if err = json.Unmarshal(data, &fork); err != nil {
|
if err = json.Unmarshal(data, &fork); err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
org = fork.Forkee.Owner
|
org = fork.Forkee.Owner
|
||||||
|
|
||||||
case "push":
|
case common.RequestType_Push:
|
||||||
push := common.PushRequest{}
|
push := common.PushRequest{}
|
||||||
if err = json.Unmarshal(data, &push); err != nil {
|
if err = json.Unmarshal(data, &push); err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
org = push.Repository.Owner
|
org = push.Repository.Owner
|
||||||
|
|
||||||
case "repository":
|
case common.RequestType_Repository:
|
||||||
repoAction := common.RepositoryAction{}
|
repoAction := common.RepositoryAction{}
|
||||||
if err = json.Unmarshal(data, &repoAction); err != nil {
|
if err = json.Unmarshal(data, &repoAction); err != nil {
|
||||||
return
|
return
|
||||||
@ -79,7 +79,7 @@ func parseRequestJSON(reqType string, data []byte) (org *common.Organization, ex
|
|||||||
org = repoAction.Organization
|
org = repoAction.Organization
|
||||||
extraAction = repoAction.Action
|
extraAction = repoAction.Action
|
||||||
|
|
||||||
case "release":
|
case common.RequestType_Release:
|
||||||
release := common.ReleaseWebhookEvent{}
|
release := common.ReleaseWebhookEvent{}
|
||||||
if err = json.Unmarshal(data, &release); err != nil {
|
if err = json.Unmarshal(data, &release); err != nil {
|
||||||
return
|
return
|
||||||
@ -95,7 +95,7 @@ func parseRequestJSON(reqType string, data []byte) (org *common.Organization, ex
|
|||||||
org = release.Repository.Owner
|
org = release.Repository.Owner
|
||||||
extraAction = release.Action
|
extraAction = release.Action
|
||||||
|
|
||||||
case "issues":
|
case common.RequestType_Issue:
|
||||||
issue := common.IssueWebhookEvent{}
|
issue := common.IssueWebhookEvent{}
|
||||||
if err = json.Unmarshal(data, &issue); err != nil {
|
if err = json.Unmarshal(data, &issue); err != nil {
|
||||||
return
|
return
|
||||||
@ -110,7 +110,7 @@ func parseRequestJSON(reqType string, data []byte) (org *common.Organization, ex
|
|||||||
org = issue.Repository.Owner
|
org = issue.Repository.Owner
|
||||||
extraAction = issue.Action
|
extraAction = issue.Action
|
||||||
|
|
||||||
case "issue_assign":
|
case common.RequestType_IssueAssign:
|
||||||
issue := common.IssueWebhookEvent{}
|
issue := common.IssueWebhookEvent{}
|
||||||
if err = json.Unmarshal(data, &issue); err != nil {
|
if err = json.Unmarshal(data, &issue); err != nil {
|
||||||
return
|
return
|
||||||
@ -125,7 +125,7 @@ func parseRequestJSON(reqType string, data []byte) (org *common.Organization, ex
|
|||||||
org = issue.Repository.Owner
|
org = issue.Repository.Owner
|
||||||
extraAction = issue.Action
|
extraAction = issue.Action
|
||||||
|
|
||||||
case "issue_comment", "pull_request_comment":
|
case common.RequestType_IssueComment, common.RequestType_PRComment:
|
||||||
issue := common.IssueCommentWebhookEvent{}
|
issue := common.IssueCommentWebhookEvent{}
|
||||||
if err = json.Unmarshal(data, &issue); err != nil {
|
if err = json.Unmarshal(data, &issue); err != nil {
|
||||||
return
|
return
|
||||||
@ -140,7 +140,7 @@ func parseRequestJSON(reqType string, data []byte) (org *common.Organization, ex
|
|||||||
org = issue.Repository.Owner
|
org = issue.Repository.Owner
|
||||||
extraAction = issue.Action
|
extraAction = issue.Action
|
||||||
|
|
||||||
case "issue_label":
|
case common.RequestType_IssueLabel:
|
||||||
issue := common.IssueWebhookEvent{}
|
issue := common.IssueWebhookEvent{}
|
||||||
if err = json.Unmarshal(data, &issue); err != nil {
|
if err = json.Unmarshal(data, &issue); err != nil {
|
||||||
return
|
return
|
||||||
@ -155,7 +155,7 @@ func parseRequestJSON(reqType string, data []byte) (org *common.Organization, ex
|
|||||||
org = issue.Repository.Owner
|
org = issue.Repository.Owner
|
||||||
extraAction = issue.Action
|
extraAction = issue.Action
|
||||||
|
|
||||||
case "issue_milestone":
|
case common.RequestType_IssueMilestone:
|
||||||
issue := common.IssueWebhookEvent{}
|
issue := common.IssueWebhookEvent{}
|
||||||
if err = json.Unmarshal(data, &issue); err != nil {
|
if err = json.Unmarshal(data, &issue); err != nil {
|
||||||
return
|
return
|
||||||
@ -170,7 +170,7 @@ func parseRequestJSON(reqType string, data []byte) (org *common.Organization, ex
|
|||||||
org = issue.Repository.Owner
|
org = issue.Repository.Owner
|
||||||
extraAction = issue.Action
|
extraAction = issue.Action
|
||||||
|
|
||||||
case "pull_request":
|
case common.RequestType_PR:
|
||||||
pr := common.PullRequestWebhookEvent{}
|
pr := common.PullRequestWebhookEvent{}
|
||||||
if err = json.Unmarshal(data, &pr); err != nil {
|
if err = json.Unmarshal(data, &pr); err != nil {
|
||||||
return
|
return
|
||||||
@ -260,7 +260,7 @@ func parseRequestJSON(reqType string, data []byte) (org *common.Organization, ex
|
|||||||
org = pr.Repository.Owner
|
org = pr.Repository.Owner
|
||||||
extraAction = ""
|
extraAction = ""
|
||||||
|
|
||||||
case "pull_request_sync":
|
case common.RequestType_PR_sync:
|
||||||
pr := common.PullRequestWebhookEvent{}
|
pr := common.PullRequestWebhookEvent{}
|
||||||
if err = json.Unmarshal(data, &pr); err != nil {
|
if err = json.Unmarshal(data, &pr); err != nil {
|
||||||
return
|
return
|
||||||
|
@ -11,7 +11,7 @@ Areas of responsibility
|
|||||||
* on package removal, removes the submodule
|
* on package removal, removes the submodule
|
||||||
|
|
||||||
2. Assumes:
|
2. Assumes:
|
||||||
* _ObsPrj = project git
|
* config.GitProjectName == project name (default: _ObsPrj)
|
||||||
* Other repositories == packages (similar to OBS project)
|
* Other repositories == packages (similar to OBS project)
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,7 +1,9 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"flag"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"log"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
|
||||||
@ -43,7 +45,7 @@ func processPushAction(h *common.RequestHandler) error {
|
|||||||
action := h.Request.Data.(common.PushRequest)
|
action := h.Request.Data.(common.PushRequest)
|
||||||
|
|
||||||
if action.Repository.Name == common.DefaultGitPrj {
|
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
|
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
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func main() {
|
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
|
var defs common.ListenDefinitions
|
||||||
|
|
||||||
defs.Url = "prjgit-updater"
|
defs.Url = "prjgit-updater"
|
||||||
@ -78,5 +88,5 @@ func main() {
|
|||||||
defs.Handlers[common.RequestType_Repository] = processRepositoryAction
|
defs.Handlers[common.RequestType_Repository] = processRepositoryAction
|
||||||
|
|
||||||
common.RequireGiteaSecretToken()
|
common.RequireGiteaSecretToken()
|
||||||
common.StartServer(defs)
|
common.StartServer(defs, configs)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user