git-host-info.js 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. 'use strict'
  2. var gitHosts = module.exports = {
  3. github: {
  4. // First two are insecure and generally shouldn't be used any more, but
  5. // they are still supported.
  6. 'protocols': [ 'git', 'http', 'git+ssh', 'git+https', 'ssh', 'https' ],
  7. 'domain': 'github.com',
  8. 'treepath': 'tree',
  9. 'filetemplate': 'https://{auth@}raw.githubusercontent.com/{user}/{project}/{committish}/{path}',
  10. 'bugstemplate': 'https://{domain}/{user}/{project}/issues',
  11. 'gittemplate': 'git://{auth@}{domain}/{user}/{project}.git{#committish}',
  12. 'tarballtemplate': 'https://{domain}/{user}/{project}/archive/{committish}.tar.gz'
  13. },
  14. bitbucket: {
  15. 'protocols': [ 'git+ssh', 'git+https', 'ssh', 'https' ],
  16. 'domain': 'bitbucket.org',
  17. 'treepath': 'src',
  18. 'tarballtemplate': 'https://{domain}/{user}/{project}/get/{committish}.tar.gz'
  19. },
  20. gitlab: {
  21. 'protocols': [ 'git+ssh', 'git+https', 'ssh', 'https' ],
  22. 'domain': 'gitlab.com',
  23. 'treepath': 'tree',
  24. 'docstemplate': 'https://{domain}/{user}/{project}{/tree/committish}#README',
  25. 'bugstemplate': 'https://{domain}/{user}/{project}/issues',
  26. 'tarballtemplate': 'https://{domain}/{user}/{project}/repository/archive.tar.gz?ref={committish}'
  27. },
  28. gist: {
  29. 'protocols': [ 'git', 'git+ssh', 'git+https', 'ssh', 'https' ],
  30. 'domain': 'gist.github.com',
  31. 'pathmatch': /^[/](?:([^/]+)[/])?([a-z0-9]+)(?:[.]git)?$/,
  32. 'filetemplate': 'https://gist.githubusercontent.com/{user}/{project}/raw{/committish}/{path}',
  33. 'bugstemplate': 'https://{domain}/{project}',
  34. 'gittemplate': 'git://{domain}/{project}.git{#committish}',
  35. 'sshtemplate': 'git@{domain}:/{project}.git{#committish}',
  36. 'sshurltemplate': 'git+ssh://git@{domain}/{project}.git{#committish}',
  37. 'browsetemplate': 'https://{domain}/{project}{/committish}',
  38. 'browsefiletemplate': 'https://{domain}/{project}{/committish}{#path}',
  39. 'docstemplate': 'https://{domain}/{project}{/committish}',
  40. 'httpstemplate': 'git+https://{domain}/{project}.git{#committish}',
  41. 'shortcuttemplate': '{type}:{project}{#committish}',
  42. 'pathtemplate': '{project}{#committish}',
  43. 'tarballtemplate': 'https://{domain}/{user}/{project}/archive/{committish}.tar.gz',
  44. 'hashformat': function (fragment) {
  45. return 'file-' + formatHashFragment(fragment)
  46. }
  47. }
  48. }
  49. var gitHostDefaults = {
  50. 'sshtemplate': 'git@{domain}:{user}/{project}.git{#committish}',
  51. 'sshurltemplate': 'git+ssh://git@{domain}/{user}/{project}.git{#committish}',
  52. 'browsetemplate': 'https://{domain}/{user}/{project}{/tree/committish}',
  53. 'browsefiletemplate': 'https://{domain}/{user}/{project}/{treepath}/{committish}/{path}{#fragment}',
  54. 'docstemplate': 'https://{domain}/{user}/{project}{/tree/committish}#readme',
  55. 'httpstemplate': 'git+https://{auth@}{domain}/{user}/{project}.git{#committish}',
  56. 'filetemplate': 'https://{domain}/{user}/{project}/raw/{committish}/{path}',
  57. 'shortcuttemplate': '{type}:{user}/{project}{#committish}',
  58. 'pathtemplate': '{user}/{project}{#committish}',
  59. 'pathmatch': /^[/]([^/]+)[/]([^/]+?)(?:[.]git|[/])?$/,
  60. 'hashformat': formatHashFragment
  61. }
  62. Object.keys(gitHosts).forEach(function (name) {
  63. Object.keys(gitHostDefaults).forEach(function (key) {
  64. if (gitHosts[name][key]) return
  65. gitHosts[name][key] = gitHostDefaults[key]
  66. })
  67. gitHosts[name].protocols_re = RegExp('^(' +
  68. gitHosts[name].protocols.map(function (protocol) {
  69. return protocol.replace(/([\\+*{}()[\]$^|])/g, '\\$1')
  70. }).join('|') + '):$')
  71. })
  72. function formatHashFragment (fragment) {
  73. return fragment.toLowerCase().replace(/^\W+|\/|\W+$/g, '').replace(/\W+/g, '-')
  74. }