Skip to content

Commit ecd39e4

Browse files
committed
minor #121 Added more logs (Nyholm)
This PR was merged into the master branch. Discussion ---------- Added more logs There are some issues when adding labels to the PRs. I need even more logs to figure out what is wrong. See symfony/symfony#39072 Commits ------- 7f9bd97 Added more logs
2 parents f63c0f9 + 7f9bd97 commit ecd39e4

File tree

6 files changed

+30
-25
lines changed

6 files changed

+30
-25
lines changed

src/Api/Label/GithubLabelApi.php

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use App\Model\Repository;
66
use Github\Api\Issue\Labels;
77
use Github\Exception\RuntimeException;
8+
use Psr\Log\LoggerInterface;
89
use Symfony\Contracts\Cache\CacheInterface;
910
use Symfony\Contracts\Cache\ItemInterface;
1011

@@ -30,10 +31,16 @@ class GithubLabelApi implements LabelApi
3031
*/
3132
private $cache;
3233

33-
public function __construct(Labels $labelsApi, CacheInterface $cache)
34+
/**
35+
* @var LoggerInterface
36+
*/
37+
private $logger;
38+
39+
public function __construct(Labels $labelsApi, CacheInterface $cache, LoggerInterface $logger)
3440
{
3541
$this->labelsApi = $labelsApi;
3642
$this->cache = $cache;
43+
$this->logger = $logger;
3744
}
3845

3946
public function getIssueLabels($issueNumber, Repository $repository): array
@@ -54,7 +61,10 @@ public function getIssueLabels($issueNumber, Repository $repository): array
5461
}
5562
}
5663

57-
return array_keys($this->labelCache[$key]);
64+
$labels = array_keys($this->labelCache[$key]);
65+
$this->logger->debug('Returning labels for {repo}#{issue}', ['repo' => $repository->getFullName(), 'issue' => $issueNumber]);
66+
67+
return $labels;
5868
}
5969

6070
public function addIssueLabel($issueNumber, string $label, Repository $repository)
@@ -65,12 +75,8 @@ public function addIssueLabel($issueNumber, string $label, Repository $repositor
6575
return;
6676
}
6777

68-
$this->labelsApi->add(
69-
$repository->getVendor(),
70-
$repository->getName(),
71-
$issueNumber,
72-
$label
73-
);
78+
$this->logger->debug('Adding label "{label}" for {repo}#{issue}', ['label' => $label, 'repo' => $repository->getFullName(), 'issue' => $issueNumber]);
79+
$this->labelsApi->add($repository->getVendor(), $repository->getName(), $issueNumber, $label);
7480

7581
// Update cache if already loaded
7682
if (isset($this->labelCache[$key])) {

src/Service/LabelNameExtractor.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use App\Api\Label\LabelApi;
66
use App\Model\Repository;
7+
use Psr\Log\LoggerInterface;
78

89
/**
910
* Extract label name from a PR/Issue.
@@ -13,6 +14,7 @@
1314
class LabelNameExtractor
1415
{
1516
private $labelsApi;
17+
private $logger;
1618

1719
private static $labelAliases = [
1820
'bridge\doctrine' => 'DoctrineBridge',
@@ -33,9 +35,10 @@ class LabelNameExtractor
3335
'wdt' => 'WebProfilerBundle',
3436
];
3537

36-
public function __construct(LabelApi $labelsApi)
38+
public function __construct(LabelApi $labelsApi, LoggerInterface $logger)
3739
{
3840
$this->labelsApi = $labelsApi;
41+
$this->logger = $logger;
3942
}
4043

4144
/**
@@ -57,6 +60,8 @@ public function extractLabels($title, Repository $repository)
5760
}
5861
}
5962

63+
$this->logger->debug('Searched for labels in title', ['title' => $title, 'labels' => json_encode($labels)]);
64+
6065
return $labels;
6166
}
6267

tests/Api/Label/GithubLabelApiTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use Github\Api\Issue\Labels;
88
use PHPUnit\Framework\MockObject\MockObject;
99
use PHPUnit\Framework\TestCase;
10+
use Psr\Log\NullLogger;
1011
use Symfony\Component\Cache\Adapter\NullAdapter;
1112

1213
/**
@@ -35,7 +36,7 @@ protected function setUp()
3536
$this->backendApi = $this->getMockBuilder(Labels::class)
3637
->disableOriginalConstructor()
3738
->getMock();
38-
$this->api = new GithubLabelApi($this->backendApi, new NullAdapter());
39+
$this->api = new GithubLabelApi($this->backendApi, new NullAdapter(), new NullLogger());
3940
$this->repository = new Repository(
4041
self::USER_NAME,
4142
self::REPO_NAME,

tests/Service/LabelNameExtractorTest.php

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,15 @@
55
use App\Api\Label\StaticLabelApi;
66
use App\Model\Repository;
77
use App\Service\LabelNameExtractor;
8-
use Github\Api\Issue\Labels;
98
use PHPUnit\Framework\TestCase;
10-
use Symfony\Component\Cache\Adapter\NullAdapter;
9+
use Psr\Log\NullLogger;
1110

1211
class LabelNameExtractorTest extends TestCase
1312
{
1413
public function testExtractLabels()
1514
{
16-
$backendApi = $this->getMockBuilder(Labels::class)
17-
->disableOriginalConstructor()
18-
->getMock();
19-
$api = new StaticLabelApi($backendApi, new NullAdapter());
20-
$extractor = new LabelNameExtractor($api);
15+
$api = new StaticLabelApi();
16+
$extractor = new LabelNameExtractor($api, new NullLogger());
2117
$repo = new Repository('carson-playground', 'symfony');
2218

2319
$this->assertSame(['Messenger'], $extractor->extractLabels('[Messenger] Foobar', $repo));

tests/Subscriber/AutoLabelFromContentSubscriberTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
use App\Service\LabelNameExtractor;
1010
use App\Subscriber\AutoLabelFromContentSubscriber;
1111
use PHPUnit\Framework\TestCase;
12+
use Psr\Log\NullLogger;
1213
use Symfony\Component\EventDispatcher\EventDispatcher;
1314

1415
class AutoLabelFromContentSubscriberTest extends TestCase
@@ -30,7 +31,7 @@ protected function setUp()
3031
->disableOriginalConstructor()
3132
->setMethods(['addIssueLabels'])
3233
->getMock();
33-
$this->autoLabelSubscriber = new AutoLabelFromContentSubscriber($this->labelsApi, new LabelNameExtractor($this->labelsApi));
34+
$this->autoLabelSubscriber = new AutoLabelFromContentSubscriber($this->labelsApi, new LabelNameExtractor($this->labelsApi, new NullLogger()));
3435
$this->repository = new Repository('weaverryan', 'symfony', null);
3536

3637
$this->dispatcher = new EventDispatcher();

tests/Subscriber/AutoUpdateTitleWithLabelSubscriberTest.php

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,9 @@
88
use App\Model\Repository;
99
use App\Service\LabelNameExtractor;
1010
use App\Subscriber\AutoUpdateTitleWithLabelSubscriber;
11-
use Github\Api\Issue\Labels;
1211
use Github\Api\PullRequest;
1312
use PHPUnit\Framework\TestCase;
14-
use Symfony\Component\Cache\Adapter\NullAdapter;
13+
use Psr\Log\NullLogger;
1514
use Symfony\Component\EventDispatcher\EventDispatcher;
1615

1716
class AutoUpdateTitleWithLabelSubscriberTest extends TestCase
@@ -26,16 +25,13 @@ class AutoUpdateTitleWithLabelSubscriberTest extends TestCase
2625

2726
protected function setUp()
2827
{
29-
$backendApi = $this->getMockBuilder(Labels::class)
30-
->disableOriginalConstructor()
31-
->getMock();
32-
$labelsApi = new StaticLabelApi($backendApi, new NullAdapter());
28+
$labelsApi = new StaticLabelApi();
3329
$this->pullRequestApi = $this->getMockBuilder(PullRequest::class)
3430
->disableOriginalConstructor()
3531
->setMethods(['update'])
3632
->getMock();
3733

38-
$this->subscriber = new AutoUpdateTitleWithLabelSubscriber($labelsApi, new LabelNameExtractor($labelsApi), $this->pullRequestApi);
34+
$this->subscriber = new AutoUpdateTitleWithLabelSubscriber($labelsApi, new LabelNameExtractor($labelsApi, new NullLogger()), $this->pullRequestApi);
3935
$this->repository = new Repository('carsonbot-playground', 'symfony', null);
4036

4137
$this->dispatcher = new EventDispatcher();

0 commit comments

Comments
 (0)