Skip to content

Commit

Permalink
Merge pull request #7 from mcfly-io/fix-remote-git
Browse files Browse the repository at this point in the history
  • Loading branch information
thaiat authored Sep 11, 2016
2 parents f3ad316 + e6f7fe3 commit 4dee967
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 21 deletions.
35 changes: 27 additions & 8 deletions lib/gitHelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,31 @@ var commitVersion = function(version) {
.pushTags('origin', cb);
});
};
/**
* Transforms the remote result to an object with url, owner and repo
* @param {Object} remote The remote
* @returns {Object} The result
*/
var transformRemote = function(remote) {
var repoUrl = remote.refs.push;
repoUrl = _.endsWith(repoUrl, '.git') ? repoUrl.substr(repoUrl, repoUrl.length - 4) : repoUrl;

if (_.startsWith(repoUrl, 'git@')) {
let ownerRepo = repoUrl.split(':')[1].split('/');
return {
url: 'https://github.com/' + ownerRepo[0] + '/' + ownerRepo[1],
owner: ownerRepo[0],
repo: ownerRepo[1]
};
} else {
let ownerRepo = repoUrl.split('/').slice(-2);
return {
url: repoUrl,
owner: ownerRepo[0],
repo: ownerRepo[1]
};
}
};

/**
* Gets a remote repository
Expand All @@ -53,14 +78,7 @@ var getRemoteRepository = function(remotename) {
if (!remote) {
throw new Error('"origin" remote repository is not configured');
}
var repoUrl = remote.refs.push;
repoUrl = _.endsWith(repoUrl, '.git') ? repoUrl.substr(repoUrl, repoUrl.length - 4) : repoUrl;
var ownerRepo = repoUrl.split('/').slice(-2);
return {
url: repoUrl,
owner: ownerRepo[0],
repo: ownerRepo[1]
};
return transformRemote(remote);
});
};

Expand All @@ -81,6 +99,7 @@ var isClean = function() {
module.exports = {
getCurrentBranch,
commitVersion,
transformRemote,
getRemoteRepository,
isClean
};
26 changes: 13 additions & 13 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,28 +6,28 @@
"mcfly-semantic-release": "./bin/mcfly-semantic-release.js"
},
"dependencies": {
"bluebird": "^3.4.0",
"bluebird-retry": "^0.7.0",
"bluebird": "^3.4.6",
"bluebird-retry": "^0.8.0",
"chalk": "^1.1.3",
"inquirer": "^1.1.0",
"lodash": "4.13.1",
"inquirer": "^1.1.3",
"lodash": "4.15.0",
"mcfly-github": "^1.0.5",
"memory-stream": "0.0.3",
"node-jsxml": "^0.7.0",
"semver": "^5.1.1",
"simple-git": "^1.38.0",
"node-jsxml": "^0.8.0",
"semver": "^5.3.0",
"simple-git": "^1.48.0",
"strip-json-comments": "^2.0.1",
"yargs": "^4.7.1"
"yargs": "^5.0.0"
},
"devDependencies": {
"chai": "^3.5.0",
"coveralls": "^2.11.9",
"eslint": "^2.13.1",
"coveralls": "^2.11.12",
"eslint": "^3.5.0",
"eslint-plugin-json": "^1.2.0",
"eslint-plugin-nodeca": "^1.0.3",
"istanbul": "^0.4.4",
"mocha": "^2.5.3",
"sinon": "^1.17.4",
"istanbul": "^0.4.5",
"mocha": "^3.0.2",
"sinon": "^1.17.5",
"sinon-chai": "^2.8.0"
},
"scripts": {
Expand Down
38 changes: 38 additions & 0 deletions test/mocha/gitHelper.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,44 @@ describe('gitHelper', () => {
.catch(done);
});
});

describe('transformRemite()', () => {
it('should succeed with an http url', () => {
var remote = {
name: 'origin',
refs: {
fetch: 'https://github.com/mcfly-io/mcfly-semantic-release',
push: 'https://github.com/mcfly-io/mcfly-semantic-release'
}
};

var retval = gitHelper.transformRemote(remote);
expect(retval).to.deep.equal({
url: 'https://github.com/mcfly-io/mcfly-semantic-release',
owner: 'mcfly-io',
repo: 'mcfly-semantic-release'
});

});

it('should succeed with a git url', () => {
var remote = {
name: 'origin',
refs: {
fetch: '[email protected]:mcfly-io/mcfly-semantic-release.git',
push: '[email protected]:mcfly-io/mcfly-semantic-release.git'
}
};

var retval = gitHelper.transformRemote(remote);
expect(retval).to.deep.equal({
url: 'https://github.com/mcfly-io/mcfly-semantic-release',
owner: 'mcfly-io',
repo: 'mcfly-semantic-release'
});
});
});

describe('getRemoteRepository()', () => {
it('should return remote origin repository', (done) => {

Expand Down

0 comments on commit 4dee967

Please sign in to comment.