Skip to content

Commit

Permalink
Move from a tuple to a record representation for the release
Browse files Browse the repository at this point in the history
  • Loading branch information
MangelMaxime committed Dec 16, 2023
1 parent 0ec2b64 commit e2b7933
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 41 deletions.
12 changes: 6 additions & 6 deletions src/Ionide.KeepAChangelog.Tasks/Library.fs
Original file line number Diff line number Diff line change
Expand Up @@ -65,14 +65,14 @@ type ParseChangelogs() =
let sortedReleases =
// have to use LINQ here because List.sortBy* require IComparable, which
// semver doesn't implement
changelogs.Releases.OrderByDescending(fun (v, _, _) -> v)
changelogs.Releases.OrderByDescending(fun release -> release.Version)

let items =
sortedReleases
|> Seq.map (fun (version, date, data) ->
|> Seq.map (fun release ->
TaskItem()
|> Util.mapReleaseInfo version date
|> fun d -> match data with Some data -> Util.mapChangelogData data d | None -> d
|> Util.mapReleaseInfo release.Version release.Date
|> fun d -> match release.Data with Some data -> Util.mapChangelogData data d | None -> d
)
|> Seq.toArray

Expand All @@ -81,8 +81,8 @@ type ParseChangelogs() =

sortedReleases
|> Seq.tryHead
|> Option.iter (fun (version, date, data) ->
data
|> Option.iter (fun release ->
release.Data
|> Option.iter (fun data ->
this.LatestReleaseNotes <- data.ToMarkdown())
)
Expand Down
18 changes: 15 additions & 3 deletions src/Ionide.KeepAChangelog/Library.fs
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,16 @@ module Domain =
section heading lines
]

type Release =
{
Version : SemanticVersion
Date : DateTime
Data : ChangelogData option
}

type Changelogs =
{ Unreleased: ChangelogData option
Releases: (SemanticVersion * DateTime * ChangelogData option) list }
Releases: Release list }

module Parser =

Expand Down Expand Up @@ -241,13 +248,17 @@ module Parser =

let pVersion = mdUrl pSemver <|> pSemver

let pRelease: Parser<SemVersion.SemanticVersion * System.DateTime * ChangelogData option> =
let pRelease: Parser<Release> =
let vPart = skipString "##" >>. spaces1 >>. pVersion
let middle = spaces1 .>> pchar '-' .>> spaces1
let date = pDate .>> skipRestOfLine true
let content = choice [ pData; pNonStructuredData ]

pipe5 vPart middle date (opt (many newline)) (opt content) (fun v _ date _ data -> v, date, data)
pipe5 vPart middle date (opt (many newline)) (opt content) (fun v _ date _ data ->
{ Version = v
Date = date
Data = data }
)

let pChangeLogs: Parser<Changelogs, unit> =
let unreleased =
Expand Down Expand Up @@ -275,3 +286,4 @@ module Parser =
with
| ParserResult.Success (result, _, pos) -> Result.Ok result
| ParserResult.Failure (msg, structuredError, pos) -> Result.Error(msg, structuredError)

86 changes: 54 additions & 32 deletions test/Ionide.KeepAChangelog.Test/Program.fs
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,16 @@ let singleRelease =
"""

let singleReleaseExpected =
(SemanticVersion.Parse "1.0.0", DateTime(2017, 06, 20), Some {
{
Version = SemanticVersion.Parse "1.0.0"
Date = DateTime(2017, 06, 20)
Data = Some {
ChangelogData.Default with
Added = "- A\n"
Changed = "- B\n"
Removed = "- C\n"
})
}
}

let keepAChangelog =
normalizeNewline """# Changelog
Expand Down Expand Up @@ -59,11 +63,13 @@ let keepAChangelogExpected: Changelogs =
Unreleased = None
Releases = [
singleReleaseExpected
SemanticVersion.Parse("0.3.0"),
DateTime(2015, 12, 03),
Some {
ChangelogData.Default with
Added = "- A\n- B\n- C\n\n"
{
Version = SemanticVersion.Parse "0.3.0"
Date = DateTime(2015, 12, 03)
Data = Some {
ChangelogData.Default with
Added = "- A\n- B\n- C\n\n"
}
}
]
}
Expand Down Expand Up @@ -96,8 +102,12 @@ let sample1Release = normalizeNewline """## [0.3.1] - 8.1.2022
"""

let sample1ReleaseExpected =
SemanticVersion.Parse "0.3.1", DateTime(2022, 1, 8), Some { ChangelogData.Default with Added = "- Add XmlDocs to the generated package\n\n" }

{
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" }
}

let sample = normalizeNewline """# Changelog
All notable changes to this project will be documented in this file.
Expand Down Expand Up @@ -133,26 +143,32 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
let sampleExpected: Changelogs = {
Unreleased = None
Releases = [
SemanticVersion.Parse "0.3.1",
DateTime(2022, 1, 8),
Some { ChangelogData.Default with Added = "* Add XmlDocs to the generated package\n" }

SemanticVersion.Parse "0.3.0",
DateTime(2021, 11, 23),
Some {
{
Version = SemanticVersion.Parse "0.3.1"
Date = DateTime(2022, 1, 8)
Data = Some { ChangelogData.Default with Added = "* Add XmlDocs to the generated package\n" }
}
{
Version = SemanticVersion.Parse "0.3.0"
Date = DateTime(2021, 11, 23)
Data = Some {
ChangelogData.Default with
Added =
normalizeNewline
"""* Expose client `CodeAction` caps as CodeActionClientCapabilities. (by @razzmatazz)
* Map CodeAction.IsPreferred & CodeAction.Disabled props. (by @razzmatazz)
""" }
SemanticVersion.Parse "0.2.0",
DateTime(2021, 11, 17),
Some { ChangelogData.Default with Added = "* Add support for `codeAction/resolve` (by @razzmatazz)\n" }

SemanticVersion.Parse "0.1.1",
DateTime(2021, 11, 15),
Some { ChangelogData.Default with Added = "* Initial implementation\n" }
}
{
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" }
}
{
Version = SemanticVersion.Parse "0.1.1"
Date = DateTime(2021, 11, 15)
Data = Some { ChangelogData.Default with Added = "* Initial implementation\n" }
}
]
}

Expand Down Expand Up @@ -328,9 +344,10 @@ let FableSampleExpected :Changelogs = {
"""
}
Releases = [
SemanticVersion.Parse "4.6.0",
DateTime(2023, 11, 27),
Some {
{
Version = SemanticVersion.Parse "4.6.0"
Date = DateTime(2023, 11, 27)
Data = Some {
ChangelogData.Default with
Changed =
normalizeNewline """#### All
Expand Down Expand Up @@ -360,6 +377,7 @@ let FableSampleExpected :Changelogs = {
* PR #3608: Rewrite `time_span.py` allowing for better precision by using a number representation intead of native `timedelta`. (by @MangelMaxime)
"""
}
}
]
}

Expand All @@ -382,12 +400,16 @@ let SectionLessSample = normalizeNewlines """# Changelog
let SectionLessSampleExpected: Changelogs = {
Unreleased = None
Releases = [
SemanticVersion.Parse "4.2.1",
DateTime(2023, 9, 29),
Some ChangelogData.Default
SemanticVersion.Parse "4.2.0",
DateTime(2023, 9, 29),
Some ChangelogData.Default
{
Version = SemanticVersion.Parse "4.2.1"
Date = DateTime(2023, 9, 29)
Data = Some ChangelogData.Default
}
{
Version = SemanticVersion.Parse "4.2.0"
Date = DateTime(2023, 9, 29)
Data = Some ChangelogData.Default
}
]
}

Expand Down

0 comments on commit e2b7933

Please sign in to comment.