Permalink
Browse files

Remove BITBUCKET_INSTANCE_URI

  • Loading branch information...
Te7a-Houdini committed May 10, 2018
1 parent 7ee4a95 commit 709acf6a1e9d11b8ddbf5257588051895739014d
Showing with 18 additions and 18 deletions.
  1. +0 −1 .env.example
  2. +0 −1 README.md
  3. +18 −16 app/Classes/Bitbucket.php
@@ -15,7 +15,6 @@ GITLAB_INSTANCE_URI=https://gitlab.com/

BITBUCKET_CLIENT_ID=
BITBUCKET_CLIENT_SECRET=
BITBUCKET_INSTANCE_URI=https://api.bitbucket.org

DB_CONNECTION=mysql
DB_HOST=
@@ -203,7 +203,6 @@ Uncheck (This is a private consumer)
```
BITBUCKET_CLIENT_ID=XXXXX -> Bitbucket Key
BITBUCKET_CLIENT_SECRET=XXXXXXXXXXXXXXXXXX Bitbucket Secret
BITBUCKET_INSTANCE_URI=https://api.bitbucket.org
```

#### Proxy
@@ -14,6 +14,8 @@
class Bitbucket implements ProviderInterface
{
private const BITBUCKET_API_URL = 'https://api.bitbucket.org/';
private const BITBUCKET_API_VER = '2.0/';
public function tplUser($obj)
{
@@ -41,7 +43,7 @@ public function tplRepository($repo, $slug = false)
return;
}
return (object) [
return (object)[
'provider_id' => $repo->uuid,
'organization_id' => $organization->id,
'organization_title' => $organization->username,
@@ -51,14 +53,14 @@ public function tplRepository($repo, $slug = false)
'is_private' => $repo->is_private,
'html_url' => $repo->links->html->href,
'description' => null,
'fork' => $repo->fork_policy =='allow_forks' ? true : false,
'fork' => $repo->fork_policy == 'allow_forks' ? true : false,
'url' => $repo->links->self->href,
'since' => Carbon::parse($repo->created_on)->toDateTimeString(),
'since' => Carbon::parse($repo->created_on)->toDateTimeString(),
'pushed_at' => Carbon::parse($repo->updated_on)->toDateTimeString(),
'ssh_url' => $repo->links->clone[1]->href,
'clone_url' => $repo->links->clone[0]->href,
'homepage' => $repo->links->html->href,
'default_branch' => isset($repo->mainbranch) ? (isset($repo->mainbranch->name) ? $repo->mainbranch->name : $repo->mainbranch ) : null,
'default_branch' => isset($repo->mainbranch) ? (isset($repo->mainbranch->name) ? $repo->mainbranch->name : $repo->mainbranch) : null,
];
}
@@ -97,7 +99,7 @@ public function tplOrganization($obj)
return [
'provider_id' => $obj->uuid,
'username' => $obj->username,
'url' => $obj->links->self->href ,
'url' => $obj->links->self->href,
'repos_url' => $propertyRepositoriesHref,
'events_url' => null,
'hooks_url' => $propertyHooksHref,
@@ -121,7 +123,7 @@ public function tplOrganization($obj)
public function readRepositories($page = 1, &$repos = null)
{
$url = env('BITBUCKET_INSTANCE_URI').'/2.0/repositories?token='.Auth::user()->token.'&role=member&page='.$page.'&pagelen=100';
$url = self::BITBUCKET_API_URL . self::BITBUCKET_API_VER . 'repositories?token=' . Auth::user()->token . '&role=member&page=' . $page . '&pagelen=100';
$repos = $this->assertTokenNotExpired(Helper::request($url), $url);
@@ -144,9 +146,9 @@ public function organization($obj)
$endPoint = strtolower($obj->owner->type) == 'user' ? 'users' : 'teams';
$url = env('BITBUCKET_INSTANCE_URI').'/2.0/'.$endPoint.'/' .$obj->owner->username ;
$url = self::BITBUCKET_API_URL . self::BITBUCKET_API_VER . $endPoint . '/' . $obj->owner->username;
$response = (object) $this->assertTokenNotExpired(Helper::request($url), $url);
$response = (object)$this->assertTokenNotExpired(Helper::request($url), $url);
$data = $this->tplOrganization($response);
@@ -167,21 +169,21 @@ public function organization($obj)
*/
public function readCollaborators($owner, $repo, $providerId = null)
{
$url = env('BITBUCKET_INSTANCE_URI').'/1.0/privileges/'.$owner .'/'.$repo ;
$url = self::BITBUCKET_API_URL . '/1.0/privileges/' . $owner . '/' . $repo;
$collaborators = $this->assertTokenNotExpired(Helper::request($url), $url);
$collaborators = $this->assertTokenNotExpired(Helper::request($url), $url);
$userId = null;
if (is_null($collaborators)) {
return ;
return;
}
foreach ($collaborators as $collaborator) {
$user = User::where('provider', 'bitbucket')->where('username', $collaborator->user->username)->first();
if (is_null($user)) {
$url = env('BITBUCKET_INSTANCE_URI').'/2.0/users/' .$collaborator->user->username;
$url = self::BITBUCKET_API_URL . self::BITBUCKET_API_VER . 'users/' . $collaborator->user->username;
$user = $this->assertTokenNotExpired(Helper::request($url), $url);
@@ -200,7 +202,7 @@ public function readCollaborators($owner, $repo, $providerId = null)
$user = User::create($data);
}
$userId[] = $user->id;
$userId[] = $user->id;
}
$organization = Organization::where('username', $owner)
@@ -211,7 +213,7 @@ public function readCollaborators($owner, $repo, $providerId = null)
public function createBranches($owner, $product_backlog_id, $repo, $providerId = null)
{
$branches = collect(Helper::request(env('BITBUCKET_INSTANCE_URI').'/1.0/repositories/'.$owner . '/' . $repo .'/branches'));
$branches = collect(Helper::request(self::BITBUCKET_API_URL . '/1.0/repositories/' . $owner . '/' . $repo . '/branches'));
$branchesData = [];
foreach ($branches as $branchName => $branchData) {
@@ -234,7 +236,7 @@ public function readIssues()
$repos = ProductBacklog::with('organization')->get();
foreach ($repos as $repo) {
$url = env('BITBUCKET_INSTANCE_URI').'/2.0/repositories/'.$repo->organization->username.'/' . $repo->title .'/issues' ;
$url = self::BITBUCKET_API_URL . self::BITBUCKET_API_VER . 'repositories/' . $repo->organization->username . '/' . $repo->title . '/issues';
$issues = $this->assertTokenNotExpired(Helper::request($url), $url);
@@ -243,7 +245,7 @@ public function readIssues()
$data = $this->tplIssue($issue, $repo->id);
if (!Issue::where('provider_id', $data['provider_id'])->where('number', $data['number'])->where('provider', 'bitbucket')->first()) {
Issue::create($data)->users()->sync([$data['user_id']]);
Issue::create($data)->users()->sync([$data['user_id']]);
}
}
}

0 comments on commit 709acf6

Please sign in to comment.