Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support to run tfnotify locally #35

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 2 additions & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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":
Expand Down
9 changes: 9 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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"},
Expand Down