Skip to content

Commit

Permalink
Merge pull request #65 from reload/handle-empty-watchers
Browse files Browse the repository at this point in the history
Handle empty watchers
  • Loading branch information
xendk authored Feb 21, 2024
2 parents 4f9dab1 + 96073c6 commit 1dc20bb
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/JiraSecurityIssue.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public function __construct()
$watchers = \getenv('JIRA_WATCHERS');

if ($watchers) {
$this->watchers = \explode(',', $watchers);
$this->watchers = \array_filter(\explode(',', \trim($watchers)));
}

$conf = [
Expand Down
44 changes: 44 additions & 0 deletions tests/JiraSecurityIssueTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,50 @@ public function testWatcherNotFound(): void
->ensure();
}

public function testEmptyWatcher(): void
{
\putenv('JIRA_WATCHERS= ');

$issue = $this->newIssue();

$this->issueService
->addComment(Argument::any(), Argument::any())
->willReturn(new Comment());

$this->issueService
->create(Argument::any())
->will(static function () {
$issue = new Issue();
$issue->key = 'ABC-17';

return $issue;
});

$this->userService
->findAssignableUsers([
'query' => ' ',
'project' => 'ABC',
'maxResults' => 1,
])
->willReturn([new User(['accountId' => 'abcd', 'displayName' => 'efgh'])]);

$this->issueService
->addComment(
'ABC-17',
$issue->createComment(
"No watchers on this issue, remember to notify relevant people.",
),
)
->shouldBeCalled();

$this->issueService->addWatcher(Argument::any(), Argument::any())->shouldNotBeCalled();

$issue
->setTitle('The title')
->setBody('Lala')
->ensure();
}

/**
* Create a new, properly mocked, JiraSecurityIssue.
*/
Expand Down

0 comments on commit 1dc20bb

Please sign in to comment.