-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhook.go
49 lines (43 loc) · 1.1 KB
/
hook.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
package octokit
import (
"github.com/Sirupsen/logrus"
)
// OctokitHook to send logs via octokit.
type OctokitHook struct {}
func NewOctokitHook(gitHubAPIURL, userAgent, accessToken, targeOwner, targetRepo string) (*OctokitHook) {
NewOctokitClient(gitHubAPIURL, userAgent, accessToken, targeOwner, targetRepo)
return &OctokitHook{}
}
func (hook *OctokitHook) Fire(entry *logrus.Entry) error {
body := entry.Message
title := body
if len(body) > 60 {
title = body[:60]
}
switch entry.Level {
case logrus.PanicLevel:
return SendLog(title, body, "panic")
case logrus.FatalLevel:
return SendLog(title, body, "fatal")
case logrus.ErrorLevel:
return SendLog(title, body, "error")
case logrus.WarnLevel:
return SendLog(title, body, "warning")
case logrus.InfoLevel:
return SendLog(title, body, "info")
case logrus.DebugLevel:
return SendLog(title, body, "debug")
default:
return nil
}
}
func (hook *OctokitHook) Levels() []logrus.Level {
return []logrus.Level{
logrus.PanicLevel,
logrus.FatalLevel,
logrus.ErrorLevel,
logrus.WarnLevel,
logrus.InfoLevel,
logrus.DebugLevel,
}
}