Skip to content

Commit 8da0170

Browse files
committed
fix: Fixed input format for requests
1 parent f375cdf commit 8da0170

File tree

2 files changed

+42
-23
lines changed

2 files changed

+42
-23
lines changed

index.js

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -126,9 +126,10 @@ class BitbucketScm extends Scm {
126126
_findWebhook(config) {
127127
return this.breaker.runCommand({
128128
json: true,
129-
login_type: 'oauth2',
130129
method: 'GET',
131-
oauth_access_token: config.token,
130+
auth: {
131+
bearer: config.token
132+
},
132133
url: `${API_URL_V2}/repositories/${config.repoId}/hooks?pagelen=30&page=${config.page}`
133134
}).then((response) => {
134135
checkResponseError(response);
@@ -178,9 +179,10 @@ class BitbucketScm extends Scm {
178179
]
179180
},
180181
json: true,
181-
login_type: 'oauth2',
182182
method: 'POST',
183-
oauth_access_token: config.token,
183+
auth: {
184+
bearer: config.token
185+
},
184186
url: `${API_URL_V2}/repositories/${config.repoId}/hooks`
185187
};
186188

@@ -654,14 +656,15 @@ class BitbucketScm extends Scm {
654656
* @return {Promise}
655657
*/
656658
_getOpenedPRs(config) {
657-
const repoId = getScmUriParts(config.scmUri)[1];
659+
const repoId = getScmUriParts(config.scmUri).repoId;
658660

659661
return this.breaker.runCommand({
660-
json: true,
661-
login_type: 'oauth2',
662+
url: `${API_URL_V2}/repositories/${repoId}/pullrequests`,
662663
method: 'GET',
663-
oauth_access_token: config.token,
664-
url: `${API_URL_V2}/repositories/${repoId}/pullrequests`
664+
json: true,
665+
auth: {
666+
bearer: config.token
667+
}
665668
}).then((response) => {
666669
checkResponseError(response);
667670

test/index.test.js

Lines changed: 30 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1151,9 +1151,10 @@ describe('index', function () {
11511151
.then(() => {
11521152
assert.calledWith(requestMock, {
11531153
json: true,
1154-
login_type: 'oauth2',
11551154
method: 'GET',
1156-
oauth_access_token: 'oauthToken',
1155+
auth: {
1156+
bearer: oauthToken
1157+
},
11571158
url: `${API_URL_V2}/repositories/repoId/hooks?pagelen=30&page=1`
11581159
});
11591160
assert.calledWith(requestMock, {
@@ -1170,9 +1171,10 @@ describe('index', function () {
11701171
]
11711172
},
11721173
json: true,
1173-
login_type: 'oauth2',
11741174
method: 'POST',
1175-
oauth_access_token: 'oauthToken',
1175+
auth: {
1176+
bearer: oauthToken
1177+
},
11761178
url: `${API_URL_V2}/repositories/repoId/hooks`
11771179
});
11781180
});
@@ -1203,9 +1205,10 @@ describe('index', function () {
12031205
}).then(() => {
12041206
assert.calledWith(requestMock, {
12051207
json: true,
1206-
login_type: 'oauth2',
12071208
method: 'GET',
1208-
oauth_access_token: 'oauthToken',
1209+
auth: {
1210+
bearer: oauthToken
1211+
},
12091212
url: `${API_URL_V2}/repositories/repoId/hooks?pagelen=30&page=1`
12101213
});
12111214
assert.calledWith(requestMock, {
@@ -1222,9 +1225,10 @@ describe('index', function () {
12221225
]
12231226
},
12241227
json: true,
1225-
login_type: 'oauth2',
12261228
method: 'PUT',
1227-
oauth_access_token: oauthToken,
1229+
auth: {
1230+
bearer: oauthToken
1231+
},
12281232
url: `${API_URL_V2}/repositories/repoId/hooks/${uuid}`
12291233
});
12301234
});
@@ -1269,9 +1273,10 @@ describe('index', function () {
12691273
}).then(() => {
12701274
assert.calledWith(requestMock, {
12711275
json: true,
1272-
login_type: 'oauth2',
12731276
method: 'GET',
1274-
oauth_access_token: 'oauthToken',
1277+
auth: {
1278+
bearer: oauthToken
1279+
},
12751280
url: `${API_URL_V2}/repositories/repoId/hooks?pagelen=30&page=2`
12761281
});
12771282
assert.calledWith(requestMock, {
@@ -1288,9 +1293,10 @@ describe('index', function () {
12881293
]
12891294
},
12901295
json: true,
1291-
login_type: 'oauth2',
12921296
method: 'PUT',
1293-
oauth_access_token: oauthToken,
1297+
auth: {
1298+
bearer: oauthToken
1299+
},
12941300
url: `${API_URL_V2}/repositories/repoId/hooks/${uuid}`
12951301
});
12961302
});
@@ -1462,6 +1468,14 @@ describe('index', function () {
14621468
describe('_getOpenedPRs', () => {
14631469
const oauthToken = 'oauthToken';
14641470
const scmUri = 'hostName:repoId:branchName';
1471+
const expectedOptions = {
1472+
url: `${API_URL_V2}/repositories/repoId/pullrequests`,
1473+
method: 'GET',
1474+
json: true,
1475+
auth: {
1476+
bearer: oauthToken
1477+
}
1478+
};
14651479

14661480
it('returns response of expected format from Bitbucket', () => {
14671481
requestMock.yieldsAsync(null, {
@@ -1483,11 +1497,13 @@ describe('index', function () {
14831497
scmUri,
14841498
token: oauthToken
14851499
})
1486-
.then(response =>
1500+
.then((response) => {
1501+
assert.calledWith(requestMock, expectedOptions);
14871502
assert.deepEqual(response, [{
14881503
name: 'PR-1',
14891504
ref: 'testbranch'
1490-
}])
1505+
}]);
1506+
}
14911507
);
14921508
});
14931509
});

0 commit comments

Comments
 (0)