forked from mglaman/drupalorg-cli
-
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.
Co-authored-by: Matt Glaman <[email protected]>
- Loading branch information
Showing
5 changed files
with
166 additions
and
2 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,87 @@ | ||
<?php | ||
|
||
namespace mglaman\DrupalOrg; | ||
|
||
trait IssueTrait | ||
{ | ||
/** | ||
* Produces the label for a given category id. | ||
* | ||
* @param int $value | ||
* Category identifier. | ||
* | ||
* @return string | ||
* The label if known, or the casted string value if not. | ||
*/ | ||
public function getIssueCategoryLabel(int $value): string | ||
{ | ||
switch ($value) { | ||
case 1: | ||
return 'Bug report'; | ||
case 2: | ||
return 'Task'; | ||
case 3: | ||
return 'Feature request'; | ||
case 4: | ||
return 'Support request'; | ||
case 5: | ||
return 'Plan'; | ||
default: | ||
return (string)$value; | ||
} | ||
} | ||
|
||
/** | ||
* Produces the label for a given priority id. | ||
* | ||
* @param int $value | ||
* Priority identifier. | ||
* | ||
* @return string | ||
* The label if known, or the casted string value if not. | ||
*/ | ||
public function getIssuePriorityLabel(int $value): string | ||
{ | ||
switch ($value) { | ||
case 100: | ||
return 'Minor'; | ||
case 200: | ||
return 'Normal'; | ||
case 300: | ||
return 'Major'; | ||
case 400: | ||
return 'Critical'; | ||
default: | ||
return (string)$value; | ||
} | ||
} | ||
|
||
/** | ||
* Produces the label for a given status id. | ||
* | ||
* @param int $value | ||
* Status identifier. | ||
* | ||
* @return string | ||
* The label if known, or the casted string value if not. | ||
*/ | ||
public function getIssueStatusLabel(int $value): string | ||
{ | ||
switch ($value) { | ||
case 1: | ||
return 'Active'; | ||
case 2: | ||
return 'Fixed'; | ||
case 13: | ||
return 'Needs Work'; | ||
case 8: | ||
return 'Needs Review'; | ||
case 16: | ||
return 'Postponed [NMI]'; | ||
case 14: | ||
return 'RTBC'; | ||
default: | ||
return (string)$value; | ||
} | ||
} | ||
} |
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,63 @@ | ||
<?php | ||
|
||
namespace mglaman\DrupalOrgCli\Command\Issue; | ||
|
||
use Symfony\Component\Console\Input\InputArgument; | ||
use Symfony\Component\Console\Input\InputInterface; | ||
use Symfony\Component\Console\Input\InputOption; | ||
use Symfony\Component\Console\Output\OutputInterface; | ||
use mglaman\DrupalOrg\IssueTrait; | ||
|
||
class Show extends IssueCommandBase | ||
{ | ||
use IssueTrait; | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
protected function configure(): void | ||
{ | ||
$this | ||
->setName('issue:show') | ||
->addArgument('nid', InputArgument::REQUIRED, 'The issue node ID') | ||
->addOption( | ||
'format', | ||
'f', | ||
InputOption::VALUE_OPTIONAL, | ||
'Output options: text, json. Defaults to text.', | ||
'text' | ||
) | ||
->setDescription('Show a given issue information.'); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
protected function execute(InputInterface $input, OutputInterface $output): int | ||
{ | ||
$nid = $this->stdIn->getArgument('nid'); | ||
$issue = $this->client->getNode($nid); | ||
$issue_data = $issue->getContent(); | ||
$format = $this->stdIn->getOption('format'); | ||
|
||
if ($format == 'json') { | ||
$this->stdOut->writeln(json_encode($issue_data)); | ||
return 0; | ||
} | ||
// format option is text. | ||
$this->stdOut->writeln(sprintf('Title: %s', $issue->get('title'))); | ||
$this->stdOut->writeln(sprintf('Status: %s', $this->getIssueStatusLabel($issue->get('field_issue_status')))); | ||
$this->stdOut->writeln(sprintf('Project: %s', $issue_data->field_project->machine_name)); | ||
$this->stdOut->writeln(sprintf('Version: %s', $issue->get('field_issue_version'))); | ||
$this->stdOut->writeln(sprintf('Component: %s', $issue->get('field_issue_component'))); | ||
$this->stdOut->writeln(sprintf('Priority: %s', $this->getIssuePriorityLabel($issue->get('field_issue_priority')))); | ||
$this->stdOut->writeln(sprintf('Category: %s', $this->getIssueCategoryLabel($issue->get('field_issue_category')))); | ||
// Assigned field does not seem to be exposed on API. | ||
// TODO Convert to username. | ||
$this->stdOut->writeln(sprintf('Reporter: %s', $issue_data->author->id)); | ||
$this->stdOut->writeln(sprintf('Created: %s', date('r', $issue->get('created')))); | ||
$this->stdOut->writeln(sprintf('Updated: %s', date('r', $issue->get('changed')))); | ||
$this->stdOut->writeln(sprintf("\nIssue summary:\n%s", strip_tags($issue_data->body->value))); | ||
return 0; | ||
} | ||
} |
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