Skip to content

Commit

Permalink
Add [YANKED] tag support
Browse files Browse the repository at this point in the history
  • Loading branch information
MangelMaxime committed Dec 16, 2023
1 parent e2b7933 commit 4e72d71
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 5 deletions.
16 changes: 12 additions & 4 deletions src/Ionide.KeepAChangelog/Library.fs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ module Domain =
Version : SemanticVersion
Date : DateTime
Data : ChangelogData option
IsYanked : bool
}

type Changelogs =
Expand Down Expand Up @@ -244,20 +245,27 @@ module Parser =
pipe5 pDay dot pMonth dot pYear (fun d _ m _ y -> System.DateTime(y, m, d))

attempt dmyDots <|> ymdDashes


let pYanked: Parser<_> =
opt (pstring "[YANKED]")
|>> function
| None -> false
| Some _ -> true

let pVersion = mdUrl pSemver <|> pSemver

let pRelease: Parser<Release> =
let vPart = skipString "##" >>. spaces1 >>. pVersion
let middle = spaces1 .>> pchar '-' .>> spaces1
let date = pDate .>> skipRestOfLine true
let date = pDate
let yanked = opt spaces1 >>. pYanked
let content = choice [ pData; pNonStructuredData ]

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

let pChangeLogs: Parser<Changelogs, unit> =
Expand Down
29 changes: 28 additions & 1 deletion test/Ionide.KeepAChangelog.Test/Program.fs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ let singleReleaseExpected =
Changed = "- B\n"
Removed = "- C\n"
}
IsYanked = false
}

let keepAChangelog =
Expand Down Expand Up @@ -70,6 +71,7 @@ let keepAChangelogExpected: Changelogs =
ChangelogData.Default with
Added = "- A\n- B\n- C\n\n"
}
IsYanked = false
}
]
}
Expand Down Expand Up @@ -106,8 +108,25 @@ let sample1ReleaseExpected =
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
}


let yankedRelease = normalizeNewline """## [0.3.1] - 8.1.2022 [YANKED]
### Added
- Add XmlDocs to the generated package
"""

let yankedReleaseExpected =
{
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 = true
}

let sample = normalizeNewline """# Changelog
All notable changes to this project will be documented in this file.
Expand Down Expand Up @@ -147,6 +166,7 @@ let sampleExpected: Changelogs = {
Version = SemanticVersion.Parse "0.3.1"
Date = DateTime(2022, 1, 8)
Data = Some { ChangelogData.Default with Added = "* Add XmlDocs to the generated package\n" }
IsYanked = false
}
{
Version = SemanticVersion.Parse "0.3.0"
Expand All @@ -158,16 +178,19 @@ let sampleExpected: Changelogs = {
"""* Expose client `CodeAction` caps as CodeActionClientCapabilities. (by @razzmatazz)
* Map CodeAction.IsPreferred & CodeAction.Disabled props. (by @razzmatazz)
""" }
IsYanked = false
}
{
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
}
{
Version = SemanticVersion.Parse "0.1.1"
Date = DateTime(2021, 11, 15)
Data = Some { ChangelogData.Default with Added = "* Initial implementation\n" }
IsYanked = false
}
]
}
Expand Down Expand Up @@ -203,6 +226,7 @@ let parsingExamples = testList "parsing examples" [
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
"header and unreleased and released"
(Parser.pHeader >>. Parser.pUnreleased
Expand Down Expand Up @@ -347,6 +371,7 @@ let FableSampleExpected :Changelogs = {
{
Version = SemanticVersion.Parse "4.6.0"
Date = DateTime(2023, 11, 27)
IsYanked = false
Data = Some {
ChangelogData.Default with
Changed =
Expand Down Expand Up @@ -404,11 +429,13 @@ let SectionLessSampleExpected: Changelogs = {
Version = SemanticVersion.Parse "4.2.1"
Date = DateTime(2023, 9, 29)
Data = Some ChangelogData.Default
IsYanked = false
}
{
Version = SemanticVersion.Parse "4.2.0"
Date = DateTime(2023, 9, 29)
Data = Some ChangelogData.Default
IsYanked = false
}
]
}
Expand Down

0 comments on commit 4e72d71

Please sign in to comment.