Skip to content

Commit 450fbd8

Browse files
committed
BUG/MEDIUM: disallow unprocessed tags, apply only one definition per set
1 parent 64f10fd commit 450fbd8

2 files changed

Lines changed: 18 additions & 7 deletions

File tree

check-commit/check.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,7 @@ func (c CommitPolicyConfig) CheckSubject(rawSubject []byte) error {
163163
if c.CheckPatchTypes(tag, severity, pType) { // we found what we were looking for, so consume input
164164
rawSubject = rawSubject[submatch[1]:]
165165
tagOK = tagOK || true
166+
break
166167
}
167168
}
168169

@@ -171,6 +172,11 @@ func (c CommitPolicyConfig) CheckSubject(rawSubject []byte) error {
171172
}
172173
}
173174

175+
submatch := r.FindSubmatchIndex(rawSubject)
176+
if len(submatch) != 0 { // no match
177+
return fmt.Errorf("detected unprocessed tags, %w", ErrTagScope)
178+
}
179+
174180
return checkSubjectText(string(rawSubject))
175181
}
176182

check-commit/check_test.go

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,38 +17,43 @@ func TestCheckSubject(t *testing.T) {
1717
wantErr bool
1818
}{
1919
{
20-
name: "valid type/severity",
20+
name: "valid type and severity",
2121
args: args{subject: "BUG/MEDIUM: config: add default location of path to the configuration file"},
2222
wantErr: false,
2323
},
2424
{
25-
name: "bug-fail",
25+
name: "short subject",
2626
args: args{subject: "BUG/MEDIUM: config: default"},
2727
wantErr: true,
2828
},
2929
{
3030
name: "missing severity",
31-
args: args{subject: "BUG/: config: default"},
31+
args: args{subject: "BUG/: config: default implementation"},
3232
wantErr: true,
3333
},
3434
{
3535
name: "wrong tag",
36-
args: args{subject: "WRONG: config: default"},
36+
args: args{subject: "WRONG: config: default implementation"},
3737
wantErr: true,
3838
},
3939
{
4040
name: "wrong severity",
41-
args: args{subject: "BUG/WRONG: config: default"},
41+
args: args{subject: "BUG/WRONG: config: default implementation"},
4242
wantErr: true,
4343
},
4444
{
4545
name: "double spaces",
46-
args: args{subject: "BUG/MEDIUM: config: default"},
46+
args: args{subject: "BUG/MEDIUM: config: default implementation"},
4747
wantErr: true,
4848
},
4949
{
5050
name: "trailing spaces",
51-
args: args{subject: "BUG/MEDIUM: config: default "},
51+
args: args{subject: "BUG/MEDIUM: config: default implementation "},
52+
wantErr: true,
53+
},
54+
{
55+
name: "unprocessed tags remain",
56+
args: args{subject: "BUG/MINOR: MAJOR: config: default implementation"},
5257
wantErr: true,
5358
},
5459
}

0 commit comments

Comments
 (0)