1
1
package main
2
2
3
3
import (
4
+ "encoding/json"
4
5
"errors"
5
6
"fmt"
6
7
"log"
7
8
"path/filepath"
8
9
"strings"
10
+
11
+ "github.com/getsentry/sentry-go"
9
12
)
10
13
11
14
type Approver struct {
@@ -18,37 +21,43 @@ func (a *Approver) Approve() {
18
21
a .application = Application {}
19
22
20
23
if err := a .application .SetApprover (); err != nil {
21
- a .printErrorAndExit ( err )
24
+ a .logErrorAndExit ( "could not set application approver" , err )
22
25
}
23
26
24
27
if err := a .gitHub .Init (); err != nil {
25
- a .printErrorAndExit ( err )
28
+ a .logErrorAndExit ( "could not initialize GitHub client" , err )
26
29
}
27
30
28
31
if * a .gitHub .Issue .State == "closed" {
29
- a .printErrorAndExit (errors .New ("script run on closed issue" ))
32
+ a .logErrorAndExit (
33
+ "script run on closed issue" ,
34
+ errors .New (* a .gitHub .Issue .State ),
35
+ )
30
36
}
31
37
32
38
if ! a .gitHub .IssueHasLabel (LabelStatusApproved ) {
33
- a .printErrorAndExit (
34
- fmt .Errorf ("script run on issue that does not have required '%s' label" , LabelStatusApproved ),
39
+ a .logErrorAndExit (
40
+ fmt .Sprintf ("script run on issue that does not have required '%s' label" , LabelStatusApproved ),
41
+ fmt .Errorf ("issue has labels %v" , a .gitHub .Issue .Labels ),
35
42
)
36
43
}
37
44
38
45
a .application .Parse (a .gitHub .Issue )
39
46
40
47
if ! a .application .IsValid () {
41
- a .printErrorAndExit (
42
- fmt .Errorf ("script run on issue with invalid application data:\n \n %s" , a .renderProblems ()),
48
+ a .logErrorAndExit (
49
+ "script run on issue with invalid application data" ,
50
+ errors .New (a .renderProblems ()),
43
51
)
44
52
}
45
53
46
54
// The reviewer may remove this label themselves, but
47
55
// let's double check and remove it if they haven't
48
56
if a .gitHub .IssueHasLabel (LabelStatusReviewing ) {
49
57
if err := a .gitHub .RemoveIssueLabel (LabelStatusReviewing ); err != nil {
50
- a .printErrorAndExit (
51
- fmt .Errorf ("could not remove issue label '%s': %s" , LabelStatusReviewing , err .Error ()),
58
+ a .logErrorAndExit (
59
+ fmt .Sprintf ("could not remove issue label '%s'" , LabelStatusReviewing ),
60
+ err ,
52
61
)
53
62
}
54
63
}
@@ -58,26 +67,41 @@ func (a *Approver) Approve() {
58
67
a .application .GetData (),
59
68
fmt .Sprintf ("Added \" %s\" to program" , a .application .Project .Name ),
60
69
); err != nil {
61
- a .printErrorAndExit (
62
- fmt .Errorf ("could not create commit: %s" , err .Error ()),
70
+ a .logErrorAndExit (
71
+ "could not create commit" ,
72
+ err ,
63
73
)
64
74
}
65
75
66
76
if err := a .gitHub .CreateIssueComment (a .getApprovalMessage ()); err != nil {
67
- a .printErrorAndExit (
68
- fmt .Errorf ("could not create issue comment: %s" , err .Error ()),
77
+ a .logErrorAndExit (
78
+ "could not create issue comment" ,
79
+ err ,
69
80
)
70
81
}
71
82
72
83
if err := a .gitHub .CloseIssue (); err != nil {
73
- a .printErrorAndExit (
74
- fmt .Errorf ("could not close issue: %s" , err .Error ()),
84
+ a .logErrorAndExit (
85
+ "could not close issue" ,
86
+ err ,
75
87
)
76
88
}
89
+
90
+ var appData map [string ]interface {}
91
+ err := json .Unmarshal (a .application .GetData (), & appData )
92
+ if err != nil {
93
+ log .Fatal (err )
94
+ }
95
+ sentry .CaptureEvent (& sentry.Event {
96
+ Message : "Application approved" ,
97
+ Level : sentry .LevelInfo ,
98
+ Extra : appData ,
99
+ })
77
100
}
78
101
79
- func (a * Approver ) printErrorAndExit (err error ) {
80
- log .Fatalf ("Error approving application: %s\n " , err .Error ())
102
+ func (a * Approver ) logErrorAndExit (message string , err error ) {
103
+ sentry .CaptureException (err )
104
+ log .Fatalf ("Error approving issue: %s: %s\n " , message , err .Error ())
81
105
}
82
106
83
107
func (a * Approver ) renderProblems () string {
0 commit comments