-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from teambit/feature/url-parser
Feature/url parser
- Loading branch information
Showing
5 changed files
with
1,791 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.