-
Notifications
You must be signed in to change notification settings - Fork 3
/
fogbugz.go
91 lines (74 loc) · 2.04 KB
/
fogbugz.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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
package main
import (
"fmt"
"github.com/BurntSushi/toml"
"github.com/litl/hookyapp/fogbugz"
"log"
)
type FogbugzCrashHandlerConfig struct {
Host string `toml:"host"`
Email string `toml:"email"`
Password string `toml:"password"`
Project string `toml:"project"`
Area string `toml:"area"`
}
func (config *FogbugzCrashHandlerConfig) GetHost() string {
return config.Host
}
func (config *FogbugzCrashHandlerConfig) GetEmail() string {
return config.Email
}
func (config *FogbugzCrashHandlerConfig) GetPassword() string {
return config.Password
}
type FogbugzCrashHandler struct {
session *fogbugz.Session
project string
area string
}
func NewFogbuzCrashHandler(configPrimitive toml.Primitive) (*FogbugzCrashHandler, error) {
var config FogbugzCrashHandlerConfig
err := toml.PrimitiveDecode(configPrimitive, &config)
if err != nil {
return nil, err
}
session, err := fogbugz.NewSession(&config)
if err != nil {
return nil, err
}
return &FogbugzCrashHandler{session, config.Project, config.Area}, nil
}
const CONTENT_PATTERN = `
See HockeyApp at %s
User: %s
%s
`
func (handler FogbugzCrashHandler) Handle(app *App, notification HockeyNotification) error {
title := fmt.Sprintf("Crash at %s:%s - %s - %s", notification.CrashReason.File,
notification.CrashReason.Line, notification.CrashReason.Method,
notification.CrashReason.Reason)
var crash HockeyCrash
var crashLog string
var err error
if len(notification.CrashReason.Crashes) > 0 {
crash = notification.CrashReason.Crashes[0]
if crash.HasLog {
if crashLog, err = app.GetCrashLog(crash); err != nil {
log.Println("Failed to fetch crash logs", err)
crashLog = ""
}
}
} else {
crash = HockeyCrash{}
}
content := fmt.Sprintf(CONTENT_PATTERN, notification.Url,
crash.UserString, crashLog)
var trackerUrl string
if trackerUrl, err = handler.session.FileBug(handler.project, handler.area, title, content); err != nil {
return err
}
if err = app.SetBugTrackerUrl(notification.CrashReason, trackerUrl); err != nil {
return err
}
return nil
}