-
Notifications
You must be signed in to change notification settings - Fork 3
/
context.go
54 lines (46 loc) · 1.02 KB
/
context.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
package probot
import (
"context"
"github.com/go-logr/logr"
)
func newProbotContext[GT GitClientType, PT gitEventType](
parent context.Context, logger logr.Logger,
client *GT, graphQLClient GitGraphQLClient, payload *PT,
) *probotContext[GT, PT] {
return &probotContext[GT, PT]{
Context: parent,
logger: logger,
client: client,
graphQL: graphQLClient,
payload: payload,
}
}
type probotContext[GT GitClientType, PT gitEventType] struct {
context.Context
// Input
logger logr.Logger
client *GT
payload *PT
graphQL GitGraphQLClient
}
func (ctx *probotContext[GT, PT]) Payload() *PT {
return ctx.payload
}
func (ctx *probotContext[GT, PT]) Client() *GT {
return ctx.client
}
func (ctx *probotContext[GT, PT]) GraphQL() GitGraphQLClient {
return ctx.graphQL
}
func (ctx *probotContext[GT, PT]) Logger() logr.Logger {
return ctx.logger
}
func (ctx *probotContext[GT, PT]) Must(errors ...interface{}) {
for _, v := range errors {
if v != nil {
if err, ok := v.(error); ok {
panic(err)
}
}
}
}