예제 #1
0
    public function testCanParseMessagesWithAnExtendedBody()
    {
        $title = "chore(test): Summary";
        $body = <<<___MSG
Optional body

Fixes #123, #456
Refs #789
___MSG;
        $text = "{$title}\n{$body}";
        $msg = new \ElggCommitMessage($text);
        $this->assertTrue($msg->isValidFormat());
        $this->assertSame('chore', $msg->getPart('type'));
        $this->assertSame('test', $msg->getPart('component'));
        $this->assertSame('Summary', $msg->getPart('summary'));
        $this->assertSame($body, $msg->getPart('body'));
    }
} else {
    // check for std in
    $msg_tmp = file_get_contents("php://stdin");
}
require_once 'ElggCommitMessage.php';
$msg = new ElggCommitMessage($msg_tmp);
if (!$msg->getMsg()) {
    usage();
}
if ($msg->shouldIgnore()) {
    output("Ignoring commit.", 'notice');
    exit(0);
}
// basic format
// don't continue if not correct
if (!$msg->isValidFormat()) {
    output("Fail.", 'error');
    output("Not in the format `type(component): summary`", 'error');
    output($msg, 'error');
    if ($is_file) {
        output("\nCommit message saved in " . $argv[1]);
    }
    exit(1);
}
$errors = array();
// line lengths
if (!$msg->isValidLineLength()) {
    $max = $msg->getMaxLineLength();
    foreach ($msg->getLengthyLines() as $line_num) {
        $errors[] = "Longer than {$max} characters at line {$line_num}";
    }