Add --noGitHubIssueLinking to stop issue link expansion in package step
This commit is contained in:
parent
ee42cf42c0
commit
368ffbd535
3 changed files with 45 additions and 14 deletions
|
@ -74,7 +74,8 @@ module.exports = function (argv: string[]): void {
|
|||
.option('--baseImagesUrl [url]', 'Prepend all relative image links in README.md with this url.')
|
||||
.option('--yarn', 'Use yarn instead of npm')
|
||||
.option('--ignoreFile [path]', 'Indicate alternative .vscodeignore')
|
||||
.action(({ out, baseContentUrl, baseImagesUrl, yarn, ignoreFile }) => main(packageCommand({ packagePath: out, baseContentUrl, baseImagesUrl, useYarn: yarn, ignoreFile })));
|
||||
.option('--noGitHubIssueLinking', 'Prevent automatic expansion of GitHub-style issue syntax into links')
|
||||
.action(({ out, baseContentUrl, baseImagesUrl, yarn, ignoreFile, noGitHubIssueLinking }) => main(packageCommand({ packagePath: out, baseContentUrl, baseImagesUrl, useYarn: yarn, ignoreFile, expandGitHubIssueLinks: noGitHubIssueLinking })));
|
||||
|
||||
program
|
||||
.command('publish [<version>]')
|
||||
|
|
|
@ -65,6 +65,7 @@ export interface IPackageOptions {
|
|||
useYarn?: boolean;
|
||||
dependencyEntryPoints?: string[];
|
||||
ignoreFile?: string;
|
||||
expandGitHubIssueLinks?: boolean;
|
||||
}
|
||||
|
||||
export interface IProcessor {
|
||||
|
@ -356,6 +357,7 @@ export class MarkdownProcessor extends BaseProcessor {
|
|||
private baseImagesUrl: string;
|
||||
private isGitHub: boolean;
|
||||
private repositoryUrl: string;
|
||||
private expandGitHubIssueLinks: boolean;
|
||||
|
||||
constructor(manifest: Manifest, private name: string, private regexp: RegExp, private assetType: string, options: IPackageOptions = {}) {
|
||||
super(manifest);
|
||||
|
@ -366,6 +368,7 @@ export class MarkdownProcessor extends BaseProcessor {
|
|||
this.baseImagesUrl = options.baseImagesUrl || options.baseContentUrl || (guess && guess.images);
|
||||
this.repositoryUrl = (guess && guess.repository);
|
||||
this.isGitHub = isGitHubRepository(this.repositoryUrl);
|
||||
this.expandGitHubIssueLinks = typeof options.expandGitHubIssueLinks === 'boolean' ? options.expandGitHubIssueLinks : true;
|
||||
}
|
||||
|
||||
async onFile(file: IFile): Promise<IFile> {
|
||||
|
@ -424,17 +427,17 @@ export class MarkdownProcessor extends BaseProcessor {
|
|||
return all.replace(link, urljoin(prefix, link));
|
||||
});
|
||||
|
||||
const markdownIssueRegex = /(\s|\n)([\w\d_-]+\/[\w\d_-]+)?#(\d+)\b/g
|
||||
const issueReplace = (all: string, prefix: string, ownerAndRepositoryName: string, issueNumber: string): string => {
|
||||
let result = all;
|
||||
let owner: string;
|
||||
let repositoryName: string;
|
||||
if (this.isGitHub && this.expandGitHubIssueLinks) {
|
||||
const markdownIssueRegex = /(\s|\n)([\w\d_-]+\/[\w\d_-]+)?#(\d+)\b/g
|
||||
const issueReplace = (all: string, prefix: string, ownerAndRepositoryName: string, issueNumber: string): string => {
|
||||
let result = all;
|
||||
let owner: string;
|
||||
let repositoryName: string;
|
||||
|
||||
if (ownerAndRepositoryName) {
|
||||
[owner, repositoryName] = ownerAndRepositoryName.split('/', 2);
|
||||
}
|
||||
if (ownerAndRepositoryName) {
|
||||
[owner, repositoryName] = ownerAndRepositoryName.split('/', 2);
|
||||
}
|
||||
|
||||
if (this.isGitHub) {
|
||||
if (owner && repositoryName && issueNumber) {
|
||||
// Issue in external repository
|
||||
const issueUrl = urljoin('https://github.com', owner, repositoryName, 'issues', issueNumber);
|
||||
|
@ -444,12 +447,12 @@ export class MarkdownProcessor extends BaseProcessor {
|
|||
// Issue in own repository
|
||||
result = prefix + `[#${issueNumber}](${urljoin(this.repositoryUrl, 'issues', issueNumber)})`;
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
return result;
|
||||
}
|
||||
// Replace Markdown issue references with urls
|
||||
contents = contents.replace(markdownIssueRegex, issueReplace);
|
||||
}
|
||||
// Replace Markdown issue references with urls
|
||||
contents = contents.replace(markdownIssueRegex, issueReplace);
|
||||
|
||||
const html = markdownit({ html: true }).render(contents);
|
||||
const $ = cheerio.load(html);
|
||||
|
|
|
@ -1551,6 +1551,33 @@ describe('MarkdownProcessor', () => {
|
|||
});
|
||||
});
|
||||
|
||||
it('should not replace issue links with urls if its a github repo but issue link expansion is disabled.', () => {
|
||||
const manifest = {
|
||||
name: 'test',
|
||||
publisher: 'mocha',
|
||||
version: '0.0.1',
|
||||
description: 'test extension',
|
||||
engines: Object.create(null),
|
||||
repository: 'https://github.com/username/repository.git'
|
||||
};
|
||||
|
||||
const root = fixture('readme');
|
||||
const processor = new ReadmeProcessor(manifest, { expandGitHubIssueLinks: false });
|
||||
const readme = {
|
||||
path: 'extension/readme.md',
|
||||
localPath: path.join(root, 'readme.github.md')
|
||||
};
|
||||
|
||||
return processor.onFile(readme)
|
||||
.then(file => read(file))
|
||||
.then(actual => {
|
||||
return readFile(path.join(root, 'readme.github.md'), 'utf8')
|
||||
.then(expected => {
|
||||
assert.equal(actual, expected);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
it('should not replace issue links with urls if its not a github repo.', () => {
|
||||
const manifest = {
|
||||
name: 'test',
|
||||
|
|
Loading…
Add table
Reference in a new issue