Skip to content

Commit

Permalink
fix: separate api and repo url
Browse files Browse the repository at this point in the history
  • Loading branch information
arlac77 committed Jan 15, 2018
1 parent db4728f commit e498add
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 19 deletions.
28 changes: 23 additions & 5 deletions src/bitbucket-repository-provider.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,35 @@ export class BitbucketProvider extends Provider {
*/
static get defaultOptions() {
return {
url: 'https://api.bitbucket.org/2.0'
url: 'https://bitbucket.org',
api: 'https://api.bitbucket.org/2.0'
};
}

constructor(config) {
super(config);

Object.defineProperty(this, 'client', {
value: new Client(this.config.url, this.config.auth)
value: new Client(this.config.api, this.config.auth)
});
}

/**
* API base url
* @return {string} api base url
*/
get api() {
return this.config.api;
}

/**
* GIT base url
* @return {string} repo base utl
*/
get url() {
return this.config.url;
}

get repositoryClass() {
return BitbucketRepository;
}
Expand Down Expand Up @@ -82,16 +99,17 @@ export class BitbucketProvider extends Provider {

get(path) {
const params = {
uri: this.config.url + '/' + path,
uri: this.api + '/' + path,
auth: this.config.auth
};

//console.log(`GET ${params.uri}`);
return request.get(params);
}

post(path, data) {
const params = {
uri: this.config.url + '/' + path,
uri: this.api + '/' + path,
auth: this.config.auth,
form: data
};
Expand All @@ -113,7 +131,7 @@ export class BitbucketRepository extends Repository {
* @return {string[]} url
*/
get urls() {
return [`https://bitbucket.org/${this.name}.git`];
return [`${this.provider.url}/${this.name}.git`];
}

get client() {
Expand Down
15 changes: 1 addition & 14 deletions tests/bitbucket-repository-provider-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,11 @@ const config = {

test('bitbucket provider', async t => {
const provider = new BitbucketProvider(config);

const repository = await provider.repository(REPOSITORY_NAME);

t.is(repository.name, REPOSITORY_NAME);
t.is(
repository.urls[0],
repository.urls.find(u => u.startsWith('http')),
'https://bitbucket.org/arlac77/sync-test-repository.git'
);

Expand Down Expand Up @@ -62,18 +61,6 @@ test('create branch', async t => {
t.is(branch.name, newName);
});

test.skip('create pullRequest', async t => {
const provider = new BitbucketProvider(config);
const repository = await provider.repository(REPOSITORY_NAME);
const branch = await repository.branch('master');

const pr = await branch.createPullRequest(branch, 'PR1');

console.log(pr);

t.is(pr.name, 'PR1');
});

test('bitbucket list', async t => {
const provider = new BitbucketProvider(config);

Expand Down
25 changes: 25 additions & 0 deletions tests/pull-request-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import test from 'ava';
import { BitbucketProvider } from '../src/bitbucket-repository-provider';

const REPOSITORY_URL =
'https://arlac77@bitbucket.org/arlac77/sync-test-repository.git';
const REPOSITORY_NAME = 'arlac77/sync-test-repository';

const config = {
auth: {
type: 'basic',
password: process.env.BITBUCKET_PASSWORD,
username: process.env.BITBUCKET_USERNAME
}
};

test.skip('create pullRequest', async t => {
const provider = new BitbucketProvider(config);
const branch = await provider.branch(REPOSITORY_NAME);

const pr = await branch.createPullRequest(branch, 'PR1');

console.log(pr);

t.is(pr.name, 'PR1');
});

0 comments on commit e498add

Please sign in to comment.