Skip to content

Commit ee145ed

Browse files
committed
bug #149 [Stale] Check if issue is open before making a comment (Nyholm)
This PR was merged into the master branch. Discussion ---------- [Stale] Check if issue is open before making a comment Related to this: symfony/symfony#34002 (comment) Commits ------- 5f1da28 [Stale] Check if issue is open before making a comment
2 parents d4d2cbc + 5f1da28 commit ee145ed

File tree

4 files changed

+24
-6
lines changed

4 files changed

+24
-6
lines changed

src/Service/TaskHandler/CloseStaleIssuesHandler.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,12 @@ public function handle(Task $task): void
3636
if (null === $repository = $this->repositoryProvider->getRepository($task->getRepositoryFullName())) {
3737
return;
3838
}
39+
40+
$issue = $this->issueApi->show($repository, $task->getNumber());
41+
if ('open' !== $issue['state']) {
42+
return;
43+
}
44+
3945
$labels = $this->labelApi->getIssueLabels($task->getNumber(), $repository);
4046
if (in_array('Keep open', $labels)) {
4147
$this->labelApi->removeIssueLabel($task->getNumber(), 'Stalled', $repository);

src/Service/TaskHandler/InformAboutClosingStaleIssuesHandler.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,12 @@ public function handle(Task $task): void
4040
if (null === $repository = $this->repositoryProvider->getRepository($task->getRepositoryFullName())) {
4141
return;
4242
}
43+
44+
$issue = $this->issueApi->show($repository, $task->getNumber());
45+
if ('open' !== $issue['state']) {
46+
return;
47+
}
48+
4349
$labels = $this->labelApi->getIssueLabels($task->getNumber(), $repository);
4450
if (in_array('Keep open', $labels)) {
4551
$this->labelApi->removeIssueLabel($task->getNumber(), 'Stalled', $repository);

tests/Service/TaskHandler/CloseStaleIssuesHandlerTest.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,9 @@ public function testHandleKeepOpen()
2424

2525
$issueApi = $this->getMockBuilder(NullIssueApi::class)
2626
->disableOriginalConstructor()
27-
->setMethods(['close', 'lastCommentWasMadeByBot'])
27+
->setMethods(['close', 'lastCommentWasMadeByBot', 'show'])
2828
->getMock();
29+
$issueApi->expects($this->any())->method('show')->willReturn(['state' => 'open']);
2930
$issueApi->expects($this->any())->method('lastCommentWasMadeByBot')->willReturn(true);
3031
$issueApi->expects($this->never())->method('close');
3132

@@ -45,8 +46,9 @@ public function testHandleComments()
4546

4647
$issueApi = $this->getMockBuilder(NullIssueApi::class)
4748
->disableOriginalConstructor()
48-
->setMethods(['close', 'lastCommentWasMadeByBot'])
49+
->setMethods(['close', 'lastCommentWasMadeByBot', 'show'])
4950
->getMock();
51+
$issueApi->expects($this->any())->method('show')->willReturn(['state' => 'open']);
5052
$issueApi->expects($this->any())->method('lastCommentWasMadeByBot')->willReturn(false);
5153
$issueApi->expects($this->never())->method('close');
5254

@@ -66,8 +68,9 @@ public function testHandleStale()
6668

6769
$issueApi = $this->getMockBuilder(NullIssueApi::class)
6870
->disableOriginalConstructor()
69-
->setMethods(['close', 'lastCommentWasMadeByBot'])
71+
->setMethods(['close', 'lastCommentWasMadeByBot', 'show'])
7072
->getMock();
73+
$issueApi->expects($this->any())->method('show')->willReturn(['state' => 'open']);
7174
$issueApi->expects($this->any())->method('lastCommentWasMadeByBot')->willReturn(true);
7275
$issueApi->expects($this->once())->method('close');
7376

tests/Service/TaskHandler/InformAboutClosingStaleIssuesHandlerTest.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,9 @@ public function testHandleKeepOpen()
2525

2626
$issueApi = $this->getMockBuilder(NullIssueApi::class)
2727
->disableOriginalConstructor()
28-
->setMethods(['close', 'lastCommentWasMadeByBot'])
28+
->setMethods(['close', 'lastCommentWasMadeByBot', 'show'])
2929
->getMock();
30+
$issueApi->expects($this->any())->method('show')->willReturn(['state' => 'open']);
3031
$issueApi->expects($this->any())->method('lastCommentWasMadeByBot')->willReturn(true);
3132
$issueApi->expects($this->never())->method('close');
3233

@@ -52,8 +53,9 @@ public function testHandleComments()
5253

5354
$issueApi = $this->getMockBuilder(NullIssueApi::class)
5455
->disableOriginalConstructor()
55-
->setMethods(['close', 'lastCommentWasMadeByBot'])
56+
->setMethods(['close', 'lastCommentWasMadeByBot', 'show'])
5657
->getMock();
58+
$issueApi->expects($this->any())->method('show')->willReturn(['state' => 'open']);
5759
$issueApi->expects($this->any())->method('lastCommentWasMadeByBot')->willReturn(false);
5860
$issueApi->expects($this->never())->method('close');
5961

@@ -79,8 +81,9 @@ public function testHandleStale()
7981

8082
$issueApi = $this->getMockBuilder(NullIssueApi::class)
8183
->disableOriginalConstructor()
82-
->setMethods(['close', 'lastCommentWasMadeByBot'])
84+
->setMethods(['close', 'lastCommentWasMadeByBot', 'show'])
8385
->getMock();
86+
$issueApi->expects($this->any())->method('show')->willReturn(['state' => 'open']);
8487
$issueApi->expects($this->any())->method('lastCommentWasMadeByBot')->willReturn(true);
8588
$issueApi->expects($this->never())->method('close');
8689

0 commit comments

Comments
 (0)