Skip to content

Commit

Permalink
fix: fixes bug with repo url handling (#97)
Browse files Browse the repository at this point in the history
* fix: fixes bug with repo url handling

when repo url was user/name shorthand we failed if it had extra path
chunks. user/name/tacos etc. because users have been allowed to publish
packages this way have have to add support for reading thme out of the
registry this way.
  • Loading branch information
soldair committed Feb 24, 2021
1 parent 4565a0c commit 93638a0
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/lib/packument.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,15 @@ export const repoToGithub = (
if (url && url.indexOf('https://github.com') === 0) {
return {url, name: new URL(url).pathname.substr(1)};
}
if (!url && repo.url.match(/^[^/]+\/[^/]+$/)) {

if (!url && /^[^/]+\/[^/]+/.test(repo.url)) {
//'xxxx/xxxx' username/repo specifier
return {url: 'https://github.com/' + repo.url, name: repo.url};
const matches = repo.url.match(/^([^/]+\/[^/]+)(.+)?$/);
// grabs the first 2 / delimited chunks.
const cleaned = matches ? matches[1] : null;
if (cleaned) {
return {url: 'https://github.com/' + cleaned, name: cleaned};
}
}
}
}
Expand Down
27 changes: 27 additions & 0 deletions test/lib/packument.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import {expect} from 'chai';
import {describe, it} from 'mocha';

import {repoToGithub} from '../../src/lib/packument';

describe('repoToGithub', () => {
it('handles github url shorthand with extra path segments', () => {
const result = repoToGithub({
type: 'git',
url:
'GoogleCloudPlatform/cloud-for-marketing/tree/master/marketing-analytics/activation/common-libs/nodejs-common',
});

const match = repoToGithub({
type: 'git',
url: 'GoogleCloudPlatform/cloud-for-marketing',
});

const expected = {
url: 'https://github.com/GoogleCloudPlatform/cloud-for-marketing',
name: 'GoogleCloudPlatform/cloud-for-marketing',
};

expect(result).to.eql(expected);
expect(match).to.eql(expected);
});
});

0 comments on commit 93638a0

Please sign in to comment.