Skip to content

Commit

Permalink
Merge pull request #9 from omaus/feature-preTag&Semver-#6
Browse files Browse the repository at this point in the history
Add match case for new prerelease command
  • Loading branch information
Freymaurer authored Oct 27, 2023
2 parents 1e8fe61 + a42fb84 commit 5171e50
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 10 deletions.
25 changes: 18 additions & 7 deletions src/Fake.Extensions.Release/ReleaseNotes.fs
Original file line number Diff line number Diff line change
Expand Up @@ -142,11 +142,11 @@ module ReleaseNotes =
let prevBugs = findCommitsByDescriptor Bugfixes addedDescriptors
prevAdditions, prevDeletions, prevBugs

let matchSemVerArg (args0: string list) =
let matchSemVerArg (args0 : string list) =
let args = args0 |> List.map (fun x -> x.ToLower().Trim())
let opt = args |> List.tryFind (fun x -> x.StartsWith "semver:")
match opt with
| Some "semver:major"->
let optSemVer = args |> List.tryFind (fun x -> x.StartsWith "semver:")
match optSemVer with
| Some "semver:major" ->
Trace.trace "Increase major for next release notes."
Major
| Some "semver:minor" ->
Expand All @@ -155,15 +155,19 @@ module ReleaseNotes =
| Some "semver:patch" ->
Trace.trace "Increase patch for next release notes."
Patch
| Some isPre when isPre.StartsWith "semver:pre-" ->
Pre <| isPre.Replace("semver:pre-", "")
| Some x ->
Trace.traceError (sprintf "Unrecognized argument: \"%s\". Default to \"semver:wip\"." x)
WIP
| None | Some "semver:wip" ->
Trace.trace "Add new commits to current release."
WIP

let matchPreArg (args0 : string list) =
let args = args0 |> List.map (fun x -> x.ToLower().Trim())
let opt = args |> List.tryFind (fun x -> x.StartsWith "pre:")
opt
|> Option.map (fun s -> Pre <| s.Replace("pre:", ""))

/// Takes an array of commit notes and filters out commits deemed unnecessary. These are: Commits about updates of the Release Notes file; Pull-Request Merge commits.
let filterOutUnimportantCommits commitNoteArr =
printfn "%A" commitNoteArr
Expand Down Expand Up @@ -244,9 +248,11 @@ module ReleaseNotes =
else
gitCommits


let writeNewReleaseNotes =

let semVer = matchSemVerArg config.Context.Arguments
let semVerPre = matchPreArg config.Context.Arguments
let commitNoteArr = newGitCommits |> Array.ofList |> Array.map (fun x -> x.Split([|";"|], StringSplitOptions.None))
let latestCommitHash =
// try pick latest from commit array
Expand All @@ -255,7 +261,12 @@ module ReleaseNotes =
elif lastCommitHash.IsSome then lastCommitHash.Value
// if all fails then empty
else ""
let newSemVer = updateSemVer semVer latestCommitHash lastReleaseNotes.SemVer
let newSemVer =
match semVer, semVerPre with
| _, None -> updateSemVer semVer latestCommitHash lastReleaseNotes.SemVer
| WIP, Some pre -> updateSemVer pre latestCommitHash lastReleaseNotes.SemVer
| _, Some pre -> updateSemVer semVer latestCommitHash lastReleaseNotes.SemVer
|> updateSemVer pre latestCommitHash
/// This will be used to directly create the release notes
let formattedCommitNoteList =
filterOutUnimportantCommits commitNoteArr
Expand Down
12 changes: 9 additions & 3 deletions tests/Fake.Extensions.Release.Tests/ReleaseNotes.Tests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,15 @@ let tests_SemVerArgs =
testCase "Test SemVerArg :patch" <| fun _ ->
let result = ["semver:patch"] |> matchSemVerArg
Expect.equal result Patch ""
testCase "Test SemVerArg :pre-alpha.02" <| fun _ ->
let result = ["semver:pre-alpha.02"] |> matchSemVerArg
Expect.equal result (Pre "alpha.02") ""
]

[<Tests>]
let tests_SemVerPreArgs =
testList "SemVerPreArgs" [
testCase "Test SemVerPreArg pre:alpha.02" <| fun _ ->
let result = ["pre:alpha.02"] |> matchPreArg
Expect.isSome result "Is not some"
Expect.equal result.Value (Pre "alpha.02") "Has incorrect SemVerPrerelease tag"
]

[<Tests>]
Expand Down

0 comments on commit 5171e50

Please sign in to comment.