Skip to content

Commit

Permalink
Merge pull request #18 from christofdamian/check-review-comments
Browse files Browse the repository at this point in the history
also check review (diff) commets
  • Loading branch information
christofdamian committed May 30, 2016
2 parents f264ab5 + 0a36f63 commit 2d69c30
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 9 deletions.
3 changes: 3 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
CHANGES
=======
0.5.13
* also check review (diff) comments

0.5.12
* update github api
* check combined status
Expand Down
12 changes: 10 additions & 2 deletions src/PlusPull/GitHub.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,9 @@ public function checkRepositoryLabelExists($label)
$result = false;
foreach ($labels as $existingLabel) {
$result = (strcmp($label->name, $existingLabel->name) == 0);
if ($result) { break; }
if ($result) {
break;
}
}
return $result;
}
Expand Down Expand Up @@ -181,8 +183,14 @@ public function getComments($number)
$number
);

$review_comments = $this->client->api('pull_request')->comments()->all(
$this->username,
$this->repository,
$number
);

$result = array();
foreach ($comments as $comment) {
foreach (array_merge($comments, $review_comments) as $comment) {
$result[] = new Comment(
$comment['user']['login'],
$comment['body']
Expand Down
56 changes: 49 additions & 7 deletions tests/PlusPull/GitHubTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -248,8 +248,10 @@ public function testCheckRepositoryLabelExists()
->will($this->returnValue($issue));


$this->assertEquals(false, $this->github->checkRepositoryLabelExists($information));
$this->assertEquals(true, $this->github->checkRepositoryLabelExists($blocked));
$this->assertFalse(
$this->github->checkRepositoryLabelExists($information)
);
$this->assertTrue($this->github->checkRepositoryLabelExists($blocked));
}

public function testAddRepositoryLabel()
Expand Down Expand Up @@ -285,7 +287,10 @@ public function testAddRepositoryLabel()
->will($this->returnValue($issue));


$this->assertEquals($expected, $this->github->addRepositoryLabel($expected));
$this->assertEquals(
$expected,
$this->github->addRepositoryLabel($expected)
);
}

public function testGetLabels()
Expand Down Expand Up @@ -368,7 +373,10 @@ public function testAddLabel()
->will($this->returnValue($issue));


$this->assertEquals($expected, $this->github->addLabel($number, $expected));
$this->assertEquals(
$expected,
$this->github->addLabel($number, $expected)
);
}

public function testRemoveLabel()
Expand Down Expand Up @@ -406,8 +414,8 @@ public function testRemoveLabel()

$this->assertEquals(
null,
$this->github->removeLabel($number, $labelToRemove
));
$this->github->removeLabel($number, $labelToRemove)
);
}

public function testGetComments()
Expand All @@ -423,8 +431,19 @@ public function testGetComments()
),
),
);
$reviewCommentLogin = 'userb';
$reviewCommentBody = 'review comment';
$reviewCommentsResult = array(
array(
'body' => $reviewCommentBody,
'user' => array(
'login' => $reviewCommentLogin,
),
),
);
$expected = array(
new Comment($commentLogin, $commentBody),
new Comment($reviewCommentLogin, $reviewCommentBody),
);

$comments = $this->getMockBuilder('Github\Api\Issue\Comments')
Expand All @@ -446,11 +465,34 @@ public function testGetComments()
->method('comments')
->will($this->returnValue($comments));

$this->client->expects($this->once())
$this->client->expects($this->at(0))
->method('api')
->with($this->equalTo('issues'))
->will($this->returnValue($issue));

$reviewComments = $this->getMockBuilder('Github\Api\Issue\Comments')
->disableOriginalConstructor()
->getMock();
$reviewComments->expects($this->once())
->method('all')
->with(
$this->equalTo(self::GITHUP_USERNAME),
$this->equalTo(self::GITHUB_REPOSITORY),
$this->equalTo($number)
)
->will($this->returnValue($reviewCommentsResult));

$pullRequest = $this->getMockBuilder('Github\Api\PullRequest')
->disableOriginalConstructor()
->getMock();
$pullRequest->expects($this->once())
->method('comments')
->will($this->returnValue($reviewComments));

$this->client->expects($this->at(1))
->method('api')
->with($this->equalTo('pull_request'))
->will($this->returnValue($pullRequest));

$this->assertEquals($expected, $this->github->getComments($number));
}
Expand Down

0 comments on commit 2d69c30

Please sign in to comment.