Skip to content

Commit c1db3cc

Browse files
authored
update regex to support repository shorthand (#561)
1 parent 9447717 commit c1db3cc

File tree

2 files changed

+30
-3
lines changed

2 files changed

+30
-3
lines changed

src/package.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -582,15 +582,15 @@ export class MarkdownProcessor extends BaseProcessor {
582582
return null;
583583
}
584584

585-
const regex = /github\.com\/([^/]+)\/([^/]+)(\/|$)/;
585+
const regex = /github(\.com\/|:)([^/]+)\/([^/]+)(\/|$)/;
586586
const match = regex.exec(repository);
587587

588588
if (!match) {
589589
return null;
590590
}
591591

592-
const account = match[1];
593-
const repositoryName = match[2].replace(/\.git$/i, '');
592+
const account = match[2];
593+
const repositoryName = match[3].replace(/\.git$/i, '');
594594
const branchName = githubBranch ? githubBranch : 'HEAD';
595595

596596
return {

src/test/package.test.ts

+27
Original file line numberDiff line numberDiff line change
@@ -1930,6 +1930,33 @@ describe('MarkdownProcessor', () => {
19301930
});
19311931
});
19321932

1933+
it('should infer baseContentUrl if its a github repo (short format)', () => {
1934+
const manifest = {
1935+
name: 'test',
1936+
publisher: 'mocha',
1937+
version: '0.0.1',
1938+
description: 'test extension',
1939+
engines: Object.create(null),
1940+
repository: 'github:username/repository',
1941+
};
1942+
1943+
const root = fixture('readme');
1944+
const processor = new ReadmeProcessor(manifest, {});
1945+
const readme = {
1946+
path: 'extension/readme.md',
1947+
localPath: path.join(root, 'readme.md'),
1948+
};
1949+
1950+
return processor
1951+
.onFile(readme)
1952+
.then(file => read(file))
1953+
.then(actual => {
1954+
return readFile(path.join(root, 'readme.default.md'), 'utf8').then(expected => {
1955+
assert.equal(actual, expected);
1956+
});
1957+
});
1958+
});
1959+
19331960
it('should replace img urls with baseImagesUrl', () => {
19341961
const manifest = {
19351962
name: 'test',

0 commit comments

Comments
 (0)