/
bot.go
61 lines (45 loc) · 1.29 KB
/
bot.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
package commitstatus
import (
"context"
"github.com/google/go-github/github"
githubbinding "github.com/mattmoor/bindings/pkg/github"
"github.com/mattmoor/knobots/pkg/handler"
)
type commitstatus struct{}
var _ handler.Interface = (*commitstatus)(nil)
func New(context.Context) handler.Interface {
return &commitstatus{}
}
func (*commitstatus) GetType() interface{} {
return &Payload{}
}
func (*commitstatus) Handle(ctx context.Context, x interface{}) (handler.Response, error) {
p := x.(*Payload)
ghc, err := githubbinding.New(ctx)
if err != nil {
return nil, err
}
_, _, err = ghc.Repositories.CreateStatus(ctx, p.Owner, p.Repository, p.SHA, &github.RepoStatus{
Context: &p.Name,
State: &p.State,
Description: &p.Description,
TargetURL: p.URL,
})
return nil, err
}
type Payload struct {
Owner string `json:"owner"`
Repository string `json:"repository"`
SHA string `json:"sha"`
Name string `json:"name"`
Description string `json:"description"`
State string `json:"state"`
URL *string `json:"url"`
}
var _ handler.Response = (*Payload)(nil)
func (*Payload) GetSource() string {
return "https://github.com/mattmoor/knobots/cmd/commitstatus"
}
func (*Payload) GetType() string {
return "dev.mattmoor.knobots.commitstatus"
}