Skip to content

Commit 41f974c

Browse files
committed
adding more logging - tracking down a production bug!
1 parent b6d405d commit 41f974c

File tree

8 files changed

+32
-6
lines changed

8 files changed

+32
-6
lines changed

app/config/github.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ services:
44
class: AppBundle\Subscriber\StatusChangeByCommentSubscriber
55
arguments:
66
- '@app.status_api'
7+
- '@logger'
78

89
app.subscriber.needs_review_new_pr_subscriber:
910
class: AppBundle\Subscriber\NeedsReviewNewPRSubscriber

app/config/services.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ services:
2828

2929
app.status_api:
3030
class: AppBundle\Issues\GitHub\GitHubStatusApi
31-
arguments: ['@app.github.cached_labels_api']
31+
arguments: ['@app.github.cached_labels_api', '@logger']
3232

3333
app.github.request_handler:
3434
class: AppBundle\Issues\GitHubRequestHandler

src/AppBundle/Issues/GitHub/GitHubStatusApi.php

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use AppBundle\Issues\Status;
66
use AppBundle\Issues\StatusApi;
77
use AppBundle\Repository\Repository;
8+
use Psr\Log\LoggerInterface;
89

910
class GitHubStatusApi implements StatusApi
1011
{
@@ -21,11 +22,16 @@ class GitHubStatusApi implements StatusApi
2122
* @var CachedLabelsApi
2223
*/
2324
private $labelsApi;
25+
/**
26+
* @var LoggerInterface
27+
*/
28+
private $logger;
2429

25-
public function __construct(CachedLabelsApi $labelsApi)
30+
public function __construct(CachedLabelsApi $labelsApi, LoggerInterface $logger)
2631
{
2732
$this->labelsApi = $labelsApi;
2833
$this->labelToStatus = array_flip(self::$statusToLabel);
34+
$this->logger = $logger;
2935
}
3036

3137
/**
@@ -59,6 +65,12 @@ public function setIssueStatus($issueNumber, $newStatus, Repository $repository)
5965
}
6066

6167
// Remove other statuses
68+
$this->logger->debug(sprintf(
69+
'Removing label %s from issue %s on repository %s',
70+
$label,
71+
$issueNumber,
72+
$repository->getFullName()
73+
));
6274
$this->labelsApi->removeIssueLabel($issueNumber, $label, $repository);
6375
}
6476

src/AppBundle/Issues/GitHubRequestHandler.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ public function handle(Request $request)
7676
try {
7777
$this->dispatcher->dispatch('github.'.$eventName, $event);
7878
} catch (\Exception $e) {
79-
throw new \RuntimeException(sprintf('Failed dispatching "%s" event for "%s" repository.', $eventName, $repository->getName()), 0, $e);
79+
throw new \RuntimeException(sprintf('Failed dispatching "%s" event for "%s" repository.', $eventName, $repository->getFullName()), 0, $e);
8080
}
8181

8282
$responseData = $event->getResponseData();

src/AppBundle/Repository/Repository.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,4 +79,9 @@ public function getNeedsReviewUrl()
7979
rawurlencode(GitHubStatusApi::getNeedsReviewLabel())
8080
);
8181
}
82+
83+
public function getFullName()
84+
{
85+
return sprintf('%s/%s', $this->getVendor(), $this->getName());
86+
}
8287
}

src/AppBundle/Subscriber/StatusChangeByCommentSubscriber.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
use AppBundle\GitHubEvents;
77
use AppBundle\Issues\Status;
88
use AppBundle\Issues\StatusApi;
9+
use Psr\Log\LoggerInterface;
910
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
1011

1112
class StatusChangeByCommentSubscriber implements EventSubscriberInterface
@@ -18,10 +19,12 @@ class StatusChangeByCommentSubscriber implements EventSubscriberInterface
1819
];
1920

2021
private $statusApi;
22+
private $logger;
2123

22-
public function __construct(StatusApi $statusApi)
24+
public function __construct(StatusApi $statusApi, LoggerInterface $logger)
2325
{
2426
$this->statusApi = $statusApi;
27+
$this->logger = $logger;
2528
}
2629

2730
/**
@@ -47,6 +50,7 @@ public function onIssueComment(GitHubEvent $event)
4750
// Second subpattern = first status character
4851
$newStatus = static::$triggerWordToStatus[strtolower(end($matches[1]))];
4952

53+
$this->logger->debug(sprintf('Setting issue number %s to status %s', $issueNumber, $newStatus));
5054
$this->statusApi->setIssueStatus($issueNumber, $newStatus, $repository);
5155
}
5256

src/AppBundle/Tests/Issues/GitHub/GitHubStatusApiTest.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,10 @@ protected function setUp()
3636
$this->labelsApi = $this->getMockBuilder('AppBundle\Issues\GitHub\CachedLabelsApi')
3737
->disableOriginalConstructor()
3838
->getMock();
39-
$this->api = new GitHubStatusApi($this->labelsApi);
39+
$logger = $this->getMockBuilder('Psr\Log\LoggerInterface')
40+
->disableOriginalConstructor()
41+
->getMock();
42+
$this->api = new GitHubStatusApi($this->labelsApi, $logger);
4043
$this->repository = new Repository(
4144
self::USER_NAME,
4245
self::REPO_NAME,

src/AppBundle/Tests/Subscriber/StatusChangeByCommentSubscriberTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ public static function setUpBeforeClass()
3030
protected function setUp()
3131
{
3232
$this->statusApi = $this->getMock('AppBundle\Issues\StatusApi');
33-
$this->statusChangeSubscriber = new StatusChangeByCommentSubscriber($this->statusApi);
33+
$logger = $this->getMock('Psr\Log\LoggerInterface');
34+
$this->statusChangeSubscriber = new StatusChangeByCommentSubscriber($this->statusApi, $logger);
3435
$this->repository = new Repository('weaverryan', 'symfony', [], null);
3536

3637
self::$dispatcher->addSubscriber($this->statusChangeSubscriber);

0 commit comments

Comments
 (0)