Skip to content

Commit

Permalink
Merge pull request #917 from amazingant/master
Browse files Browse the repository at this point in the history
Add date to ReleaseNotes type definition
  • Loading branch information
forki committed Aug 24, 2015
2 parents 290622e + 92f0de8 commit 68f42b7
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 10 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]|[1-9])\2(0[1-9]|[12][0-9]|3[01]|[1-9])"
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
22 changes: 15 additions & 7 deletions src/test/Test.FAKECore/ReleaseNotesSpecs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ public class when_parsing_release_notes

static readonly ReleaseNotesHelper.ReleaseNotes expected = ReleaseNotesHelper.ReleaseNotes.New("1.1.10",
"1.1.10",
new Microsoft.FSharp.Core.FSharpOption<DateTime>(new DateTime(2013, 09, 12)),
new[]
{
"Support for heterogeneous XML attributes.",
Expand All @@ -52,20 +53,20 @@ public class when_parsing_release_notes

It should_parse_empty_notes =
() => ReleaseNotesHelper.parseReleaseNotes(Notes.FromString(@"### New in 1.1.10 (Released 2013/09/12)"))
.ShouldEqual(ReleaseNotesHelper.ReleaseNotes.New("1.1.10", "1.1.10", FSharpList<string>.Empty));
.ShouldEqual(ReleaseNotesHelper.ReleaseNotes.New("1.1.10", "1.1.10", new Microsoft.FSharp.Core.FSharpOption<DateTime>(new DateTime(2013, 09, 12)), FSharpList<string>.Empty));

It should_parse_simple_format =
() => ReleaseNotesHelper.parseReleaseNotes(Notes.FromString(@"
* 1.1.9 - Infer booleans for ints that only manifest 0 and 1. Support for partially overriding the Schema in CsvProvider.
* 1.1.10 - Support for heterogeneous XML attributes. Make CsvFile re-entrant."))
.ShouldEqual(ReleaseNotesHelper.ReleaseNotes.New("1.1.10", "1.1.10",
.ShouldEqual(ReleaseNotesHelper.ReleaseNotes.New("1.1.10", "1.1.10", null,
new[] {"Support for heterogeneous XML attributes.", "Make CsvFile re-entrant."}.ToFSharpList()));


It should_parse_simple_format_with_dots =
() => ReleaseNotesHelper.parseReleaseNotes(Notes.FromString(@"
* 1.2.0 - Allow currency symbols on decimals. Remove .AsTuple member from CsvProvider. CsvProvider now uses GetSample instead of constructor like the other providers."))
.ShouldEqual(ReleaseNotesHelper.ReleaseNotes.New("1.2.0", "1.2.0",
.ShouldEqual(ReleaseNotesHelper.ReleaseNotes.New("1.2.0", "1.2.0", null,
new[]
{
"Allow currency symbols on decimals.", "Remove .AsTuple member from CsvProvider.",
Expand Down Expand Up @@ -98,7 +99,7 @@ public class when_parsing_many_alpha_versions
#### 2.0.0-alpha001 - December 15 2013
* A";
static readonly ReleaseNotesHelper.ReleaseNotes expected =
ReleaseNotesHelper.ReleaseNotes.New("2.0.0", "2.0.0-alpha2", new[] { "B" }.ToFSharpList());
ReleaseNotesHelper.ReleaseNotes.New("2.0.0", "2.0.0-alpha2", null, new[] { "B" }.ToFSharpList());

It should_parse =
() => ReleaseNotesHelper.parseReleaseNotes(Notes.FromString(input)).ShouldEqual(expected);
Expand Down Expand Up @@ -131,7 +132,7 @@ public class when_parsing_many_pre_release_versions
#### 2.0.0-alpha001 - December 15 2013
* A";
static readonly ReleaseNotesHelper.ReleaseNotes expected =
ReleaseNotesHelper.ReleaseNotes.New("2.0.0", "2.0.0-rc007", new[] { "A" }.ToFSharpList());
ReleaseNotesHelper.ReleaseNotes.New("2.0.0", "2.0.0-rc007", null, new[] { "A" }.ToFSharpList());

It should_parse =
() => ReleaseNotesHelper.parseReleaseNotes(Notes.FromString(input)).ShouldEqual(expected);
Expand Down Expand Up @@ -159,6 +160,7 @@ public class when_parsing_release_notes_in_reverse_order

static readonly ReleaseNotesHelper.ReleaseNotes expected = ReleaseNotesHelper.ReleaseNotes.New("1.1.10",
"1.1.10",
new Microsoft.FSharp.Core.FSharpOption<DateTime>(new DateTime(2013, 09, 12)),
new[]
{
"Support for heterogeneous XML attributes.",
Expand All @@ -174,13 +176,13 @@ public class when_parsing_release_notes_in_reverse_order

It should_parse_empty_notes =
() => ReleaseNotesHelper.parseReleaseNotes(Notes.FromString(@"### New in 1.1.10 (Released 2013/09/12)"))
.ShouldEqual(ReleaseNotesHelper.ReleaseNotes.New("1.1.10", "1.1.10", FSharpList<string>.Empty));
.ShouldEqual(ReleaseNotesHelper.ReleaseNotes.New("1.1.10", "1.1.10", new Microsoft.FSharp.Core.FSharpOption<DateTime>(new DateTime(2013, 09, 12)), FSharpList<string>.Empty));

It should_parse_simple_format =
() => ReleaseNotesHelper.parseReleaseNotes(Notes.FromString(@"
* 1.1.10 - Support for heterogeneous XML attributes. Make CsvFile re-entrant.
* 1.0.9 - Infer booleans for ints that only manifest 0 and 1. Support for partially overriding the Schema in CsvProvider."))
.ShouldEqual(ReleaseNotesHelper.ReleaseNotes.New("1.1.10", "1.1.10",
.ShouldEqual(ReleaseNotesHelper.ReleaseNotes.New("1.1.10", "1.1.10", null,
new[] {"Support for heterogeneous XML attributes.", "Make CsvFile re-entrant."}.ToFSharpList()));

It should_throws_on_empty_seq_input =
Expand Down Expand Up @@ -215,6 +217,7 @@ public class when_parsing_all_release_notes

static readonly ReleaseNotesHelper.ReleaseNotes expected = ReleaseNotesHelper.ReleaseNotes.New("1.1.10",
"1.1.10",
new Microsoft.FSharp.Core.FSharpOption<DateTime>(new DateTime(2013, 09, 12)),
new[]
{
"Support for heterogeneous XML attributes.",
Expand All @@ -226,6 +229,7 @@ public class when_parsing_all_release_notes
.ToFSharpList());

static readonly ReleaseNotesHelper.ReleaseNotes expected2 = ReleaseNotesHelper.ReleaseNotes.New("1.1.9", "1.1.9",
new Microsoft.FSharp.Core.FSharpOption<DateTime>(new DateTime(2013, 07, 21)),
new[] {"Infer booleans for ints that only manifest 0 and 1."}
.ToFSharpList());

Expand All @@ -249,6 +253,7 @@ public class when_parsing_octokit_release_notes


static readonly ReleaseNotesHelper.ReleaseNotes expected = ReleaseNotesHelper.ReleaseNotes.New("0.1.3", "0.1.3",
new Microsoft.FSharp.Core.FSharpOption<DateTime>(new DateTime(2013, 11, 5)),
new[]
{
"New Xamarin Component store versions of Octokit.net",
Expand All @@ -275,6 +280,7 @@ public class when_parsing_machine_release_notes


static readonly ReleaseNotesHelper.ReleaseNotes expected = ReleaseNotesHelper.ReleaseNotes.New("1.8.0", "1.8.0",
null,
new[]
{
"When the subject's constructor throws an exception, it is now bubbled up and shown in the failure message.",
Expand Down Expand Up @@ -303,6 +309,7 @@ public class when_parsing_semver_release_notes
static readonly ReleaseNotesHelper.ReleaseNotes expected =
ReleaseNotesHelper.ReleaseNotes.New("1.0.0",
"1.0.0-rc.1",
new Microsoft.FSharp.Core.FSharpOption<DateTime>(new DateTime(2013, 10, 30)),
new[]
{
"Initial release"
Expand All @@ -312,6 +319,7 @@ public class when_parsing_semver_release_notes
static readonly ReleaseNotesHelper.ReleaseNotes expected2 =
ReleaseNotesHelper.ReleaseNotes.New("1.0.0",
"1.0.0-beta.2",
null,
new[]
{
"Fixed problems with Microsoft.Threading.Tasks"
Expand Down

0 comments on commit 68f42b7

Please sign in to comment.