-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from eventum/note-unfurl
- Loading branch information
Showing
6 changed files
with
135 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
<?php | ||
|
||
namespace Eventum\SlackUnfurl; | ||
|
||
use Eventum\RPC\EventumXmlRpcClient; | ||
use Eventum\RPC\XmlRpcException; | ||
|
||
class ApiClient | ||
{ | ||
/** @var EventumXmlRpcClient */ | ||
private $client; | ||
|
||
public function __construct(EventumXmlRpcClient $client) | ||
{ | ||
$this->client = $client; | ||
} | ||
|
||
/** | ||
* Get issue details, but filter only needed keys. | ||
* | ||
* @param int $issueId | ||
* @throws XmlRpcException | ||
* @return array | ||
*/ | ||
public function getIssueDetails(int $issueId): array | ||
{ | ||
/** @var array $issue */ | ||
$issue = $this->client->getIssueDetails($issueId); | ||
|
||
$fields = [ | ||
'assignments', | ||
'iss_created_date', | ||
'iss_created_date_ts', | ||
'iss_description', | ||
'iss_id', | ||
'iss_last_internal_action_date', | ||
'iss_last_public_action_date', | ||
'iss_original_description', | ||
'iss_summary', | ||
'iss_updated_date', | ||
'prc_title', | ||
'pri_title', | ||
'reporter', | ||
'sta_title', | ||
]; | ||
|
||
return array_intersect_key($issue, array_flip($fields)); | ||
} | ||
|
||
/** | ||
* @param int $noteId | ||
* @throws XmlRpcException | ||
* @return array | ||
*/ | ||
public function getNoteDetails(int $noteId): array | ||
{ | ||
$fields = [ | ||
'issue_url', | ||
'not_id', | ||
'not_iss_id', | ||
'not_title', | ||
'not_from', | ||
'not_note', | ||
'not_created_date_ts', | ||
]; | ||
|
||
return $this->client->getNoteDetails($noteId, $fields); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
<?php | ||
|
||
namespace Eventum\SlackUnfurl\Route; | ||
|
||
use DateTimeZone; | ||
use Eventum\SlackUnfurl\ApiClient; | ||
use Psr\Log\LoggerInterface; | ||
use SlackUnfurl\Traits\LoggerTrait; | ||
|
||
class Note | ||
{ | ||
use LoggerTrait; | ||
|
||
/** @var ApiClient */ | ||
private $client; | ||
/** @var DateTimeZone */ | ||
private $utc; | ||
/** @var DateTimeZone */ | ||
private $timeZone; | ||
|
||
public function __construct( | ||
ApiClient $client, | ||
LoggerInterface $logger | ||
) { | ||
$this->client = $client; | ||
$this->logger = $logger; | ||
} | ||
|
||
public function unfurl(string $url, array $parts): ?array | ||
{ | ||
$noteId = (int)$parts['id']; | ||
$note = $this->client->getNoteDetails($noteId); | ||
$this->debug(' note', ['note' => $note]); | ||
$issueId = $note['not_iss_id']; | ||
$issueUrl = $note['issue_url']; | ||
|
||
return [ | ||
'title' => "Note in <$issueUrl|Issue #{$issueId}>: {$note['not_title']}", | ||
'text' => $note['not_note'], | ||
'color' => '#006486', | ||
'ts' => $note['not_created_date_ts'], | ||
'footer' => "Note by {$note['not_from']}", | ||
]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters