From 9cceb35addc1374750a9402cb184c37ba690ed12 Mon Sep 17 00:00:00 2001 From: Shunsuke Suzuki Date: Wed, 27 Jan 2021 09:59:15 +0900 Subject: [PATCH 1/2] feat: support to get a pull request number from CI_INFO_PR_NUBER https://github.com/suzuki-shunsuke/ci-info --- main.go | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/main.go b/main.go index 0cb9791e..65d46ea9 100644 --- a/main.go +++ b/main.go @@ -8,6 +8,7 @@ import ( "io" "os" "os/exec" + "strconv" "strings" "text/template" @@ -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 } From 23a981ecbd0aa2238a8cc21fb7cb793f59f667d2 Mon Sep 17 00:00:00 2001 From: Shunsuke Suzuki Date: Wed, 27 Jan 2021 10:10:26 +0900 Subject: [PATCH 2/2] docs: update document --- COMPARED_WITH_TFNOTIFY.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/COMPARED_WITH_TFNOTIFY.md b/COMPARED_WITH_TFNOTIFY.md index 0eccb1c2..dc0b4bee 100644 --- a/COMPARED_WITH_TFNOTIFY.md +++ b/COMPARED_WITH_TFNOTIFY.md @@ -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) @@ -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)