Skip to content

Commit 7448f5d

Browse files
committed
Added support for Commit::getSubjectMessage and Commit::getBodyMessage
1 parent 5c9f79f commit 7448f5d

File tree

3 files changed

+65
-2
lines changed

3 files changed

+65
-2
lines changed

src/Gitonomy/Git/Commit.php

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -381,4 +381,35 @@ public function getMessage()
381381

382382
return $this->message;
383383
}
384+
385+
/**
386+
* Returns the subject message (the first line)
387+
*
388+
* @return string The subject message
389+
*/
390+
public function getSubjectMessage()
391+
{
392+
$message = $this->getMessage();
393+
394+
$lines = explode("\n", $message);
395+
396+
return reset($lines);
397+
}
398+
399+
/**
400+
* Return the body message
401+
*
402+
* @return string The body message
403+
*/
404+
public function getBodyMessage()
405+
{
406+
$message = $this->getMessage();
407+
408+
$lines = explode("\n", $message);
409+
410+
array_shift($lines);
411+
array_shift($lines);
412+
413+
return implode("\n", $lines);
414+
}
384415
}

tests/Gitonomy/Git/Tests/AbstractTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ abstract class AbstractTest extends \PHPUnit_Framework_TestCase
2121

2222
const LONGFILE_COMMIT = '4f17752acc9b7c54ba679291bf24cb7d354f0f4f';
2323
const BEFORE_LONGFILE_COMMIT = 'e0ec50e2af75fa35485513f60b2e658e245227e9';
24+
const LONGMESSAGE_COMMIT = '3febd664b6886344a9b32d70657687ea4b1b4fab';
2425
const INITIAL_COMMIT = '74acd054c8ec873ae6be044041d3a85a4f890ba5';
2526

2627
/**

tests/Gitonomy/Git/Tests/CommitTest.php

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -170,9 +170,40 @@ public function testGetMessage($repository)
170170
*/
171171
public function testGetShortMessage($repository)
172172
{
173-
$commit = $repository->getCommit(self::LONGFILE_COMMIT);
173+
$commit = $repository->getCommit(self::LONGMESSAGE_COMMIT);
174+
175+
$this->assertEquals('Fixed perm...', $commit->getShortMessage(10));
176+
}
177+
178+
/**
179+
* @dataProvider provideFoobar
180+
*/
181+
public function testGetSubjectMessage($repository)
182+
{
183+
$commit = $repository->getCommit(self::LONGMESSAGE_COMMIT);
184+
185+
$this->assertEquals('Fixed permissions of test.sh. Basically I just run bash command.', $commit->getSubjectMessage());
186+
}
187+
188+
/**
189+
* @dataProvider provideFoobar
190+
*/
191+
public function testGetBodyMessage($repository)
192+
{
193+
$commit = $repository->getCommit(self::LONGMESSAGE_COMMIT);
194+
$message = <<<EOL
195+
If you want to know everything,
196+
I ran something like `chmox +x test.sh`
197+
198+
Hello and good bye.
199+
200+
EOL;
201+
202+
$this->assertEquals($message, $commit->getBodyMessage());
203+
204+
$commit = $repository->getCommit(self::INITIAL_COMMIT);
174205

175-
$this->assertEquals('add a long file', $commit->getShortMessage());
206+
$this->assertEquals('', $commit->getBodyMessage());
176207
}
177208

178209
/**

0 commit comments

Comments
 (0)