diff --git a/resources/extension.vsixmanifest b/resources/extension.vsixmanifest
index 9b4ae83..33edb5f 100644
--- a/resources/extension.vsixmanifest
+++ b/resources/extension.vsixmanifest
@@ -11,7 +11,11 @@
<% if (links.repository) { %>
+ <% if (links.github) { %>
+
+ <% } else { %>
+ <% } %>
<% } %>
<% if (links.bugs) { %><% } %>
<% if (links.homepage) { %><% } %>
diff --git a/src/package.ts b/src/package.ts
index 43d0d1b..47e493d 100644
--- a/src/package.ts
+++ b/src/package.ts
@@ -89,6 +89,16 @@ function getUrl(url: string | { url?: string; }): string {
return ( url).url;
}
+function getRepositoryUrl(url: string | { url?: string; }): string {
+ const result = getUrl(url);
+
+ if (/^[^\/]+\/[^\/]+$/.test(result)) {
+ return `https://github.com/${ result }.git`;
+ }
+
+ return result;
+}
+
// Contributed by Mozilla develpoer authors
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions
function escapeRegExp(string){
@@ -106,6 +116,8 @@ class ManifestProcessor extends BaseProcessor {
flags.push('Preview');
}
+ const repository = getRepositoryUrl(manifest.repository);
+
_.assign(this.vsix, {
id: manifest.name,
displayName: manifest.displayName || manifest.name,
@@ -115,12 +127,16 @@ class ManifestProcessor extends BaseProcessor {
categories: (manifest.categories || []).join(','),
flags: flags.join(' '),
links: {
- repository: getUrl(manifest.repository),
+ repository,
bugs: getUrl(manifest.bugs),
homepage: manifest.homepage
},
galleryBanner: manifest.galleryBanner || {}
});
+
+ if (/^https:\/\/github\.com\/|^git@github\.com:/.test(repository)) {
+ this.vsix.links.github = repository;
+ }
}
}
diff --git a/src/test/package.test.ts b/src/test/package.test.ts
index accde42..2ad9a0c 100644
--- a/src/test/package.test.ts
+++ b/src/test/package.test.ts
@@ -12,7 +12,7 @@ import * as denodeify from 'denodeify';
import * as _ from 'lodash';
const readFile = denodeify(fs.readFile);
-const parseXml = denodeify(parseString);
+const parseXml = denodeify(parseString);
const fixture = name => path.join(__dirname, 'fixtures', name);
function _toVsixManifest(manifest: Manifest, files: IFile[]): Promise {
@@ -374,23 +374,62 @@ describe('toVsixManifest', () => {
engines: Object.create(null),
repository: {
type: "git",
- url: "https://github.com/Microsoft/vscode-spell-check.git"
+ url: "https://server.com/Microsoft/vscode-spell-check.git"
},
bugs: {
- url: "https://github.com/Microsoft/vscode-spell-check/issues"
+ url: "https://server.com/Microsoft/vscode-spell-check/issues"
},
- homepage: "https://github.com/Microsoft/vscode-spell-check",
+ homepage: "https://server.com/Microsoft/vscode-spell-check",
};
return _toVsixManifest(manifest, [])
.then(xml => parseXml(xml))
.then(result => {
const properties = result.PackageManifest.Metadata[0].Properties[0].Property.map(p => p.$);
- assert.ok(properties.some(p => p.Id === 'Microsoft.VisualStudio.Services.Links.Source' && p.Value === 'https://github.com/Microsoft/vscode-spell-check.git'));
- assert.ok(properties.some(p => p.Id === 'Microsoft.VisualStudio.Services.Links.Getstarted' && p.Value === 'https://github.com/Microsoft/vscode-spell-check.git'));
- assert.ok(properties.some(p => p.Id === 'Microsoft.VisualStudio.Services.Links.Repository' && p.Value === 'https://github.com/Microsoft/vscode-spell-check.git'));
- assert.ok(properties.some(p => p.Id === 'Microsoft.VisualStudio.Services.Links.Support' && p.Value === 'https://github.com/Microsoft/vscode-spell-check/issues'));
- assert.ok(properties.some(p => p.Id === 'Microsoft.VisualStudio.Services.Links.Learn' && p.Value === 'https://github.com/Microsoft/vscode-spell-check'));
+ assert.ok(properties.some(p => p.Id === 'Microsoft.VisualStudio.Services.Links.Source' && p.Value === 'https://server.com/Microsoft/vscode-spell-check.git'));
+ assert.ok(properties.some(p => p.Id === 'Microsoft.VisualStudio.Services.Links.Getstarted' && p.Value === 'https://server.com/Microsoft/vscode-spell-check.git'));
+ assert.ok(properties.some(p => p.Id === 'Microsoft.VisualStudio.Services.Links.Repository' && p.Value === 'https://server.com/Microsoft/vscode-spell-check.git'));
+ assert.ok(properties.some(p => p.Id === 'Microsoft.VisualStudio.Services.Links.Support' && p.Value === 'https://server.com/Microsoft/vscode-spell-check/issues'));
+ assert.ok(properties.some(p => p.Id === 'Microsoft.VisualStudio.Services.Links.Learn' && p.Value === 'https://server.com/Microsoft/vscode-spell-check'));
+ });
+ });
+
+ it('should detect github repositories', () => {
+ const manifest = {
+ name: 'test',
+ publisher: 'mocha',
+ version: '0.0.1',
+ engines: Object.create(null),
+ repository: {
+ type: "git",
+ url: "https://github.com/Microsoft/vscode-spell-check.git"
+ }
+ };
+
+ return _toVsixManifest(manifest, [])
+ .then(xml => parseXml(xml))
+ .then(result => {
+ const properties = result.PackageManifest.Metadata[0].Properties[0].Property.map(p => p.$);
+ assert.ok(properties.some(p => p.Id === 'Microsoft.VisualStudio.Services.Links.GitHub' && p.Value === 'https://github.com/Microsoft/vscode-spell-check.git'));
+ assert.ok(properties.every(p => p.Id !== 'Microsoft.VisualStudio.Services.Links.Repository'));
+ });
+ });
+
+ it('should detect short github repositories', () => {
+ const manifest = {
+ name: 'test',
+ publisher: 'mocha',
+ version: '0.0.1',
+ engines: Object.create(null),
+ repository: 'Microsoft/vscode-spell-check'
+ };
+
+ return _toVsixManifest(manifest, [])
+ .then(xml => parseXml(xml))
+ .then(result => {
+ const properties = result.PackageManifest.Metadata[0].Properties[0].Property.map(p => p.$);
+ assert.ok(properties.some(p => p.Id === 'Microsoft.VisualStudio.Services.Links.GitHub' && p.Value === 'https://github.com/Microsoft/vscode-spell-check.git'));
+ assert.ok(properties.every(p => p.Id !== 'Microsoft.VisualStudio.Services.Links.Repository'));
});
});