Skip to content

Commit

Permalink
Merge pull request #1 from teambit/feature/url-parser
Browse files Browse the repository at this point in the history
Feature/url parser
  • Loading branch information
GiladShoham committed Jul 22, 2018
2 parents 724126f + fc043bd commit 6ca9eeb
Show file tree
Hide file tree
Showing 5 changed files with 1,791 additions and 3 deletions.
13 changes: 12 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ Usage
```javascript
'use strict'

const gitconfig = require('gitconfig')
const gitconfig = require('@teambit/gitconfig')

// Set git config values.
gitconfig.set({
Expand All @@ -101,9 +101,20 @@ gitconfig.get({
}).then((config) => {
/* ... */
})

/**
* @name getUrl
* @description Get git remote name url or all remotes urls.
* @param remoteName - string - remotname to fetch url
* @return returns the remote names url if specified or all remote names urls if nothing is passed
*/
gitconfig.getUrl().then((config) => {
/* ... */
})
```



<!-- Section from "doc/guides/02.Usage.md.hbs" End -->

<!-- Section from "doc/guides/03.API.md.hbs" Start -->
Expand Down
45 changes: 45 additions & 0 deletions lib/fetchRepo.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
const get = require('./get');
const lget = require('lodash.get');

/**
* Get remote url.
* @param remoteName - remote name to fetch git url
* @function getRepoRemoteUrl
* @returns {String}
*/
function getRepoRemoteUrl (getGitInfo, remoteName) {
return lget(getGitInfo, `remote.${remoteName}.url`);
}

/**
* Get all remote urls from current project
* @function getAllRemotesUrls
* @returns {Array<String>}
*/
function getAllRemotesUrls (getGitInfo) {
const remotes = lget(getGitInfo, 'remote', {});
return Object.keys(remotes).map(key => lget(remotes[key],'url'));
}


/**
* Get gitInfo
* @function getGitInfo
* @returns {Object}
*/
function getGitInfo () {
return get.sync();
}

/**
* Get all remote url or all remote urls from current project
* @param remoteName - string
* @function getAllRemotesUrls
* @returns {Array<string> | string}
*/
function getUrl(remoteName){
const gitInfo = getGitInfo();
return remoteName ? getRepoRemoteUrl(gitInfo, remoteName) : getAllRemotesUrls(gitInfo);
}

module.exports = getUrl
3 changes: 2 additions & 1 deletion lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,6 @@ let d = (module) => module.default || module
module.exports = {
get get () { return d(require('./get')) },
get set () { return d(require('./set')) },
get unset () { return d(require('./unset')) }
get unset () { return d(require('./unset')) },
get getUrl () { return d(require('./fetchRepo')) }
}
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
"askconfig": "^3.0.5",
"co": "^4.6.0",
"execcli": "^4.0.8",
"lodash.get": "^4.4.2",
"objnest": "^3.0.6"
},
"devDependencies": {
Expand All @@ -43,4 +44,4 @@
"node": ">=6",
"npm": ">=3"
}
}
}
Loading

0 comments on commit 6ca9eeb

Please sign in to comment.