Skip to content

Commit

Permalink
fix: Allow slashes in gitlab project section
Browse files Browse the repository at this point in the history
Technically these are called groups and subgroups in GitLab parlance,
but effectively, it means that a GitLab project url can have a path with
unlimited portions, like company/property/team/component.git.

This allows passing in unlimited path portions in the full url, and
avoids encoding the `project` section akin to how `path` is treated as
of 3776fa5 #44

Fix #46
Fix #43
  • Loading branch information
isaacs committed Aug 4, 2019
1 parent 60abaea commit bbcf7b2
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
3 changes: 2 additions & 1 deletion git-host-info.js
Expand Up @@ -24,7 +24,8 @@ var gitHosts = module.exports = {
'treepath': 'tree',
'bugstemplate': 'https://{domain}/{user}/{project}/issues',
'httpstemplate': 'git+https://{auth@}{domain}/{user}/{projectPath}.git{#committish}',
'tarballtemplate': 'https://{domain}/{user}/{project}/repository/archive.tar.gz?ref={committish}'
'tarballtemplate': 'https://{domain}/{user}/{project}/repository/archive.tar.gz?ref={committish}',
'pathmatch': /^[/]([^/]+)[/](.+?)(?:[.]git|[/])?$/
},
gist: {
'protocols': [ 'git', 'git+ssh', 'git+https', 'ssh', 'https' ],
Expand Down
2 changes: 1 addition & 1 deletion git-host.js
Expand Up @@ -52,7 +52,7 @@ GitHost.prototype._fill = function (template, opts) {
var rawProject = vars.project
Object.keys(vars).forEach(function (key) {
var value = vars[key]
if (key === 'path' && typeof value === 'string') {
if ((key === 'path' || key === 'project') && typeof value === 'string') {
vars[key] = value.split('/').map(function (pathComponent) {
return encodeURIComponent(pathComponent)
}).join('/')
Expand Down
9 changes: 9 additions & 0 deletions test/gitlab.js
Expand Up @@ -28,6 +28,15 @@ test('fromUrl(gitlab url)', function (t) {
require('./lib/standard-tests')(verify, 'gitlab.com', 'gitlab')
require('./lib/standard-tests')(verify, 'www.gitlab.com', 'gitlab')

const subsShort = HostedGit.fromUrl('gitlab:adpt/starters/hello-node')
const subsFull = HostedGit.fromUrl('git+https://gitlab.com/adpt/starters/hello-node.git')
t.ok(subsShort)
t.equal(subsShort.https(), 'git+https://gitlab.com/adpt/starters/hello-node.git')
t.equal(subsShort.ssh(), 'git@gitlab.com:adpt/starters/hello-node.git')
t.ok(subsFull)
t.equal(subsFull.https(), 'git+https://gitlab.com/adpt/starters/hello-node.git')
t.equal(subsFull.ssh(), 'git@gitlab.com:adpt/starters/hello-node.git')

t.is(
HostedGit.fromUrl('gitlab:group/sub group1/subgroup2/repo').https(),
'git+https://gitlab.com/group/sub%20group1/subgroup2/repo.git',
Expand Down

0 comments on commit bbcf7b2

Please sign in to comment.