use GitHub link type

This commit is contained in:
Joao Moreno 2016-07-19 15:52:25 +02:00
parent 79e8f4eb22
commit c3af0c2627
3 changed files with 69 additions and 10 deletions

View file

@ -11,7 +11,11 @@
<% if (links.repository) { %>
<Property Id="Microsoft.VisualStudio.Services.Links.Source" Value="<%- links.repository %>" />
<Property Id="Microsoft.VisualStudio.Services.Links.Getstarted" Value="<%- links.repository %>" />
<% if (links.github) { %>
<Property Id="Microsoft.VisualStudio.Services.Links.GitHub" Value="<%- links.github %>" />
<% } else { %>
<Property Id="Microsoft.VisualStudio.Services.Links.Repository" Value="<%- links.repository %>" />
<% } %>
<% } %>
<% if (links.bugs) { %><Property Id="Microsoft.VisualStudio.Services.Links.Support" Value="<%- links.bugs %>" /><% } %>
<% if (links.homepage) { %><Property Id="Microsoft.VisualStudio.Services.Links.Learn" Value="<%- links.homepage %>" /><% } %>

View file

@ -89,6 +89,16 @@ function getUrl(url: string | { url?: string; }): string {
return (<any> 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;
}
}
}

View file

@ -12,7 +12,7 @@ import * as denodeify from 'denodeify';
import * as _ from 'lodash';
const readFile = denodeify<string, string, string>(fs.readFile);
const parseXml = denodeify<string,any>(parseString);
const parseXml = denodeify<string, any>(parseString);
const fixture = name => path.join(__dirname, 'fixtures', name);
function _toVsixManifest(manifest: Manifest, files: IFile[]): Promise<string> {
@ -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'));
});
});