Skip to content

Commit

Permalink
keep reviewers on pullrequest description update (#5)
Browse files Browse the repository at this point in the history
  • Loading branch information
lifeofguenter authored Feb 12, 2018
1 parent f330766 commit d2e955c
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 8 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ A bitbucket cli tool.
## Installation

```bash
$ sudo curl -#fLo /usr/local/bin/bitbucket https://github.com/NINEJKH/bitbucket-cli/releases/download/0.0.3/bitbucket.phar && sudo chmod +x /usr/local/bin/bitbucket
$ curl -#fL "$(curl -s https://api.github.com/repos/NINEJKH/bitbucket-cli/releases/latest | grep 'browser_download_url' | sed -n 's/.*"\(http.*\)".*/\1/p')" | sudo tee /usr/local/bin/bitbucket > /dev/null && sudo chmod +x /usr/local/bin/bitbucket
```

## Auth
Expand Down
5 changes: 4 additions & 1 deletion app/Commands/BitbucketCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,13 @@ abstract class BitbucketCommand extends Command
protected function throwApiResponseError(MessageInterface $message)
{
$error_message = $message->getContent();

if (preg_match('~^{.*}$~', $error_message)) {
$error_message = json_decode($error_message, true);
if (!empty($error_message['error'])) {
if (!empty($error_message['error']) && !empty($error_message['error']['detail'])) {
$error_message = sprintf('[%s]%s%s', $error_message['error']['message'], PHP_EOL, $error_message['error']['detail']);
} elseif (!empty($error_message['error'])) {
$error_message = sprintf('%s', $error_message['error']['message']);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,11 @@ protected function execute(InputInterface $input, OutputInterface $output)
]
];

if (!empty($current_pr['reviewers'])) {
$payload['reviewers'] = $current_pr['reviewers'];
}

$pull = $this->create();
$pr = $pull->update($username, $repo_slug, $input->getArgument('pull_request_id'), $payload);

if (!$pr->isOk()) {
Expand Down
21 changes: 15 additions & 6 deletions app/Commands/Repositories/PullRequestsCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,29 @@

use App\Commands\BitbucketCommand;
use App\Providers\BitbucketConfigProvider;
use Bitbucket\API\Http\Listener\BasicAuthListener;
use Bitbucket\API\Repositories\PullRequests;

abstract class PullRequestsCommand extends BitbucketCommand
{
protected function create()
{
$bitbucket_config = new BitbucketConfigProvider;

$pull = new PullRequests;
$pull->getClient()->addListener(
new BasicAuthListener($bitbucket_config->getBasicAuthUsername(), $bitbucket_config->getBasicAuthPassword())
);
$pull->getClient()->addListener($this->createAuthListener());

return $pull;
}

protected function createAuthListener()
{
$bitbucket_config = new BitbucketConfigProvider;

if ($bitbucket_config->hasOAuth2()) {
return new \Bitbucket\API\Http\Listener\OAuth2Listener([
'client_id' => $bitbucket_config->getOAuth2Id(),
'client_secret' => $bitbucket_config->getOAuth2Secret(),
]);
} elseif ($bitbucket_config->hasBasicAuth()) {
return new \Bitbucket\API\Http\Listener\BasicAuthListener($bitbucket_config->getBasicAuthUsername(), $bitbucket_config->getBasicAuthPassword());
}
}
}
24 changes: 24 additions & 0 deletions app/Providers/BitbucketConfigProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,30 @@ public function __construct()
}
}

public function hasOAuth2()
{
return (bool) isset(static::$config['auth']['client_id'], static::$config['auth']['client_secret']);
}

public function hasBasicAuth()
{
return (bool) isset(static::$config['auth']['username'], static::$config['auth']['password']);
}

public function getOAuth2Id()
{
if (isset(static::$config['auth']['client_id'])) {
return static::$config['auth']['client_id'];
}
}

public function getOAuth2Secret()
{
if (isset(static::$config['auth']['client_secret'])) {
return static::$config['auth']['client_secret'];
}
}

public function getBasicAuthUsername()
{
if (isset(static::$config['auth']['username'])) {
Expand Down

0 comments on commit d2e955c

Please sign in to comment.