The check implements by default the following grammar for commit messages, while it can be customized like shown later. Message ::= Statement+ | Statement* Comment+ Statement ::= Reference | Fixed | Implemented | Documented | Tested | Added | Translated Comment ::= '# ' TextLine | '#\n' Reference ::= '- Refs' BugNr ': ' TextLine Text? Fixed ::= '- ' FixedString BugNr ': ' TextLine Text? Implemented ::= '- Implemented' BugNr? ': ' TextLine Text? Documented ::= '- Documented' BugNr? ': ' TextLine Text? Tested ::= '- Tested: ' TextLine Text? Added ::= '- Added: ' TextLine Text? Translated ::= '- Translated: ' TextLine Text? FixedString ::= 'Fixed' | 'Closed' Text ::= ' ' TextLine Text? BugNr ::= ' #' [1-9]+[0-9]* TextLine ::= [\x20-\x7E]+ "\n" With one additional condition not mentioned in the grammar, that no line should ever exceed 79 characters per line. A textual description of the rules above: All messages should wrap at 79 characters per line. This means, if you are writing multiple lines after a message starting with a "- " each following line should be indented by exactly two spaces. Including descriptive text in your commit messages is generally important to offer a good overview on the commit when the issue tracker is not available (commit mails, history). All messages may include references to existing issues to add status updates to the issue, which should look like:: - Refs #: Where references the ticket and the describes what you did. Comments -------- You may always append arbitrary comments in your commit messages, where each line should start with a number sign (#). Text in these lines won't be checked. Bug fix ------- A bug fix commit message should follow the following scheme:: - Fixed #: Where references the closed bug and is a description of the bug and the fix. Keep in mind that the texts will be used for the changelog, so please check the spelling before committing. The bug number is not optional, which means that there should be an open bug in the issue tracker for *each* bug you fix. For compatibility with other issue tracker you may also use "Closed" instead of "Fixed" in your message, but "Fixed" is highly preferred. New features ------------ If you implemented a new feature, your commit message should look like:: - Implemented[ #]: Where is a short description of the feature you implemented, and may optionally reference a feature request in the bug tracker. Keep in mind that the texts will be used for the changelog, so please check the spelling before committing. Documentation ------------- If you extended your documentation, your commit message should look like:: - Documented[ #]: Where optionally specifies a documentation request, and the text describes what you documented. Additional tests ---------------- If you added tests for some feature, your commit message should look like:: - Tested: Where describes the feature(s) you are testing. Other commits ------------- If your commit does not match any of the above rules you should only include a comment in your commit message or extend this document with your commit message of desire. Even we have a contextfree grammar for the language, we implement the trivial parser using regular expressions. You can customize the allowed keywords in the commit messages and if a bug number is optional for each keyword, by providing your own specification array, like described in the constructor documentation.
Inheritance: extends pchCheck
Example #1
0
    public function testGeneratedCustomEBNF()
    {
        $parser = new pchCommitMessageCheck(array('Done' => pchCommitMessageCheck::REQUIRED, 'Tested' => pchCommitMessageCheck::OPTIONAL, 'Fixed' => pchCommitMessageCheck::PROHIBITED));
        $expectation = <<<'EOEBNF'
Message       ::= Statement+ | Statement* Comment+
Statement     ::= Done | Tested | Fixed
Comment       ::= '# ' TextLine | '#\n'

Done          ::= '- Done'         BugNr  ': ' TextLine Text?
Tested        ::= '- Tested'       BugNr? ': ' TextLine Text?
Fixed         ::= '- Fixed'               ': ' TextLine Text?

Text          ::= '  ' TextLine Text?
BugNr         ::= ' #' [1-9]+[0-9]*
TextLine      ::= [\x20-\x7E]+ "\n"

EOEBNF;
        $this->assertEquals($expectation, $parser->getEBNF());
    }
Example #2
0
 /**
  * Test valid commit messages from data provider
  * 
  * @dataProvider getCustomCommitMessages
  */
 public function testValidCustomCommitMessages($message, $expectation)
 {
     $parser = new pchCommitMessageCheck(array('Done' => pchCommitMessageCheck::REQUIRED, 'Tested' => pchCommitMessageCheck::OPTIONAL, 'Fixed' => pchCommitMessageCheck::PROHIBITED));
     $this->assertEquals(array(), $parser->parse($message));
     $this->assertEquals($expectation, $parser->getResult());
 }