Add production mode in PR bot

This commit is contained in:
Zero King
2017-07-16 10:28:30 +00:00
parent bc693775f6
commit 1dc08f58a7
3 changed files with 17 additions and 6 deletions
+7 -1
View File
@@ -21,5 +21,11 @@ func main() {
log.Fatal("HUB_BOT_SECRET not found")
}
webhook.NewReceiver(*webhookAddr, hookSecret, botSecret).Start()
prodFlag := false
if os.Getenv("BOT_ENV") == "production" {
prodFlag = true
}
webhook.NewReceiver(*webhookAddr, hookSecret, botSecret, prodFlag).Start()
}
+5 -1
View File
@@ -56,8 +56,12 @@ func (receiver *Receiver) handlePullRequest(body []byte) {
switch *event.Action {
case "opened":
// Notify maintainers
mentionSymbol := "@_"
if receiver.production {
mentionSymbol = "@"
}
if len(handles) > 0 {
body := "Notifying maintainers: @_" + strings.Join(handles, " @_")
body := "Notifying maintainers: " + mentionSymbol + strings.Join(handles, " "+mentionSymbol)
err = receiver.githubClient.CreateComment(owner, repo, number, &body)
if err != nil {
log.Println(err)
+5 -4
View File
@@ -14,14 +14,15 @@ import (
type Receiver struct {
listenAddr string
hookSecret []byte
production bool
githubClient *githubapi.Client
}
func NewReceiver(listenAddr string, hookSecret []byte, botSecret string) *Receiver {
func NewReceiver(listenAddr string, hookSecret []byte, botSecret string, production bool) *Receiver {
return &Receiver{
listenAddr: listenAddr,
hookSecret: hookSecret,
// TODO: canonical owner
listenAddr: listenAddr,
hookSecret: hookSecret,
production: production,
githubClient: githubapi.NewClient(botSecret),
}
}