From 1e25d7a292bd4531a15087826aca5dbf09037d75 Mon Sep 17 00:00:00 2001 From: b4b4r07 Date: Fri, 12 Apr 2019 20:17:24 +0900 Subject: [PATCH] Add(core): Support to run tfnotify locally --- README.md | 8 +++++++- config/config.go | 2 ++ main.go | 9 +++++++++ 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 5907d72..a1a19cf 100644 --- a/README.md +++ b/README.md @@ -234,9 +234,15 @@ Currently, supported CI are here: - Travis CI - AWS CodeBuild +If you want to run tfnotify locally and use GitHub as notifier, please set `--pr` flag with `--ci=local` like the following: + +```console +$ terraform plan | ./tfnotify --ci "local" --pr "2" plan +``` + ### Private Repository Considerations -GitHub private repositories require the `repo` and `write:discussion` permissions. +GitHub private repositories require the `repo` and `write:discussion` permissions. ## Committers diff --git a/config/config.go b/config/config.go index 419a4b1..1d471d1 100644 --- a/config/config.go +++ b/config/config.go @@ -96,6 +96,8 @@ func (cfg *Config) Validation() error { switch strings.ToLower(cfg.CI) { case "": return errors.New("ci: need to be set") + case "local": + // ok pattern case "circleci", "circle-ci": // ok pattern case "travis", "travisci", "travis-ci": diff --git a/main.go b/main.go index eb9e8c2..9ab46cf 100644 --- a/main.go +++ b/main.go @@ -38,6 +38,14 @@ func (t *tfnotify) Run() error { var ci CI var err error switch ciname { + case "local": + ci = CI{ + URL: "", + PR: PullRequest{ + Number: t.context.GlobalInt("pr"), + Revision: "", + }, + } case "circleci", "circle-ci": ci, err = circleci() if err != nil { @@ -134,6 +142,7 @@ func main() { app.Usage = description app.Version = version app.Flags = []cli.Flag{ + cli.IntFlag{Name: "pr", Usage: "Pull request number. this is useful for running locally. this should be given with --ci=local"}, cli.StringFlag{Name: "ci", Usage: "name of CI to run tfnotify"}, cli.StringFlag{Name: "config", Usage: "config path"}, cli.StringFlag{Name: "notifier", Usage: "notification destination"},