Skip to content

Commit 9833aeb

Browse files
authored
Merge pull request #34 from wahapo/bitbucket_username
fix: can settings username and email for bitbucket checkout
2 parents dffcf2a + b093d13 commit 9833aeb

File tree

4 files changed

+32
-3
lines changed

4 files changed

+32
-3
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ The class has a variety of knobs to tweak when interacting with Bitbucket.org.
1818
| config | Object | Configuration Object |
1919
| config.oauthClientId | String | OAuth Client ID provided by Bitbucket application |
2020
| config.oauthClientSecret | String | OAuth Client Secret provided by Bitbucket application |
21+
| config.username (sd-buildbot) | String | Bitbucket username for checkout |
22+
| config.email (dev-null@screwdriver.cd) | String | Bitbucket user email for checkout |
2123
| config.https (false) | Boolean | Is the Screwdriver API running over HTTPS |
2224
| config.fusebox ({}) | Object | [Circuit Breaker configuration][circuitbreaker] |
2325
```js

index.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,8 @@ class BitbucketScm extends Scm {
9292
* @method constructor
9393
* @param {String} options.oauthClientId OAuth Client ID provided by Bitbucket application
9494
* @param {String} options.oauthClientSecret OAuth Client Secret provided by Bitbucket application
95+
* @param {String} [options.username=sd-buildbot] Bitbucket username for checkout
96+
* @param {String} [options.email=dev-null@screwdriver.cd] Bitbucket user email for checkout
9597
* @param {Boolean} [options.https=false] Is the Screwdriver API running over HTTPS
9698
* @param {Object} [options.fusebox={}] Circuit Breaker configuration
9799
* @return {BitbucketScm}
@@ -100,6 +102,8 @@ class BitbucketScm extends Scm {
100102
super();
101103

102104
this.config = joi.attempt(config, joi.object().keys({
105+
username: joi.string().optional().default('sd-buildbot'),
106+
email: joi.string().optional().default('dev-null@screwdriver.cd'),
103107
https: joi.boolean().optional().default(false),
104108
oauthClientId: joi.string().required(),
105109
oauthClientSecret: joi.string().required(),
@@ -635,8 +639,8 @@ class BitbucketScm extends Scm {
635639
command.push(`git reset --hard ${checkoutRef}`);
636640
// Set config
637641
command.push('echo Setting user name and user email');
638-
command.push('git config user.name sd-buildbot');
639-
command.push('git config user.email dev-null@screwdriver.cd');
642+
command.push(`git config user.name ${this.config.username}`);
643+
command.push(`git config user.email ${this.config.email}`);
640644

641645
if (config.prRef) {
642646
command.push(`echo Fetching PR and merging with ${config.branch}`);

test/data/customPrCommands.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"name": "sd-checkout-code",
3+
"command": "echo Cloning https://hostName/orgName/repoName, on branch branchName && git clone --quiet --progress --branch branchName https://hostName/orgName/repoName $SD_SOURCE_DIR && echo Reset to SHA branchName && git reset --hard branchName && echo Setting user name and user email && git config user.name abcd && git config user.email dev-null@my.email.com && echo Fetching PR and merging with branchName && git fetch origin prBranch && git merge shaValue"
4+
}

test/index.test.js

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ const mockery = require('mockery');
55
const sinon = require('sinon');
66
const testCommands = require('./data/commands.json');
77
const testPrCommands = require('./data/prCommands.json');
8+
const testCustomPrCommands = require('./data/customPrCommands.json');
89
const testPayloadOpen = require('./data/pr.opened.json');
910
const testPayloadSync = require('./data/pr.sync.json');
1011
const testPayloadClose = require('./data/pr.closed.json');
@@ -72,12 +73,16 @@ describe('index', function () {
7273
it('constructs successfully', () => {
7374
const testScm = new BitbucketScm({
7475
oauthClientId: 'myclientid',
75-
oauthClientSecret: 'myclientsecret'
76+
oauthClientSecret: 'myclientsecret',
77+
username: 'abcd',
78+
email: 'dev-null@my.email.com'
7679
});
7780

7881
assert.deepEqual(testScm.config, {
7982
oauthClientId: 'myclientid',
8083
oauthClientSecret: 'myclientsecret',
84+
username: 'abcd',
85+
email: 'dev-null@my.email.com',
8186
fusebox: {},
8287
https: false
8388
});
@@ -1102,6 +1107,20 @@ describe('index', function () {
11021107
assert.deepEqual(command, testPrCommands);
11031108
});
11041109
});
1110+
1111+
it('resolves checkout command with custom username and email', () => {
1112+
scm = new BitbucketScm({
1113+
oauthClientId: 'myclientid',
1114+
oauthClientSecret: 'myclientsecret',
1115+
username: 'abcd',
1116+
email: 'dev-null@my.email.com'
1117+
});
1118+
1119+
return scm.getCheckoutCommand(config)
1120+
.then((command) => {
1121+
assert.deepEqual(command, testCustomPrCommands);
1122+
});
1123+
});
11051124
});
11061125

11071126
describe('stats', () => {

0 commit comments

Comments
 (0)