mirror of
https://github.com/macports/mpbot-github.git
synced 2026-07-13 03:18:39 -07:00
Add production mode in PR bot
This commit is contained in:
+7
-1
@@ -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()
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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),
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user