Skip to content

Commit

Permalink
feat: add generation of compare link + date of release for the vers…
Browse files Browse the repository at this point in the history
…ion + include `scope` if present
  • Loading branch information
MangelMaxime committed Nov 18, 2024
1 parent 36049d1 commit 181edc5
Show file tree
Hide file tree
Showing 14 changed files with 156 additions and 73 deletions.
62 changes: 1 addition & 61 deletions build/packages.lock.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"type": "Direct",
"requested": "[8.0.200, )",
"resolved": "8.0.200",
"contentHash": "qnxoF3Fu0HzfOeYdrwmQOsLP1v+OtOMSIYkNVUwf6nGqWzL03Hh4r6VFCvCb54jlsgtt3WADVYkKkrgdeY5kiQ=="
"contentHash": "U016Y0NhtIEQvbmxf6Sff9lx7PTSGEFctA/kLrJr9MvNfKwjrzlK/4C2V1StgsapegWeGYW6K8Zd/D6vc9C4Yw=="
},
"Semver": {
"type": "Direct",
Expand All @@ -44,70 +44,10 @@
"Spectre.Console": "0.49.0"
}
},
"EasyBuild.CommitParser": {
"type": "Transitive",
"resolved": "2.0.0",
"contentHash": "hplgmdQQOwnSnOIeR2HhlgHs3Jzz8XeoyZB3qnjfWJREqZX+5BIYrNorcDxiVluqu9FT9U1vinxz4gCHc7FarQ==",
"dependencies": {
"FSharp.Core": "7.0.300",
"FsToolkit.ErrorHandling": "4.18.0",
"Thoth.Json.Newtonsoft": "0.1.0"
}
},
"Fable.Core": {
"type": "Transitive",
"resolved": "4.1.0",
"contentHash": "NISAbAVGEcvH2s+vHLSOCzh98xMYx4aIadWacQdWPcQLploxpSQXLEe9SeszUBhbHa73KMiKREsH4/W3q4A4iA=="
},
"FsToolkit.ErrorHandling": {
"type": "Transitive",
"resolved": "4.18.0",
"contentHash": "cGtOP6lWcnLcXiLTGZLHi+8JAyuUDjGhZOmJWnZfd5aPCUIyL+DqUIwmfEGkUk3j/gpcchLDk9BNwUTc1oM30w==",
"dependencies": {
"FSharp.Core": "7.0.300"
}
},
"Newtonsoft.Json": {
"type": "Transitive",
"resolved": "13.0.1",
"contentHash": "ppPFpBcvxdsfUonNcvITKqLl3bqxWbDCZIzDWHzjpdAHRFfZe0Dw9HmA0+za13IdyrgJwpkDTDA9fHaxOrt20A=="
},
"Spectre.Console": {
"type": "Transitive",
"resolved": "0.49.0",
"contentHash": "1s+hhYq5fcrqCvZhrNOPehAmCZJM6cjro85g1Qirvmm1tys+/sfFJgePCGcxr+S/nONZ/lCDTflPda3C+WlBdg=="
},
"Thoth.Json.Core": {
"type": "Transitive",
"resolved": "0.1.0",
"contentHash": "hIo4bdnbG2BOmCrUTHhScgn0aTnlGPQtmO0KiCklSHduEQV3r7SjwscvjjcbfXyc0nuPV6UOg05KHMUgiIeXjQ==",
"dependencies": {
"FSharp.Core": "5.0.0",
"Fable.Core": "4.1.0"
}
},
"Thoth.Json.Newtonsoft": {
"type": "Transitive",
"resolved": "0.1.0",
"contentHash": "i64dDASv8UY8oPNwvcF7UTLvXYL2C3PaTeNQ8s8Woy/pNTKud616//+0V858wcS2PyunVnyQeuiND4bfvMujhQ==",
"dependencies": {
"FSharp.Core": "5.0.0",
"Fable.Core": "4.1.0",
"Newtonsoft.Json": "13.0.1",
"Thoth.Json.Core": "0.1.0"
}
},
"easybuild.changeloggen": {
"type": "Project",
"dependencies": {
"BlackFox.CommandLine": "[1.0.0, )",
"EasyBuild.CommitParser": "[2.0.0, )",
"FSharp.Core": "[8.0.101, )",
"FsToolkit.ErrorHandling": "[4.18.0, )",
"Semver": "[2.3.0, )",
"SimpleExec": "[12.0.0, )",
"Spectre.Console.Cli": "[0.49.0, )"
}
}
}
}
Expand Down
42 changes: 38 additions & 4 deletions src/Generate/Changelog.fs
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,8 @@ let private writeSection
writer.AppendLine $"### %s{label}"
writer.NewLine()

let commits = commits |> List.sortBy (fun commit -> commit.SemanticCommit.Scope)

for commit in commits do
let githubCommitUrl sha =
$"https://github.com/%s{githubRemote.Owner}/%s{githubRemote.Repository}/commit/%s{sha}"
Expand All @@ -148,7 +150,14 @@ let private writeSection

let description = capitalizeFirstLetter commit.SemanticCommit.Description

$"* %s{description} ([%s{commit.OriginalCommit.AbbrevHash}](%s{commitUrl}))"
[
"*"
match commit.SemanticCommit.Scope with
| Some scope -> $"*(%s{scope})*"
| None -> ()
$"%s{description.Trim()} ([%s{commit.OriginalCommit.AbbrevHash}](%s{commitUrl}))"
]
|> String.concat " "
|> writer.AppendLine

let additionalChangelogContent =
Expand All @@ -162,10 +171,22 @@ let private writeSection

writer.NewLine()

let generateNewVersionSection (githubRemote: GithubRemoteConfig) (releaseContext: BumpInfo) =
let generateNewVersionSection
(githubRemote: GithubRemoteConfig)
(previousReleasedSha: string option)
(releaseContext: BumpInfo)
=
let writer = Writer()

writer.AppendLine $"## %s{releaseContext.NewVersion.ToString()}"
[
"##"
$"%s{releaseContext.NewVersion.ToString()}"
"-"
DateTime.UtcNow.ToString("yyyy-MM-dd")
]
|> String.concat " "
|> writer.AppendLine

writer.NewLine()

let rec groupCommits (acc: GroupedCommits) (commits: CommitForRelease list) =
Expand Down Expand Up @@ -194,14 +215,27 @@ let generateNewVersionSection (githubRemote: GithubRemoteConfig) (releaseContext
writeSection writer "🚀 Features" githubRemote groupedCommits.Feats
writeSection writer "🐞 Bug Fixes" githubRemote groupedCommits.Fixes

match previousReleasedSha with
| Some sha ->
let compareUrl =
$"https://github.com/%s{githubRemote.Owner}/%s{githubRemote.Repository}/compare/%s{sha}..%s{releaseContext.LastCommitSha}"

$"<strong><small>[View changes on Github](%s{compareUrl})</small></strong>"
|> writer.AppendLine

writer.NewLine()

| None -> ()

writer.ToText()

let updateWithNewVersion
(githubRemote: GithubRemoteConfig)
(releaseContext: BumpInfo)
(changelogInfo: ChangelogInfo)
=
let newVersionLines = generateNewVersionSection githubRemote releaseContext
let newVersionLines =
generateNewVersionSection githubRemote changelogInfo.LastReleaseCommit releaseContext

let rec removeConsecutiveEmptyLines
(previousLineWasBlank: bool)
Expand Down
79 changes: 79 additions & 0 deletions tests/Changelog.fs
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@ let private generateNewVersionSectionTests =
Owner = "owner"
Repository = "repository"
}
(Some "fefd5e0bf242e034f86ad23a886e2d71ded4f7bb")
{
NewVersion = Semver.SemVersion(1, 0, 0)
CommitsForRelease =
Expand Down Expand Up @@ -206,6 +207,7 @@ let private generateNewVersionSectionTests =
Owner = "owner"
Repository = "repository"
}
(Some "fefd5e0bf242e034f86ad23a886e2d71ded4f7bb")
{
NewVersion = Semver.SemVersion(1, 0, 0)
CommitsForRelease =
Expand Down Expand Up @@ -234,6 +236,7 @@ let private generateNewVersionSectionTests =
Owner = "owner"
Repository = "repository"
}
(Some "fefd5e0bf242e034f86ad23a886e2d71ded4f7bb")
{
NewVersion = Semver.SemVersion(1, 0, 0)
CommitsForRelease =
Expand Down Expand Up @@ -272,6 +275,7 @@ let private generateNewVersionSectionTests =
Owner = "owner"
Repository = "repository"
}
(Some "fefd5e0bf242e034f86ad23a886e2d71ded4f7bb")
{
NewVersion = Semver.SemVersion(1, 0, 0)
CommitsForRelease =
Expand Down Expand Up @@ -310,6 +314,7 @@ let private generateNewVersionSectionTests =
Owner = "owner"
Repository = "repository"
}
(Some "fefd5e0bf242e034f86ad23a886e2d71ded4f7bb")
{
NewVersion = Semver.SemVersion(1, 0, 0)
CommitsForRelease =
Expand Down Expand Up @@ -348,6 +353,7 @@ let private generateNewVersionSectionTests =
Owner = "owner"
Repository = "repository"
}
(Some "fefd5e0bf242e034f86ad23a886e2d71ded4f7bb")
{
NewVersion = Semver.SemVersion(1, 0, 0)
CommitsForRelease =
Expand Down Expand Up @@ -381,6 +387,79 @@ This is a list of changes:
}
)
)

testMarkdown (
"compare link is not generated if no previous release sha is provided",
(fun _ ->
Changelog.generateNewVersionSection
{
Owner = "owner"
Repository = "repository"
}
None
{
NewVersion = Semver.SemVersion(1, 0, 0)
CommitsForRelease =
[
Git.Commit.Create(
"0b1899bb03d3eb86a30c84aa4c66c037527fbd14",
"feat: Add feature"
)
|> gitCommitToCommitForRelease
Git.Commit.Create(
"2a6f3b3403aaa629de6e65558448b37f126f8e86",
"feat: Add another feature"
)
|> gitCommitToCommitForRelease
]
LastCommitSha = "0b1899bb03d3eb86a30c84aa4c66c037527fbd14"
}
)
)

testMarkdown (
"commits are ordered by scope",
(fun _ ->
Changelog.generateNewVersionSection
{
Owner = "owner"
Repository = "repository"
}
None
{
NewVersion = Semver.SemVersion(1, 0, 0)
CommitsForRelease =
[
Git.Commit.Create(
"0b1899bb03d3eb86a30c84aa4c66c037527fbd14",
"feat(js): Add feature #2"
)
|> gitCommitToCommitForRelease
Git.Commit.Create(
"21033aae357447dbfac30557a2dee0c4b5b03f68",
"feat(js): Add feature #1"
)
|> gitCommitToCommitForRelease
Git.Commit.Create(
"be429a973ac2f6d1c009b7efcd15360c9e585450",
"feat(js): JavaScript is awesome"
)
|> gitCommitToCommitForRelease
Git.Commit.Create(
"2a6f3b3403aaa629de6e65558448b37f126f8e86",
"feat(rust): Rust is awesome"
)
|> gitCommitToCommitForRelease
Git.Commit.Create(
"2a6f3b3403aaa629de6e65558448b37f126f8e86",
"feat(all): All Fable targets are awesome"
)
|> gitCommitToCommitForRelease
]
LastCommitSha = "0b1899bb03d3eb86a30c84aa4c66c037527fbd14"
}
)
)
]

let private updateChangelogWithNewVersionTests =
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
## 1.0.0
## 1.0.0 - 2024-11-18

### 🏗️ Breaking changes

Expand All @@ -12,3 +12,5 @@
### 🐞 Bug Fixes

* Fix bug ([2a6f3b3](https://github.com/owner/repository/commit/2a6f3b3403aaa629de6e65558448b37f126f8e86))

<strong><small>[View changes on Github](https://github.com/owner/repository/compare/fefd5e0bf242e034f86ad23a886e2d71ded4f7bb..0b1899bb03d3eb86a30c84aa4c66c037527fbd14)</small></strong>
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
## 1.0.0
## 1.0.0 - 2024-11-18

### 🚀 Features

Expand All @@ -9,3 +9,5 @@

* Fix bug via breaking change ([9156258](https://github.com/owner/repository/commit/9156258d463ba78ac21ebb5fcd32147657bfe86f))
* Fix bug ([2a6f3b3](https://github.com/owner/repository/commit/2a6f3b3403aaa629de6e65558448b37f126f8e86))

<strong><small>[View changes on Github](https://github.com/owner/repository/compare/fefd5e0bf242e034f86ad23a886e2d71ded4f7bb..0b1899bb03d3eb86a30c84aa4c66c037527fbd14)</small></strong>
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
## 1.0.0 - 2024-11-18

### 🚀 Features

* *(all)* All Fable targets are awesome ([2a6f3b3](https://github.com/owner/repository/commit/2a6f3b3403aaa629de6e65558448b37f126f8e86))
* *(js)* JavaScript is awesome ([be429a9](https://github.com/owner/repository/commit/be429a973ac2f6d1c009b7efcd15360c9e585450))
* *(js)* Add feature #1 ([21033aa](https://github.com/owner/repository/commit/21033aae357447dbfac30557a2dee0c4b5b03f68))
* *(js)* Add feature #2 ([0b1899b](https://github.com/owner/repository/commit/0b1899bb03d3eb86a30c84aa4c66c037527fbd14))
* *(rust)* Rust is awesome ([2a6f3b3](https://github.com/owner/repository/commit/2a6f3b3403aaa629de6e65558448b37f126f8e86))
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
## 1.0.0 - 2024-11-18

### 🚀 Features

* Add another feature ([2a6f3b3](https://github.com/owner/repository/commit/2a6f3b3403aaa629de6e65558448b37f126f8e86))
* Add feature ([0b1899b](https://github.com/owner/repository/commit/0b1899bb03d3eb86a30c84aa4c66c037527fbd14))
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
## 1.0.0
## 1.0.0 - 2024-11-18

### 🚀 Features

Expand All @@ -16,3 +16,5 @@
### 🐞 Bug Fixes
* Fix bug ([2a6f3b3](https://github.com/owner/repository/commit/2a6f3b3403aaa629de6e65558448b37f126f8e86))
<strong><small>[View changes on Github](https://github.com/owner/repository/compare/fefd5e0bf242e034f86ad23a886e2d71ded4f7bb..0b1899bb03d3eb86a30c84aa4c66c037527fbd14)</small></strong>
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
## 1.0.0
## 1.0.0 - 2024-11-18

### 🚀 Features

Expand All @@ -7,3 +7,5 @@
### 🐞 Bug Fixes

* Fix bug ([2a6f3b3](https://github.com/owner/repository/commit/2a6f3b3403aaa629de6e65558448b37f126f8e86))

<strong><small>[View changes on Github](https://github.com/owner/repository/compare/fefd5e0bf242e034f86ad23a886e2d71ded4f7bb..0b1899bb03d3eb86a30c84aa4c66c037527fbd14)</small></strong>
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
## 1.0.0
## 1.0.0 - 2024-11-18

### 🚀 Features

* Add another feature ([2a6f3b3](https://github.com/owner/repository/commit/2a6f3b3403aaa629de6e65558448b37f126f8e86))
* Add feature ([0b1899b](https://github.com/owner/repository/commit/0b1899bb03d3eb86a30c84aa4c66c037527fbd14))

<strong><small>[View changes on Github](https://github.com/owner/repository/compare/fefd5e0bf242e034f86ad23a886e2d71ded4f7bb..0b1899bb03d3eb86a30c84aa4c66c037527fbd14)</small></strong>
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
## 1.0.0
## 1.0.0 - 2024-11-18

### 🐞 Bug Fixes

* Fix another bug ([2a6f3b3](https://github.com/owner/repository/commit/2a6f3b3403aaa629de6e65558448b37f126f8e86))
* Fix bug ([0b1899b](https://github.com/owner/repository/commit/0b1899bb03d3eb86a30c84aa4c66c037527fbd14))

<strong><small>[View changes on Github](https://github.com/owner/repository/compare/fefd5e0bf242e034f86ad23a886e2d71ded4f7bb..0b1899bb03d3eb86a30c84aa4c66c037527fbd14)</small></strong>
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ This changelog is generated using [EasyBuild.ChangelogGen](https://github.com/ea
<!-- last_commit_released: 0b1899bb03d3eb86a30c84aa4c66c037527fbd14 -->
<!-- EasyBuild: END -->

## 1.1.0
## 1.1.0 - 2024-11-18

### 🚀 Features

Expand All @@ -22,6 +22,8 @@ This changelog is generated using [EasyBuild.ChangelogGen](https://github.com/ea
* Fix another bug ([2a6f3b3](https://github.com/owner/repository/commit/2a6f3b3403aaa629de6e65558448b37f126f8e86))
* Fix bug ([0b1899b](https://github.com/owner/repository/commit/0b1899bb03d3eb86a30c84aa4c66c037527fbd14))

<strong><small>[View changes on Github](https://github.com/owner/repository/compare/fefd5e0bf242e034f86ad23a886e2d71ded4f7bb..0b1899bb03d3eb86a30c84aa4c66c037527fbd14)</small></strong>

## 1.0.0

### 🚀 Features
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ This changelog is generated using [EasyBuild.ChangelogGen](https://github.com/ea
<!-- last_commit_released: 0b1899bb03d3eb86a30c84aa4c66c037527fbd14 -->
<!-- EasyBuild: END -->

## 1.1.0
## 1.1.0 - 2024-11-18

### 🚀 Features

Expand Down
Loading

0 comments on commit 181edc5

Please sign in to comment.