Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: replace linkify-markdown #9954

Merged
merged 13 commits into from
May 19, 2021
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions lib/types/remark-github.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/**
* Types for `remark-github`
*
* @see https://github.com/remarkjs/remark-github
*/
declare module 'remark-github' {
import type { Plugin } from 'unified';

namespace github {
export interface Options {
/**
* Wrap mentions in `<strong>`, true by default.
* @see https://github.com/remarkjs/remark-github#mentions
*/
mentionStrong?: boolean;

/**
* Repository to link against.
*
* @see https://github.com/remarkjs/remark-github#repository
*/
repository?: string;
}
}

const github: Plugin<[github.Options?]>;

export = github;
}
15 changes: 15 additions & 0 deletions lib/util/__snapshots__/markdown.spec.ts.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`util/markdown .linkify works 1`] = `
"Some references:

* Commit: [\`f808317\`](https://github.com/some/repo/commit/f8083175fe890cbf14f41d0a06e7aa35d4989587)
* Commit (fork): [foo@\`f808317\`](https://github.com/foo/repo/commit/f8083175fe890cbf14f41d0a06e7aa35d4989587)
* Commit (repo): [remarkjs/remark@\`e1aa9f6\`](https://github.com/remarkjs/remark/commit/e1aa9f6c02de18b9459b7d269712bcb50183ce89)
* Issue or PR (\`#\`): [#1](https://github.com/some/repo/issues/1)
* Issue or PR (\`GH-\`): [GH-1](https://github.com/some/repo/issues/1)
* Issue or PR (fork): [foo#1](https://github.com/foo/repo/issues/1)
* Issue or PR (project): [remarkjs/remark#1](https://github.com/remarkjs/remark/issues/1)
* Mention: [@wooorm](https://github.com/wooorm)
"
`;
21 changes: 21 additions & 0 deletions lib/util/markdown.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { getName } from '../../test/util';
import { linkify } from './markdown';

describe(getName(), () => {
describe('.linkify', () => {
const md = `Some references:

* Commit: f8083175fe890cbf14f41d0a06e7aa35d4989587
* Commit (fork): foo@f8083175fe890cbf14f41d0a06e7aa35d4989587
* Commit (repo): remarkjs/remark@e1aa9f6c02de18b9459b7d269712bcb50183ce89
* Issue or PR (\`#\`): #1
* Issue or PR (\`GH-\`): GH-1
* Issue or PR (fork): foo#1
* Issue or PR (project): remarkjs/remark#1
* Mention: @wooorm
`;
it('works', async () => {
expect(await linkify(md, { repository: 'some/repo' })).toMatchSnapshot();
});
});
});
21 changes: 21 additions & 0 deletions lib/util/markdown.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import remark from 'remark';
import github from 'remark-github';

// Generic replacements/link-breakers
export function sanitizeMarkdown(markdown: string): string {
let res = markdown;
Expand All @@ -16,3 +19,21 @@ export function sanitizeMarkdown(markdown: string): string {
res = res.replace(/`#&#8203;(\d+)`/g, '`#$1`');
return res;
}

/**
*
* @param content content to process
* @param options github options
* @returns linkified content
*/
export async function linkify(
content: string,
options: github.Options
): Promise<string> {
// https://github.com/syntax-tree/mdast-util-to-markdown#optionsbullet
const output = await remark()
.use({ settings: { bullet: '-' } })
.use(github, { mentionStrong: false, ...options })
.process(content);
return output.toString();
}
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,7 @@ Closes ADAPT-207

See merge request itentialopensource/adapter-utils!177

* * *
***
",
"url": "https://gitlab.com/itentialopensource/adapter-utils/blob/master/CHANGELOG.md#4330-05-15-2020",
}
Expand Down Expand Up @@ -789,7 +789,7 @@ Object {
([#4730](https://github.com/facebook/jest/pull/4730))
- \`[jest-runtime]\` Use realpath to match transformers
([#5000](https://github.com/facebook/jest/pull/5000))
- \`[expect]\` [**BREAKING**] Replace identity equality with Object.is in toBe
- \`[expect]\` \\\\[**BREAKING**] Replace identity equality with Object.is in toBe
matcher ([#4917](https://github.com/facebook/jest/pull/4917))

##### Features
Expand All @@ -810,18 +810,18 @@ Object {
([#4866](https://github.com/facebook/jest/pull/4866))
- \`[eslint-plugin-jest]\` Add \`prefer-to-have-length\` lint rule.
([#4771](https://github.com/facebook/jest/pull/4771))
- \`[jest-environment-jsdom]\` [**BREAKING**] Upgrade to JSDOM@11
- \`[jest-environment-jsdom]\` \\\\[**BREAKING**] Upgrade to JSDOM@11
([#4770](https://github.com/facebook/jest/pull/4770))
- \`[jest-environment-*]\` [**BREAKING**] Add Async Test Environment APIs, dispose
- \`[jest-environment-*]\` \\\\[**BREAKING**] Add Async Test Environment APIs, dispose
is now teardown ([#4506](https://github.com/facebook/jest/pull/4506))
- \`[jest-cli]\` Add an option to clear the cache
([#4430](https://github.com/facebook/jest/pull/4430))
- \`[babel-plugin-jest-hoist]\` Improve error message, that the second argument of
\`jest.mock\` must be an inline function
([#4593](https://github.com/facebook/jest/pull/4593))
- \`[jest-snapshot]\` [**BREAKING**] Concatenate name of test and snapshot
- \`[jest-snapshot]\` \\\\[**BREAKING**] Concatenate name of test and snapshot
([#4460](https://github.com/facebook/jest/pull/4460))
- \`[jest-cli]\` [**BREAKING**] Fail if no tests are found
- \`[jest-cli]\` \\\\[**BREAKING**] Fail if no tests are found
([#3672](https://github.com/facebook/jest/pull/3672))
- \`[jest-diff]\` Highlight only last of odd length leading spaces
([#4558](https://github.com/facebook/jest/pull/4558))
Expand Down Expand Up @@ -855,7 +855,7 @@ Object {
([#4614](https://github.com/facebook/jest/pull/4614))
- \`[jest-runtime]\` Support sourcemaps in transformers
([#3458](https://github.com/facebook/jest/pull/3458))
- \`[jest-snapshot]\` [**BREAKING**] Add a serializer for \`jest.fn\` to allow a
- \`[jest-snapshot]\` \\\\[**BREAKING**] Add a serializer for \`jest.fn\` to allow a
snapshot of a jest mock ([#4668](https://github.com/facebook/jest/pull/4668))
- \`[jest-worker]\` Initial version of parallel worker abstraction, say hello!
([#4497](https://github.com/facebook/jest/pull/4497))
Expand All @@ -877,7 +877,7 @@ Object {
([#5093](https://github.com/facebook/jest/pull/5093))
- \`[jest-util]\` \`jest-util\` should not depend on \`jest-mock\`
([#4992](https://github.com/facebook/jest/pull/4992))
- \`[*]\` [**BREAKING**] Drop support for Node.js version 4
- \`[*]\` \\\\[**BREAKING**] Drop support for Node.js version 4
([#4769](https://github.com/facebook/jest/pull/4769))
- \`[docs]\` Wrap code comments at 80 characters
([#4781](https://github.com/facebook/jest/pull/4781))
Expand Down
10 changes: 5 additions & 5 deletions lib/workers/pr/changelog/release-notes.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import * as URL from 'url';
import is from '@sindresorhus/is';
import { linkify } from 'linkify-markdown';
import { DateTime } from 'luxon';
import MarkdownIt from 'markdown-it';
import { PLATFORM_TYPE_GITLAB } from '../../../constants/platforms';
import { logger } from '../../../logger';
import * as memCache from '../../../util/cache/memory';
import * as packageCache from '../../../util/cache/package';
import * as hostRules from '../../../util/host-rules';
import { linkify } from '../../../util/markdown';
import * as github from './github';
import * as gitlab from './gitlab';
import type { ChangeLogFile, ChangeLogNotes, ChangeLogResult } from './types';
Expand Down Expand Up @@ -104,7 +104,7 @@ export async function getReleaseNotes(
const releaseList = await getCachedReleaseList(apiBaseUrl, repository);
logger.trace({ releaseList }, 'Release list from getReleaseList');
let releaseNotes: ChangeLogNotes | null = null;
releaseList.forEach((release) => {
for (const release of releaseList) {
if (
release.tag === version ||
release.tag === `v${version}` ||
Expand All @@ -120,7 +120,7 @@ export async function getReleaseNotes(
if (releaseNotes.body.length) {
try {
if (baseUrl !== 'https://gitlab.com/') {
releaseNotes.body = linkify(releaseNotes.body, {
releaseNotes.body = await linkify(releaseNotes.body, {
repository: `${baseUrl}${repository}`,
});
}
Expand All @@ -131,7 +131,7 @@ export async function getReleaseNotes(
releaseNotes = null;
}
}
});
}
logger.trace({ releaseNotes });
return releaseNotes;
}
Expand Down Expand Up @@ -257,7 +257,7 @@ export async function getReleaseNotesMd(
body = massageBody(body, baseUrl);
if (body?.length) {
try {
body = linkify(body, {
body = await linkify(body, {
repository: `${baseUrl}${repository}`,
});
} catch (err) /* istanbul ignore next */ {
Expand Down
8 changes: 6 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
"markdown-lint": "markdownlint-cli2",
"markdown-lint-fix": "markdownlint-cli2-fix",
"prepare": "run-s prepare:*",
"prepare:fix-packages": "patch-package",
"prepare:generate": "run-s generate:*",
"prepare:re2": "node tools/check-re2.mjs",
"prepare:tools": "tsc -p tools",
Expand Down Expand Up @@ -159,7 +160,6 @@
"json-dup-key-validator": "1.0.3",
"json-stringify-pretty-compact": "2.0.0",
"json5": "2.2.0",
"linkify-markdown": "1.0.0",
"luxon": "1.26.0",
"markdown-it": "12.0.6",
"markdown-table": "2.0.0",
Expand All @@ -174,6 +174,8 @@
"parse-link-header": "1.0.1",
"redis": "3.1.2",
"registry-auth-token": "4.2.1",
"remark": "13.0.0",
"remark-github": "10.0.1",
"semver": "7.3.5",
"semver-stable": "3.0.0",
"semver-utils": "1.1.4",
Expand Down Expand Up @@ -252,6 +254,7 @@
"mockdate": "3.0.5",
"nock": "13.0.11",
"npm-run-all": "4.1.5",
"patch-package": "6.4.7",
"prettier": "2.2.1",
"pretty-quick": "3.1.0",
"rimraf": "3.0.2",
Expand All @@ -262,7 +265,8 @@
"ts-jest": "26.5.5",
"ts-node": "9.1.1",
"type-fest": "1.0.2",
"typescript": "4.2.4"
"typescript": "4.2.4",
"unified": "9.2.1"
},
"resolutions": {
"underscore": "^1.12.1",
Expand Down
13 changes: 13 additions & 0 deletions patches/vfile-message+2.0.4.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
diff --git a/node_modules/vfile-message/types/index.d.ts b/node_modules/vfile-message/types/index.d.ts
index d217843..31c853a 100644
--- a/node_modules/vfile-message/types/index.d.ts
+++ b/node_modules/vfile-message/types/index.d.ts
@@ -6,7 +6,7 @@ declare namespace vfileMessage {
/**
* Create a virtual message.
*/
- interface VFileMessage extends Error {
+ interface VFileMessage extends Omit<Error, 'location'> {
/**
* Constructor of a message for `reason` at `position` from `origin`.
* When an error is passed in as `reason`, copies the `stack`.
Loading