diff --git a/src/Ionide.KeepAChangelog.Tasks/Library.fs b/src/Ionide.KeepAChangelog.Tasks/Library.fs index aa1abd1..48425b3 100644 --- a/src/Ionide.KeepAChangelog.Tasks/Library.fs +++ b/src/Ionide.KeepAChangelog.Tasks/Library.fs @@ -30,6 +30,10 @@ module Util = item + let mapDescription (description: string) (item: ITaskItem) : ITaskItem = + item.SetMetadata("Description", description) + item + type ParseChangelogs() = inherit Task() @@ -72,6 +76,10 @@ type ParseChangelogs() = |> Seq.map (fun release -> TaskItem() |> Util.mapReleaseInfo release.Version release.Date + |> fun d -> + match release.Description with + | Some desc -> Util.mapDescription desc d + | None -> d |> fun d -> match release.Data with | Some data -> Util.mapChangelogData data d diff --git a/src/Ionide.KeepAChangelog/Library.fs b/src/Ionide.KeepAChangelog/Library.fs index f0ea828..1aee9ac 100644 --- a/src/Ionide.KeepAChangelog/Library.fs +++ b/src/Ionide.KeepAChangelog/Library.fs @@ -41,6 +41,7 @@ module Domain = { Version: SemanticVersion Date: DateTime Data: ChangelogData option + Description: string option IsYanked: bool } type Changelogs = @@ -233,6 +234,18 @@ module Parser = let pVersion = mdUrl pSemver <|> pSemver + let pReleaseDescription = + let nextHeader = (opt newline >>. regex @"[#]{1,3}\s\S" |>> ignore) + let endOfSection = choice [ eof; nextHeader ] + + let description = + (manyTill anyChar (lookAhead endOfSection) .>> attempt (opt newline)) + |>> function + | [] -> None + | x -> Some(System.String.Concat x) + + description "release description body" + let pRelease: Parser = let vPart = skipString "##" >>. spaces1 >>. pVersion let middle = spaces1 .>> pchar '-' .>> spaces1 @@ -240,11 +253,20 @@ module Parser = let yanked = opt spaces1 >>. pYanked let content = choice [ pData; pNonStructuredData ] - pipe6 vPart middle date yanked (opt (many newline)) (opt content) (fun v _ date yanked _ data -> - { Version = v - Date = date - Data = data - IsYanked = yanked }) + pipe7 + vPart + middle + date + yanked + (opt (many newline)) + pReleaseDescription + (opt content) + (fun v _ date yanked _ desciption data -> + { Version = v + Date = date + Data = data + Description = desciption + IsYanked = yanked }) let pChangeLogs: Parser = let unreleased = diff --git a/test/Ionide.KeepAChangelog.Test/Program.fs b/test/Ionide.KeepAChangelog.Test/Program.fs index 5416a21..ea43959 100644 --- a/test/Ionide.KeepAChangelog.Test/Program.fs +++ b/test/Ionide.KeepAChangelog.Test/Program.fs @@ -30,6 +30,7 @@ let singleReleaseExpected = Removed = "- C\n" } IsYanked = false + Description = None } let keepAChangelog = @@ -72,6 +73,7 @@ let keepAChangelogExpected: Changelogs = Added = "- A\n- B\n- C\n\n" } IsYanked = false + Description = None } ] } @@ -109,6 +111,7 @@ let sample1ReleaseExpected = Date = DateTime(2022, 1, 8) Data = Some { ChangelogData.Default with Added = "- Add XmlDocs to the generated package\n\n" } IsYanked = false + Description = None } let yankedRelease = normalizeNewline """## [0.3.1] - 8.1.2022 [YANKED] @@ -125,6 +128,29 @@ let yankedReleaseExpected = Date = DateTime(2022, 1, 8) Data = Some { ChangelogData.Default with Added = "- Add XmlDocs to the generated package\n\n" } IsYanked = true + Description = None + } + +let releaseWithDescription = + normalizeNewline """## [0.3.1] - 8.1.2022 + +This is a description + +And there is even a second line + +### Added + +- Add XmlDocs to the generated package + +""" + +let releaseWithDescriptionExpected = + { + Version = SemanticVersion.Parse "0.3.1" + Date = DateTime(2022, 1, 8) + Data = Some { ChangelogData.Default with Added = "- Add XmlDocs to the generated package\n\n" } + IsYanked = false + Description = Some "This is a description\n\nAnd there is even a second line\n" } let sample = normalizeNewline """# Changelog @@ -167,6 +193,7 @@ let sampleExpected: Changelogs = { Date = DateTime(2022, 1, 8) Data = Some { ChangelogData.Default with Added = "* Add XmlDocs to the generated package\n" } IsYanked = false + Description = None } { Version = SemanticVersion.Parse "0.3.0" @@ -179,18 +206,21 @@ let sampleExpected: Changelogs = { * Map CodeAction.IsPreferred & CodeAction.Disabled props. (by @razzmatazz) """ } IsYanked = false + Description = None } { Version = SemanticVersion.Parse "0.2.0" Date = DateTime(2021, 11, 17) Data = Some { ChangelogData.Default with Added = "* Add support for `codeAction/resolve` (by @razzmatazz)\n" } IsYanked = false + Description = None } { Version = SemanticVersion.Parse "0.1.1" Date = DateTime(2021, 11, 15) Data = Some { ChangelogData.Default with Added = "* Initial implementation\n" } IsYanked = false + Description = None } ] @@ -220,7 +250,7 @@ let runSuccessNormalized label (p: Parser) text (expected:string) = failwithf "%A" m } -let parsingExamples = testList "parsing examples" [ +let parsingExamples = ftestList "parsing examples" [ runSuccess "line entry" Parser.pEntry "- A" "- A" runSuccess "header" Parser.pHeader header () runSuccess "unreleased" Parser.pUnreleased emptyUnreleased None @@ -228,6 +258,7 @@ let parsingExamples = testList "parsing examples" [ runSuccess "release" Parser.pRelease singleRelease singleReleaseExpected runSuccess "sample 1 release" Parser.pRelease sample1Release sample1ReleaseExpected runSuccess "yanked release" Parser.pRelease yankedRelease yankedReleaseExpected + runSuccess "release with description" Parser.pRelease releaseWithDescription releaseWithDescriptionExpected runSuccess "header and unreleased and released" (Parser.pHeader >>. Parser.pUnreleased @@ -373,6 +404,7 @@ let FableSampleExpected :Changelogs = { Version = SemanticVersion.Parse "4.6.0" Date = DateTime(2023, 11, 27) IsYanked = false + Description = None Data = Some { ChangelogData.Default with Changed = @@ -430,12 +462,14 @@ let SectionLessSampleExpected: Changelogs = { Version = SemanticVersion.Parse "4.2.1" Date = DateTime(2023, 9, 29) IsYanked = false + Description = None Data = Some ChangelogData.Default } { Version = SemanticVersion.Parse "4.2.0" Date = DateTime(2023, 9, 29) IsYanked = false + Description = None Data = Some ChangelogData.Default } ]