Skip to content

Commit e65daa6

Browse files
authored
fix(2185): Add default branch (hardcode for now) (#69)
1 parent 7b5ea3a commit e65daa6

File tree

3 files changed

+30
-5
lines changed

3 files changed

+30
-5
lines changed

index.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ function getRepoInfo(checkoutUrl) {
7070
return {
7171
hostname: matched[MATCH_COMPONENT_HOSTNAME],
7272
repo: matched[MATCH_COMPONENT_REPO],
73-
branch: matched[MATCH_COMPONENT_BRANCH].slice(1),
73+
branch: matched[MATCH_COMPONENT_BRANCH] ? matched[MATCH_COMPONENT_BRANCH].slice(1) : null,
7474
username: matched[MATCH_COMPONENT_USER]
7575
};
7676
}
@@ -259,8 +259,11 @@ class BitbucketScm extends Scm {
259259
*/
260260
async _parseUrl(config) {
261261
const repoInfo = getRepoInfo(config.checkoutUrl);
262+
// TODO: add logic to fetch default branch
263+
// See https://jira.atlassian.com/browse/BCLOUD-20212
264+
const branch = repoInfo.branch || 'master';
262265
const branchUrl =
263-
`${REPO_URL}/${repoInfo.username}/${repoInfo.repo}/refs/branches/${repoInfo.branch}`;
266+
`${REPO_URL}/${repoInfo.username}/${repoInfo.repo}/refs/branches/${branch}`;
264267
const token = await this._getToken();
265268

266269
const options = {
@@ -288,7 +291,7 @@ class BitbucketScm extends Scm {
288291
}
289292

290293
return `${repoInfo.hostname}:${repoInfo.username}` +
291-
`/${response.body.target.repository.uuid}:${repoInfo.branch}`;
294+
`/${response.body.target.repository.uuid}:${branch}`;
292295
}
293296

294297
/**

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
"chai": "^4.2.0",
4040
"eslint": "^4.19.1",
4141
"eslint-config-screwdriver": "^3.0.1",
42-
"jenkins-mocha": "^6.0.0",
42+
"jenkins-mocha": "^8.0.0",
4343
"mockery": "^2.0.0",
4444
"sinon": "^4.5.0"
4545
},
@@ -48,7 +48,7 @@
4848
"hoek": "^5.0.4",
4949
"joi": "^13.7.0",
5050
"request": "^2.88.0",
51-
"screwdriver-data-schema": "^18.38.0",
51+
"screwdriver-data-schema": "^19.12.1",
5252
"screwdriver-scm-base": "^4.0.5"
5353
}
5454
}

test/index.test.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,28 @@ describe('index', function () {
151151
});
152152
});
153153

154+
it('resolves to the correct parsed url for ssh wtih default branch', () => {
155+
const expected =
156+
'bitbucket.org:batman/{de7d7695-1196-46a1-b87d-371b7b2945ab}:master';
157+
158+
expectedOptions = {
159+
url: `${apiUrl}/master`,
160+
method: 'GET',
161+
json: true,
162+
auth: {
163+
bearer: systemToken
164+
}
165+
};
166+
167+
return scm.parseUrl({
168+
checkoutUrl: 'git@bitbucket.org:batman/test.git',
169+
token
170+
}).then((parsed) => {
171+
assert.calledWith(requestMock, expectedOptions);
172+
assert.equal(parsed, expected);
173+
});
174+
});
175+
154176
it('resolves to the correct parsed url for https', () => {
155177
const expected =
156178
'bitbucket.org:batman/{de7d7695-1196-46a1-b87d-371b7b2945ab}:mynewbranch';

0 commit comments

Comments
 (0)