Skip to content

Commit

Permalink
[#jira] Fix billable flag
Browse files Browse the repository at this point in the history
  • Loading branch information
larowlan committed Jan 15, 2019
1 parent 67a1341 commit 5044bb0
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
13 changes: 11 additions & 2 deletions src/Connector/JiraConnector.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,13 @@ class JiraConnector implements Connector, ConfigurableService {
*/
private $httpClient;

/**
* Non billable project IDs.
*
* @var array
*/
protected $nonBillableProjects = [];

/**
* Constructs a new JiraConnector.
*
Expand Down Expand Up @@ -102,6 +109,9 @@ public function __construct(array $configuration, Cache $cache, array $config, $
$this->userName = $configuration['jira_username'];
$this->version = $version;
$this->httpClient = $httpClient;
$this->nonBillableProjects = array_map(function ($item) {
return (int) $item;
}, $config['jira_non_billable_projects'] ?? []);
}

/**
Expand Down Expand Up @@ -223,8 +233,7 @@ public function ticketDetails($id, $connectorId) {
}
return FALSE;
}
// @todo work out if ticket is billable.
return new Ticket(sprintf('[%s] %s', $issue->key, $issue->fields->summary), $issue->fields->getProjectId(), TRUE);
return new Ticket(sprintf('[%s] %s', $issue->key, $issue->fields->summary), $issue->fields->getProjectId(), !in_array((int) $issue->fields->getProjectId(), $this->nonBillableProjects, TRUE));
}

/**
Expand Down
6 changes: 4 additions & 2 deletions src/Connector/RedmineConnector.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,9 @@ public function __construct(ClientInterface $httpClient, Cache $cache, array $co
$this->httpClient = $httpClient;
$this->url = $config['url'];
$this->apiKey = $config['api_key'];
$this->nonBillableProjects = isset($config['non_billable_projects']) ? $config['non_billable_projects'] : [];
$this->nonBillableProjects = array_map(function ($item) {
return (int) $item;
}, $config['non_billable_projects'] ?? []);
$this->cache = $cache;
$this->version = $version;
}
Expand Down Expand Up @@ -360,7 +362,7 @@ public function pause($ticket_id, $comment, $connectorId) {
* TRUE if billable.
*/
protected function isBillable($project_id) {
return !in_array($project_id, $this->nonBillableProjects, TRUE);
return !in_array((int) $project_id, $this->nonBillableProjects, TRUE);
}

/**
Expand Down

0 comments on commit 5044bb0

Please sign in to comment.