-
Notifications
You must be signed in to change notification settings - Fork 3
/
github_events.go.tmpl
51 lines (41 loc) · 2.22 KB
/
github_events.go.tmpl
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
// Code generated by codegen. DO NOT EDIT.
package probot
import "github.com/google/go-github/v48/github"
// {{ $.Prefix }} contains all event and handler types
type {{ $.Prefix }} struct {
{{ range $event := .Events }}// {{ $event.Type }} is webhook event `{{ toSnake $event.Type }}`.
// reference: https://docs.github.com/developers/webhooks-and-events/webhooks/webhook-events-and-payloads#{{ toSnake $event.Type }}
{{ $event.Type }} {{ $.Prefix }}{{ $event.Type }}AllInOne
{{ end }}
}
{{ range $event := .Events }}
// {{ $.Prefix }}{{ $event.Type }}AllInOne contains event and handler for type {{ $event.Type }}
type {{ $.Prefix }}{{ $event.Type }}AllInOne struct {
githubEvent{{ $event.Type }}
{{ range $val := .Actions }}// {{ toCamel $val }} is `{{ toSnake $event.Type }}` event with `{{ $val }}` action.
{{ toCamel $val }} {{ $.Prefix }}{{ $event.Type }}{{toCamel $val}}
{{ end }}
}
// GitHub{{ $event.Type }}Context is the context type for {{ $event.Type }} event handler to process
type GitHub{{ $event.Type }}Context = ProbotContext[GitHubClient, github.{{ $event.Type }}Event]
// Handler returns event handler function to process context
func ({{ $.Prefix }}{{ $event.Type }}AllInOne) Handler(fn func(ctx GitHub{{ $event.Type }}Context)) Handler {
return EventHandlerFunc[GitHubClient, github.{{ $event.Type }}Event](fn)
}
// {{ $.Prefix }}{{ $event.Type }} is the base event type of {{ $event.Type }}
type {{ $.Prefix }}{{ $event.Type }} struct{}
// Type implement the WebhookEvent interface
{{if $event.RawType}}func ({{ $.Prefix }}{{ $event.Type }}) Type() string { return "{{ toSnake $event.RawType }}" }
{{else}}func ({{ $.Prefix }}{{ $event.Type }}) Type() string { return "{{ toSnake $event.Type }}" }
{{end}}
// Action implement the WebhookEvent interface
func ({{ $.Prefix }}{{ $event.Type }}) Action() string { return "" }
{{ range $val := .Actions }}
// {{ $.Prefix }}{{ $event.Type }}{{ toCamel $val }} is the {{ toCamel $val }} action of {{ $event.Type }} event
type {{ $.Prefix }}{{ $event.Type }}{{ toCamel $val }} struct {
{{ $.Prefix }}{{ $event.Type }}
}
// Action implement the WebhookEvent interface
func ({{ $.Prefix }}{{ $event.Type }}{{ toCamel $val }}) Action() string { return "{{ $val }}" }
{{ end }}
{{ end }}