hosted-git-info-from-manifest.js 588 B

1234567891011121314
  1. // given a manifest, try to get the hosted git info from it based on
  2. // repository (if a string) or repository.url (if an object)
  3. // returns null if it's not a valid repo, or not a known hosted repo
  4. const hostedGitInfo = require('hosted-git-info')
  5. module.exports = mani => {
  6. const r = mani.repository
  7. const rurl = !r ? null
  8. : typeof r === 'string' ? r
  9. : typeof r === 'object' && typeof r.url === 'string' ? r.url
  10. : null
  11. // hgi returns undefined sometimes, but let's always return null here
  12. return (rurl && hostedGitInfo.fromUrl(rurl.replace(/^git\+/, ''))) || null
  13. }