Skip to content

Commit

Permalink
Add pint ci --base-branch flag
Browse files Browse the repository at this point in the history
  • Loading branch information
prymitive committed Jul 17, 2022
1 parent 970b2af commit c213b6f
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 0 deletions.
11 changes: 11 additions & 0 deletions cmd/pint/ci.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ import (
"github.com/urfave/cli/v2"
)

var baseBranchFlag = "base-branch"

var ciCmd = &cli.Command{
Name: "ci",
Usage: "Lint CI changes",
Expand All @@ -30,6 +32,12 @@ var ciCmd = &cli.Command{
Value: false,
Usage: "Require all rules to have an owner set via comment",
},
&cli.StringFlag{
Name: baseBranchFlag,
Aliases: []string{"b"},
Value: "",
Usage: "Set base branch to use for PR checks (main, master, ...)",
},
},
}

Expand All @@ -45,6 +53,9 @@ func actionCI(c *cli.Context) error {
}

baseBranch := strings.Split(meta.cfg.CI.BaseBranch, "/")[len(strings.Split(meta.cfg.CI.BaseBranch, "/"))-1]
if c.String(baseBranchFlag) != "" {
baseBranch = c.String(baseBranchFlag)
}
currentBranch, err := git.CurrentBranch(git.RunGit)
if err != nil {
return fmt.Errorf("failed to get the name of current branch")
Expand Down
33 changes: 33 additions & 0 deletions cmd/pint/tests/0082_ci_base_branch_flag.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
mkdir testrepo
cd testrepo
exec git init --initial-branch=main .

cp ../src/v1.yml rules.yml
cp ../src/.pint.hcl .
env GIT_AUTHOR_NAME=pint
env GIT_AUTHOR_EMAIL=pint@example.com
env GIT_COMMITTER_NAME=pint
env GIT_COMMITTER_EMAIL=pint@example.com
exec git add .
exec git commit -am 'import rules and config'

pint.ok --no-color ci --base-branch=main
! stdout .
cmp stderr ../stderr.txt

-- stderr.txt --
level=info msg="Loading configuration file" path=.pint.hcl
level=info msg="Running from base branch, skipping checks" branch=main
-- src/v1.yml --
- record: rule1
expr: sum(foo) by(job)
- record: rule2
expr: sum(foo) bi(job)

-- src/.pint.hcl --
ci {
baseBranch = "foo"
}
parser {
relaxed = [".*"]
}
4 changes: 4 additions & 0 deletions docs/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@

- Fixed line reporting on some strict parser errors.

### Added

- Added `--base-branch` flag to `pint ci` command.

## v0.24.0

### Added
Expand Down

0 comments on commit c213b6f

Please sign in to comment.