Skip to content

Commit

Permalink
Allow release section to have a free-text descrption
Browse files Browse the repository at this point in the history
  • Loading branch information
MangelMaxime committed Dec 16, 2023
1 parent c667d4b commit fc35778
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 6 deletions.
8 changes: 8 additions & 0 deletions src/Ionide.KeepAChangelog.Tasks/Library.fs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ module Util =

item

let mapDescription (description: string) (item: ITaskItem) : ITaskItem =
item.SetMetadata("Description", description)
item

type ParseChangelogs() =
inherit Task()

Expand Down Expand Up @@ -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
Expand Down
32 changes: 27 additions & 5 deletions src/Ionide.KeepAChangelog/Library.fs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ module Domain =
{ Version: SemanticVersion
Date: DateTime
Data: ChangelogData option
Description: string option
IsYanked: bool }

type Changelogs =
Expand Down Expand Up @@ -233,18 +234,39 @@ 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<Release> =
let vPart = skipString "##" >>. spaces1 >>. pVersion
let middle = spaces1 .>> pchar '-' .>> spaces1
let date = pDate
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<Changelogs, unit> =
let unreleased =
Expand Down
36 changes: 35 additions & 1 deletion test/Ionide.KeepAChangelog.Test/Program.fs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ let singleReleaseExpected =
Removed = "- C\n"
}
IsYanked = false
Description = None
}

let keepAChangelog =
Expand Down Expand Up @@ -72,6 +73,7 @@ let keepAChangelogExpected: Changelogs =
Added = "- A\n- B\n- C\n\n"
}
IsYanked = false
Description = None
}
]
}
Expand Down Expand Up @@ -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]
Expand All @@ -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
Expand Down Expand Up @@ -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"
Expand All @@ -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
}

]
Expand Down Expand Up @@ -220,14 +250,15 @@ let runSuccessNormalized label (p: Parser<string,unit>) 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
runSuccess "header and unreleased" (Parser.pHeader >>. Parser.pUnreleased) headerAndUnreleased None
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
Expand Down Expand Up @@ -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 =
Expand Down Expand Up @@ -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
}
]
Expand Down

0 comments on commit fc35778

Please sign in to comment.