generated from actions/typescript-action
-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
15 changed files
with
189 additions
and
63 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
# Use LF as default EOL marker | ||
* text=auto eol=lf |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
### Added | ||
|
||
- Everything since the beginning! |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
### Changed | ||
|
||
- Our main theme is now blue instead of red. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
### Changed | ||
|
||
- Our main theme is now blue instead of red. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
### Changed | ||
|
||
- Our main theme is now blue instead of red. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import getReleaseNotes from "../src/getReleaseNotes"; | ||
import { read } from "to-vfile"; | ||
|
||
interface Fixture { | ||
tag: string; | ||
version: string; | ||
date: string; | ||
genesisHash: string; | ||
owner: string; | ||
repo: string; | ||
} | ||
|
||
it.each(["empty_release", "standard", "first_release", "lowercase_link_reference", "tag_release", "tag_on_tag"])( | ||
`should extract %s release-notes output`, | ||
async function(testcase) { | ||
const expectedChangelog = await read( | ||
`./__tests__/fixtures/${testcase}/CHANGELOG.expected.md`, | ||
{ | ||
encoding: "utf-8" | ||
} | ||
); | ||
const release: Fixture = await import( | ||
`./fixtures/${testcase}/fixture` | ||
).then(module => module.default); | ||
|
||
const expectedReleaseNotes = await read( | ||
`./__tests__/fixtures/${testcase}/release-notes.expected.md`, | ||
{ | ||
encoding: "utf-8" | ||
} | ||
).then(expected => expected.toString("utf-8")); | ||
const actualReleaseNotes = getReleaseNotes(expectedChangelog, release.version); | ||
expect(actualReleaseNotes).toEqual(expectedReleaseNotes); | ||
} | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import unified, { Transformer } from "unified"; | ||
import markdown from "remark-parse"; | ||
import stringify from "remark-stringify"; | ||
import { VFile } from "vfile"; | ||
import { Node } from "unist"; | ||
import { MarkdownRootNode } from "markdown-nodes"; | ||
|
||
function releaseNotesExtraction(version: string) { | ||
return transformer as unknown as Transformer; | ||
|
||
function transformer(tree: MarkdownRootNode, _file: VFile) { | ||
const children = tree.children; | ||
|
||
const firstNodeIndex = children.findIndex( | ||
node => node.type === "heading" && node.depth === 2 && | ||
node.children.length > 1 && node.children[0].type === "linkReference" && | ||
node.children[0].identifier === version | ||
) + 1; | ||
const firstNode = children.slice(firstNodeIndex); | ||
|
||
let lastNodeIndex = firstNode.findIndex( | ||
node => node.type === "heading" && node.depth === 2 | ||
); | ||
// special case: release notes for first release will not end with another | ||
// section, instead they end with the compare URLs | ||
if (lastNodeIndex === -1) { | ||
lastNodeIndex = firstNode.findIndex( | ||
node => node.type === "definition" && node.identifier === "unreleased" | ||
); | ||
} | ||
|
||
const releaseNotesNodes = firstNode.slice(0, lastNodeIndex); | ||
tree.children = releaseNotesNodes; | ||
return tree as Node; | ||
} | ||
} | ||
|
||
export default function getReleaseNotes( | ||
file: VFile, | ||
version: string | ||
): string { | ||
// @ts-ignore | ||
return unified() | ||
.use(markdown) | ||
.use(releaseNotesExtraction, version) | ||
.data("settings", { | ||
listItemIndent: "1", | ||
tightDefinitions: true, | ||
bullet: "-" | ||
}) | ||
.use(stringify) | ||
.processSync(file) | ||
.toString("utf-8") | ||
.trim(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
declare module "markdown-nodes" { | ||
import { Position } from "unist"; | ||
|
||
type MarkdownRootNode = { | ||
type: "root"; | ||
children: MarkdownNode[]; | ||
}; | ||
|
||
interface HeadingNode { | ||
type: "heading"; | ||
depth: number; | ||
children: MarkdownNode[]; | ||
position: Position; | ||
} | ||
|
||
interface DefinitionNode { | ||
type: "definition"; | ||
identifier: string; | ||
label: string; | ||
url: string; | ||
position?: Position; | ||
} | ||
|
||
interface ListNode { | ||
type: "list"; | ||
ordered: boolean; | ||
start: any; | ||
spread: boolean; | ||
url: string; | ||
children: object[]; | ||
position: Position; | ||
} | ||
|
||
interface ParagraphNode { | ||
type: "paragraph"; | ||
children: object[]; | ||
position: Position; | ||
} | ||
|
||
interface LinkReferenceNode { | ||
type: "linkReference"; | ||
identifier: string; | ||
label: string; | ||
referenceType: string; | ||
children: TextNode[]; | ||
position?: Position; | ||
} | ||
|
||
interface TextNode { | ||
type: "text"; | ||
value: string; | ||
position?: Position; | ||
} | ||
|
||
type MarkdownNode = | ||
| HeadingNode | ||
| DefinitionNode | ||
| ListNode | ||
| ParagraphNode | ||
| LinkReferenceNode | ||
| TextNode; | ||
} |