Skip to content

Commit

Permalink
fix: disallow 0 as valid jira issue id
Browse files Browse the repository at this point in the history
This change fixes an issue that would allow JIRA-0 to be a valid Jira issue key. Id within Jira always start at 1, and cannot be prefixed by a any amount of leading 0's.

Fixes siderolabs#191

Signed-off-by: André Valentin <[email protected]>
  • Loading branch information
André Valentin authored and talos-bot committed Dec 3, 2020
1 parent 5b58100 commit 73f334a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
2 changes: 1 addition & 1 deletion internal/policy/commit/check_jira.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func (j *JiraCheck) Errors() []error {
func (c Commit) ValidateJiraCheck() policy.Check {
check := &JiraCheck{}

reg := regexp.MustCompile(`.* \[?(\w+)-\d+\]?.*`)
reg := regexp.MustCompile(`.* \[?(\w+)-[1-9]{1}\d*\]?.*`)

if reg.MatchString(c.msg) {
submatch := reg.FindStringSubmatch(c.msg)
Expand Down
12 changes: 12 additions & 0 deletions internal/policy/commit/check_jira_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,18 @@ func TestCommit_ValidateJiraCheck(t *testing.T) {
},
want: want{errorCount: 1},
},
{
name: "Invalid jira issue number",
fields: fields{
Header: &HeaderChecks{
Jira: &JiraChecks{
Keys: []string{"JIRA", "PROJ"},
},
},
msg: "fix: JIRA-0 valid commit",
},
want: want{errorCount: 1},
},
{
name: "Valid commit with scope",
fields: fields{
Expand Down

0 comments on commit 73f334a

Please sign in to comment.