-
Notifications
You must be signed in to change notification settings - Fork 0
/
github.go
47 lines (40 loc) · 1.39 KB
/
github.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
// Copyright 2017 Inca Roads LLC. All rights reserved.
// Use of this source code is governed by licenses granted by the
// copyright holder including that found in the LICENSE file.
// Github webhook that enables server auto-restart on commit
package main
import (
"encoding/json"
"fmt"
"io"
"net/http"
"os"
)
// Github webhook
func inboundWebGithubHandler(rw http.ResponseWriter, req *http.Request) {
stats.Count.HTTP++
stats.Count.HTTPGithub++
// Unpack the request
body, err := io.ReadAll(req.Body)
if err != nil {
fmt.Printf("Github webhook: error reading body: %s\n", err)
return
}
var p PushPayload
err = json.Unmarshal(body, &p)
if err != nil {
fmt.Printf("Github webhook: error unmarshaling body: %s\n", err)
return
}
// Handle 'git commit -mm' and 'git commit -amm', used in dev intermediate builds, in a more aesthetically pleasing manner.
if p.HeadCommit.Commit.Message == "m" {
ServerLog(fmt.Sprintf("*** RESTARTING because %s pushed %s's commit to GitHub\n", p.Pusher.Name, p.HeadCommit.Commit.Committer.Name))
} else {
sendToSafecastOps(fmt.Sprintf("** Restarting ** %s %s",
p.HeadCommit.Commit.Committer.Name, p.HeadCommit.Commit.Message), SlackMsgUnsolicitedOps)
ServerLog(fmt.Sprintf("*** RESTARTING because %s pushed %s's commit to GitHub: %s\n",
p.Pusher.Name, p.HeadCommit.Commit.Committer.Name, p.HeadCommit.Commit.Message))
}
// Exit
os.Exit(0)
}