-
Notifications
You must be signed in to change notification settings - Fork 8
/
webhooks.go
67 lines (60 loc) · 2.11 KB
/
webhooks.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
package main
import (
"context"
"fmt"
"io"
"net/http"
"github.com/erda-project/erda-bot/handlers"
"github.com/erda-project/erda-bot/handlers/issue/comment"
"github.com/erda-project/erda-bot/handlers/issue/comment/instruction"
"github.com/erda-project/erda-bot/handlers/issue/comment/instruction/approve"
"github.com/erda-project/erda-bot/handlers/issue/comment/instruction/assign"
"github.com/erda-project/erda-bot/handlers/issue/comment/instruction/cherrypick"
"github.com/erda-project/erda-bot/handlers/issue/comment/instruction/erda/actions"
"github.com/erda-project/erda-bot/handlers/issue/pr"
"github.com/erda-project/erda-bot/handlers/issue/title"
"github.com/erda-project/erda-bot/handlers/issue/title/label"
"github.com/erda-project/erda-bot/handlers/star"
"github.com/erda-project/erda/pkg/httpserver"
)
func Webhooks(ctx context.Context, r *http.Request, vars map[string]string) (httpserver.Responser, error) {
// get event bytes
eventBytes, err := io.ReadAll(r.Body)
if err != nil {
return httpserver.ErrResp(http.StatusBadRequest, "", fmt.Sprintf("%v", err))
}
// init request
req := &handlers.Request{EventBytes: eventBytes, HTTPRequest: r}
// init handlers chain of responsibility
h :=
handlers.NewRootHandler(
handlers.NewEventTypeParseHandler(
handlers.NewEventDispatchHandler(
comment.NewIssueCommentHandler(
instruction.NewPrCommentInstructionHandler(
cherrypick.NewPrCommentInstructionCherryPickHandler(),
approve.NewPrCommentInstructionApproveHandler(),
assign.NewPrCommentInstructionAssignHandler(),
actions.NewPrCommentInstructionActionHandler(),
),
),
// other event type handler here
star.NewStarHandler(),
pr.NewPRHandler(
title.NewPrTitleHandler(
label.NewPrTitleLabelHandler(),
),
comment.NewIssueCommentHandler(
instruction.NewPrCommentInstructionHandler(
cherrypick.NewPrCommentInstructionCherryPickHandler(),
assign.NewPrCommentInstructionAssignHandler(),
),
),
),
),
),
)
// handle request
go h.Execute(ctx, req)
return httpserver.OkResp(nil)
}