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