Skip to content

Commit 151b5c4

Browse files
committed
ci: explain the expected format of bad PR titles better (leanprover-community#36523)
If a PR kind was not recognised, explain which ones are expected. This also clarifies the check's logic: this error was supposed to be emitted already, but wasn't (due to a last-minute refactoring of the linter). Remove the old code path was never run (and is run now).
1 parent c2993b3 commit 151b5c4

2 files changed

Lines changed: 9 additions & 15 deletions

File tree

Mathlib/Tactic/Linter/ValidatePRTitle.lean

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ verify whether the title or body are written in present imperative tense.
1919

2020
open Std.Internal.Parsec String
2121

22-
/-- Basic parser for PR titles: given a title `feat(scope): main title` or `feat: title`,
23-
extracts the `feat` and `scope` components. In the future, this will be extended to also parse
22+
/-- Basic parser for PR titles: given a title `kind(scope): main title` or `kind: title`,
23+
extracts the `kind` and `scope` components. In the future, this will be extended to also parse
2424
the main PR title. -/
2525
-- TODO: also parse and return the main PR title
2626
def prTitle : Parser (String × Option String) :=
@@ -79,20 +79,13 @@ public def validateTitle (title : String) : Array String := Id.run do
7979
if title.startsWith " " then
8080
errors := #["error: the PR title starts with a space"]
8181

82+
let knownKinds := ["feat", "chore", "perf", "refactor", "style", "fix", "doc", "test", "ci"]
8283
match Parser.run prTitle title.trimAsciiStart.copy with
8384
| Except.error _ =>
84-
return errors.push s!"error: the PR title should be of the form\n abbrev: main title\n\
85-
or\n abbrev(scope): main title"
86-
| Except.ok (kind, _scope?) =>
85+
return errors.push s!"error: the PR title should be of the form\n kind: main title\n\
86+
or\n kind(scope): main title\nAllowed values for `kind` are {knownKinds}"
87+
| Except.ok (_kind, _scope?) =>
8788
-- Future: also check scope (and the main PR title)
88-
let knownKinds := ["feat", "chore", "perf", "refactor", "style", "fix", "doc", "test", "ci"]
89-
let mut isFine := false
90-
for k in knownKinds do
91-
isFine := isFine || kind.startsWith k
92-
if isFine == false then
93-
errors := errors.push s!"error: the PR title should be of the form \
94-
\"kind: main title\" or \"kind(scope): main title\"\n
95-
Known PR title kinds are {knownKinds}"
9689
if title.contains " " then
9790
errors := errors.push
9891
"error: the PR title contains multiple consecutive spaces; please add just one"

MathlibTest/ValidatePRTitle.lean

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,10 @@ elab "#check_title " title:str : command => do
2424

2525
/--
2626
info: Message: 'error: the PR title should be of the form
27-
abbrev: main title
27+
kind: main title
2828
or
29-
abbrev(scope): main title'
29+
kind(scope): main title
30+
Allowed values for `kind` are [feat, chore, perf, refactor, style, fix, doc, test, ci]'
3031
-/
3132
#guard_msgs in
3233
#check_title "fsdfs: bad title"

0 commit comments

Comments
 (0)