From 1dc08f58a773dd83773242ec414508f20b9e77f5 Mon Sep 17 00:00:00 2001 From: Zero King Date: Sun, 16 Jul 2017 10:28:30 +0000 Subject: [PATCH] Add production mode in PR bot --- pr/prbot/main.go | 8 +++++++- pr/webhook/pull_request.go | 6 +++++- pr/webhook/server.go | 9 +++++---- 3 files changed, 17 insertions(+), 6 deletions(-) diff --git a/pr/prbot/main.go b/pr/prbot/main.go index 57f14d9..f2b8973 100644 --- a/pr/prbot/main.go +++ b/pr/prbot/main.go @@ -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() } diff --git a/pr/webhook/pull_request.go b/pr/webhook/pull_request.go index 249be78..97c937f 100644 --- a/pr/webhook/pull_request.go +++ b/pr/webhook/pull_request.go @@ -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) diff --git a/pr/webhook/server.go b/pr/webhook/server.go index d43f134..a7b4d89 100644 --- a/pr/webhook/server.go +++ b/pr/webhook/server.go @@ -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), } }