Skip to content

Commit

Permalink
Add Date field to Fake.ReleaseNotesHelper.ReleaseNotes
Browse files Browse the repository at this point in the history
Added a parser to handle looking for dates in the header of
complex-formatted release notes.
  • Loading branch information
allykzam committed Aug 21, 2015
1 parent 56f47d2 commit 84ccf22
Showing 1 changed file with 18 additions and 3 deletions.
21 changes: 18 additions & 3 deletions src/app/FakeLib/ReleaseNotesHelper.fs
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,17 @@ type ReleaseNotes =
NugetVersion: string
/// Semantic version
SemVer: SemVerHelper.SemVerInfo
/// Release date
Date : DateTime option
// The parsed release notes.
Notes: string list }
override x.ToString() = sprintf "%A" x

static member New(assemblyVersion,nugetVersion,notes) = {
static member New(assemblyVersion,nugetVersion,date,notes) = {
AssemblyVersion = assemblyVersion
NugetVersion = nugetVersion
SemVer = SemVerHelper.parse nugetVersion
Date = date
Notes = notes }

let parseVersions =
Expand All @@ -71,6 +74,17 @@ let parseVersions =
then failwithf "Unable to parse valid NuGet version from release notes (%s)." line
assemblyVersion, nugetVersion

let parseDate =
let dateRegex = getRegEx @"(19|20)\d\d([- /.])(0[1-9]|1[012])\2(0[1-9]|[12][0-9]|3[01])"
fun line ->
let possibleDate = dateRegex.Match line
match possibleDate.Success with
| false -> None
| true ->
match DateTime.TryParse possibleDate.Value with
| false, _ -> None
| true, x -> Some(x)

/// Parse simple release notes sequence
let private parseSimpleReleaseNotes line =
let assemblyVersion, nugetVersion = parseVersions line
Expand All @@ -83,7 +97,7 @@ let private parseSimpleReleaseNotes line =
|> List.map (trimDot >> trim)
|> List.filter isNotNullOrEmpty
|> List.map (fun x -> x + ".")
ReleaseNotes.New(assemblyVersion.Value, nugetVersion.Value, notes)
ReleaseNotes.New(assemblyVersion.Value, nugetVersion.Value, None, notes)

/// Parse "complex" release notes text sequence
let private parseAllComplexReleaseNotes (text: seq<string>) =
Expand All @@ -102,7 +116,8 @@ let private parseAllComplexReleaseNotes (text: seq<string>) =
match findNextNotesBlock text with
| Some(header,(notes, rest)) ->
let assemblyVer, nugetVer = parseVersions header
let newReleaseNotes = ReleaseNotes.New(assemblyVer.Value,nugetVer.Value,notes |> List.filter isNotNullOrEmpty |> List.rev)
let date = parseDate header
let newReleaseNotes = ReleaseNotes.New(assemblyVer.Value,nugetVer.Value,date,notes |> List.filter isNotNullOrEmpty |> List.rev)
loop (newReleaseNotes::releaseNotes) rest
| None -> releaseNotes

Expand Down

0 comments on commit 84ccf22

Please sign in to comment.