Skip to content

Commit 0124369

Browse files
authored
Merge pull request #125 from benbotwin/master
Added push notifications when a build fails or finished
2 parents 9ba6991 + 582594a commit 0124369

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

main.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,13 @@ import (
99
shellwords "github.com/mattn/go-shellwords"
1010
"gopkg.in/urfave/cli.v1"
1111

12+
"github.com/0xAX/notificator"
1213
"log"
1314
"os"
1415
"os/signal"
1516
"path/filepath"
1617
"strconv"
18+
"strings"
1719
"syscall"
1820
"time"
1921
)
@@ -26,6 +28,7 @@ var (
2628
colorGreen = string([]byte{27, 91, 57, 55, 59, 51, 50, 59, 49, 109})
2729
colorRed = string([]byte{27, 91, 57, 55, 59, 51, 49, 59, 49, 109})
2830
colorReset = string([]byte{27, 91, 48, 109})
31+
notifier = notificator.New(notificator.Options{AppName: "Gin Build"})
2932
)
3033

3134
func main() {
@@ -218,17 +221,25 @@ func EnvAction(c *cli.Context) {
218221
func build(builder gin.Builder, runner gin.Runner, logger *log.Logger) {
219222
logger.Println("Building...")
220223

224+
notifier.Push("Build Started!", "Building "+builder.Binary()+"...", "", notificator.UR_NORMAL)
221225
err := builder.Build()
222226
if err != nil {
223227
buildError = err
224228
logger.Printf("%sBuild failed%s\n", colorRed, colorReset)
225229
fmt.Println(builder.Errors())
230+
buildErrors := strings.Split(builder.Errors(), "\n")
231+
if err := notifier.Push("Build FAILED!", buildErrors[1], "", notificator.UR_CRITICAL); err != nil {
232+
logger.Println("Notification send failed")
233+
}
226234
} else {
227235
buildError = nil
228236
logger.Printf("%sBuild finished%s\n", colorGreen, colorReset)
229237
if immediate {
230238
runner.Run()
231239
}
240+
if err := notifier.Push("Build Succeded", "Build Finished!", "", notificator.UR_CRITICAL); err != nil {
241+
logger.Println("Notification send failed")
242+
}
232243
}
233244

234245
time.Sleep(100 * time.Millisecond)

wercker.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
box: wercker/golang@1.1.1
1+
box: wercker/golang

0 commit comments

Comments
 (0)