/** * @param int $issueNumber The GitHub issue number * @param string $newStatus A Status::* constant */ public function setIssueStatus($issueNumber, $newStatus) { if (!isset($this->statusToLabel[$newStatus])) { throw new \InvalidArgumentException(sprintf('Invalid status "%s"', $newStatus)); } $newLabel = $this->statusToLabel[$newStatus]; $currentLabels = $this->labelsApi->getIssueLabels($issueNumber); $addLabel = true; foreach ($currentLabels as $label) { // Ignore non-status if (!isset($this->labelToStatus[$label])) { continue; } if ($newLabel === $label) { $addLabel = false; continue; } // Remove other statuses $this->labelsApi->removeIssueLabel($issueNumber, $label); } // Ignored if the label is already set if ($addLabel) { $this->labelsApi->addIssueLabel($issueNumber, $newLabel); } }
public function testRemoveIssueLabelIgnoresUnsetLabel() { $this->backendApi->expects($this->once())->method('all')->with(self::USER_NAME, self::REPO_NAME, 1234)->willReturn(array(array('name' => 'a'), array('name' => 'b'), array('name' => 'c'))); $this->backendApi->expects($this->never())->method('remove'); $this->assertSame(array('a', 'b', 'c'), $this->api->getIssueLabels(1234)); $this->api->removeIssueLabel(1234, 'd'); $this->assertSame(array('a', 'b', 'c'), $this->api->getIssueLabels(1234)); }