Skip to content

Commit

Permalink
Merge pull request #61 from suzuki-shunsuke/feat/support-ci-info-pr-n…
Browse files Browse the repository at this point in the history
…umber

feat: support to get a pull request number from CI_INFO_PR_NUBER
  • Loading branch information
suzuki-shunsuke authored Jan 27, 2021
2 parents 02c4e77 + 23a981e commit c08f3f4
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
6 changes: 6 additions & 0 deletions COMPARED_WITH_TFNOTIFY.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ tfcmt isn't compatible with tfnotify.
* [Add templates configuration](#feature-add-templates-configuration)
* [Add template functions](#feature-add-template-functions)
* [Add command-line options about CI](#feature-add-command-line-options-about-ci)
* [Get pull request number from CI_INFO_PR_NUMBER](#feature-)
* [Add --log-level option and log.level configuration and output structured log with logrus](#feature-add---log-level-option-and-loglevel-configuration-and-output-structured-log-with-logrus)
* [Don't recreate labels](#feature-dont-recreate-labels)
* [--version option and `version` command](#feature---version-option-and-version-command)
Expand Down Expand Up @@ -404,6 +405,11 @@ ex.
$ tfcmt -owner suzuki-shunsuke -repo tfcmt -pr 3 -- terraform plan
```
## Feature: Get pull request number from CI_INFO_PR_NUMBER
[ci-info](https://github.com/suzuki-shunsuke/ci-info) is a CLI tool to get CI related information, and the environment variable `CI_INFO_PR_NUMBER` is set via ci-info by default.
If the pull request number can't bet gotten but `CI_INFO_PR_NUMBER` is being set, `CI_INFO_PR_NUMBER` is used.
## Feature: Add --log-level option and log.level configuration and output structured log with logrus
[#59](https://github.com/suzuki-shunsuke/tfcmt/pull/59)
Expand Down
11 changes: 11 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"io"
"os"
"os/exec"
"strconv"
"strings"
"text/template"

Expand Down Expand Up @@ -193,6 +194,16 @@ func (t *tfcmt) Run(ctx context.Context) error {
if pr := t.context.Int("pr"); pr != 0 {
ci.PR.Number = pr
}
if ci.PR.Number == 0 {
// support suzuki-shunsuke/ci-info
if prS := os.Getenv("CI_INFO_PR_NUMBER"); prS != "" {
a, err := strconv.Atoi(prS)
if err != nil {
return fmt.Errorf("parse CI_INFO_PR_NUMBER %s: %w", prS, err)
}
ci.PR.Number = a
}
}
if buildURL := t.context.String("build-url"); buildURL != "" {
ci.URL = buildURL
}
Expand Down

0 comments on commit c08f3f4

Please sign in to comment.