You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

git-host-info.js 3.7KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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://codeload.{domain}/{user}/{project}/tar.gz/{committish}'
  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. 'bugstemplate': 'https://{domain}/{user}/{project}/issues',
  25. 'httpstemplate': 'git+https://{auth@}{domain}/{user}/{projectPath}.git{#committish}',
  26. 'tarballtemplate': 'https://{domain}/{user}/{project}/repository/archive.tar.gz?ref={committish}',
  27. 'pathmatch': /^[/]([^/]+)[/]((?!.*(\/-\/|\/repository\/archive\.tar\.gz\?=.*|\/repository\/[^/]+\/archive.tar.gz$)).*?)(?:[.]git|[/])?$/
  28. },
  29. gist: {
  30. 'protocols': [ 'git', 'git+ssh', 'git+https', 'ssh', 'https' ],
  31. 'domain': 'gist.github.com',
  32. 'pathmatch': /^[/](?:([^/]+)[/])?([a-z0-9]{32,})(?:[.]git)?$/,
  33. 'filetemplate': 'https://gist.githubusercontent.com/{user}/{project}/raw{/committish}/{path}',
  34. 'bugstemplate': 'https://{domain}/{project}',
  35. 'gittemplate': 'git://{domain}/{project}.git{#committish}',
  36. 'sshtemplate': 'git@{domain}:/{project}.git{#committish}',
  37. 'sshurltemplate': 'git+ssh://git@{domain}/{project}.git{#committish}',
  38. 'browsetemplate': 'https://{domain}/{project}{/committish}',
  39. 'browsefiletemplate': 'https://{domain}/{project}{/committish}{#path}',
  40. 'docstemplate': 'https://{domain}/{project}{/committish}',
  41. 'httpstemplate': 'git+https://{domain}/{project}.git{#committish}',
  42. 'shortcuttemplate': '{type}:{project}{#committish}',
  43. 'pathtemplate': '{project}{#committish}',
  44. 'tarballtemplate': 'https://codeload.github.com/gist/{project}/tar.gz/{committish}',
  45. 'hashformat': function (fragment) {
  46. return 'file-' + formatHashFragment(fragment)
  47. }
  48. }
  49. }
  50. var gitHostDefaults = {
  51. 'sshtemplate': 'git@{domain}:{user}/{project}.git{#committish}',
  52. 'sshurltemplate': 'git+ssh://git@{domain}/{user}/{project}.git{#committish}',
  53. 'browsetemplate': 'https://{domain}/{user}/{project}{/tree/committish}',
  54. 'browsefiletemplate': 'https://{domain}/{user}/{project}/{treepath}/{committish}/{path}{#fragment}',
  55. 'docstemplate': 'https://{domain}/{user}/{project}{/tree/committish}#readme',
  56. 'httpstemplate': 'git+https://{auth@}{domain}/{user}/{project}.git{#committish}',
  57. 'filetemplate': 'https://{domain}/{user}/{project}/raw/{committish}/{path}',
  58. 'shortcuttemplate': '{type}:{user}/{project}{#committish}',
  59. 'pathtemplate': '{user}/{project}{#committish}',
  60. 'pathmatch': /^[/]([^/]+)[/]([^/]+?)(?:[.]git|[/])?$/,
  61. 'hashformat': formatHashFragment
  62. }
  63. Object.keys(gitHosts).forEach(function (name) {
  64. Object.keys(gitHostDefaults).forEach(function (key) {
  65. if (gitHosts[name][key]) return
  66. gitHosts[name][key] = gitHostDefaults[key]
  67. })
  68. gitHosts[name].protocols_re = RegExp('^(' +
  69. gitHosts[name].protocols.map(function (protocol) {
  70. return protocol.replace(/([\\+*{}()[\]$^|])/g, '\\$1')
  71. }).join('|') + '):$')
  72. })
  73. function formatHashFragment (fragment) {
  74. return fragment.toLowerCase().replace(/^\W+|\/|\W+$/g, '').replace(/\W+/g, '-')
  75. }