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

Allow subsections and section less items #22

Merged
merged 8 commits into from
Dec 5, 2023
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Support subsections.
nojaf committed Dec 3, 2023
commit f3a2ae08cc23186c1d28c6127837c79515dde9d0
35 changes: 31 additions & 4 deletions src/Ionide.KeepAChangelog/Library.fs
Original file line number Diff line number Diff line change
@@ -7,11 +7,11 @@ module Domain =
type Section =
{
Items: string list
SubSection: Map<string, string list>
SubSections: Map<string, string list>
}
static member Default = {
Items = List.empty
SubSection = Map.empty
SubSections = Map.empty
}

// TODO: a changelog entry may have a description?
@@ -141,8 +141,35 @@ module Parser =
pipe2 bullet content (fun bullet text -> $"{bullet} {text}")

let pEntriesInASection sectionName =
(many pEntry <?> $"{sectionName} entries")
|>> (fun entries -> { Items = entries; SubSection = Map.empty })
let pSubSection: Parser<string * string list> =
let sectionName =
skipString "####"
>>. spaces1
>>. restOfLine true

sectionName
.>> many1 newline
.>>. many pEntry

let pEntryOrSubSectionOrNewline =
choice [
pSubSection |>> Choice2Of3
pEntry |>> Choice1Of3
newline |>> Choice3Of3
]

(many pEntryOrSubSectionOrNewline <?> $"{sectionName} entries")
|>> (fun entries ->
(entries, Section.Default)
||> List.foldBack(fun entry section ->
match entry with
// Ignore blank line
| Choice3Of3 _ -> section
| Choice1Of3 item -> { section with Items = item :: section.Items }
| Choice2Of3 (subSectionName, subSectionItems) ->
{ section with SubSections = Map.add subSectionName subSectionItems section.SubSections }
)
)

let pCustomSection: Parser<string * Section> =
let sectionName =
62 changes: 59 additions & 3 deletions test/Ionide.KeepAChangelog.Test/Program.fs
Original file line number Diff line number Diff line change
@@ -284,8 +284,64 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
"""

let FableSampleExpected :Changelogs = {
Unreleased = None
Releases = []
Unreleased = Some {
ChangelogData.Default with
Fixed = {
Items = []
SubSections = [
"Python", [
"* Fix #3617: Fix comparaison between list option when one is None"
"* Fix #3615: Fix remove from dictionary with tuple as key"
"* Fix #3598: Using obj () now generated an empty dict instead of None"
"* Fix #3597: Do not translate .toString methods to str"
"* Fix #3610: Cleanup Python regex handling"
"* Fix #3628: System.DateTime.Substract not correctly transpiled"
]
]
|> Map.ofList
}
}
Releases = [
SemanticVersion.Parse "4.6.0",
DateTime(2023, 11, 27),
Some {
ChangelogData.Default with
Changed = {
Section.Default with
SubSections =[
"All", [
"* Updated .NET metadata to 8.0.100 (by @ncave)"
]
] |> Map.ofList
}
Added = {
Section.Default with
SubSections = [
"All", [
"* Fix #3584: Unit type compiles to undeclared variable (by @ncave)"
]
"Python", [
"* Support `DateTime(..., DateTimeKind.Utc).ToString(\"O\")` (by @MangelMaxime)"
]
"Rust", [
"* Added `Guid.TryParse`, `Guid.ToByteArray` (by @ncave)"
]
] |> Map.ofList
}
Fixed = {
Section.Default with
SubSections = [
"Python", [
"* Fixed char to string type regression with binary operator (by @dbrattli)"
"* Fix `DateTime(..., DateTimeKind.Local).ToString(\"O\")` (by @MangelMaxime)"
"* Fix calling `value.ToString(CultureInfo.InvariantCulture)` (by @MangelMaxime)"
"* Fix #3605: Fix record equality comparison to works with optional fields (by @MangelMaxime and @dbrattli)"
"* PR #3608: Rewrite `time_span.py` allowing for better precision by using a number representation intead of native `timedelta`. (by @MangelMaxime)"
]
] |> Map.ofList
}
}
]
}

let subSectionTests = testList "subsections" [
@@ -300,4 +356,4 @@ let tests = testList "All" [

[<EntryPoint>]
let main argv =
runTestsWithCLIArgs Seq.empty argv subSectionTests // tests
runTestsWithCLIArgs Seq.empty argv tests