Skip to content

Commit

Permalink
feat: release link
Browse files Browse the repository at this point in the history
generate a new release link when running cli for the configured
repository provider
  • Loading branch information
pedraal committed Aug 23, 2024
1 parent b3bdd31 commit dce4002
Show file tree
Hide file tree
Showing 3 changed files with 98 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/releam.gleam
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import gleam/io
import gleam/option.{None, Some}
import gleamsver as gs
import releam/changelog
import releam/commit
import releam/git
import releam/package_config
import releam/release
import releam/semver
import simplifile

Expand Down Expand Up @@ -45,4 +47,14 @@ pub fn main() {
let assert Ok(_) = simplifile.write("gleam.toml", new_config)

let assert Ok(_) = git.commit_release(new_tag)

let release_link =
release.generate_repository_provider_release_link(package, new_changelog)
case release_link {
Ok(rl) -> {
io.println("Click on the following link to create a new release")
io.println(rl)
}
_ -> Nil
}
}
30 changes: 30 additions & 0 deletions src/releam/release.gleam
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import gleam/uri
import releam/changelog.{type Changelog}
import releam/package_config.{type PackageConfig, Github, Repository}

pub fn generate_repository_provider_release_link(
package_config: PackageConfig,
new_changelog: Changelog,
) {
case package_config.repository {
Ok(Repository(provider, org, name)) -> {
case provider {
Github ->
Ok(
"https://github.com/"
<> org
<> "/"
<> name
<> "/releases/new?tag="
<> new_changelog.title
<> "&title="
<> new_changelog.title
<> "&body="
<> uri.percent_encode(changelog.render(new_changelog, False)),
)
_ -> Error(Nil)
}
}
_ -> Error(Nil)
}
}
56 changes: 56 additions & 0 deletions test/releam/release_test.gleam
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import gleam/option
import gleamsver as gs
import gleeunit
import gleeunit/should
import releam/changelog as cl
import releam/commit as c
import releam/conventional_attributes as ca
import releam/package_config as pc
import releam/release

pub fn main() {
gleeunit.main()
}

pub fn generate_repository_provider_release_link_test() {
let package_config =
pc.PackageConfig(
gs.SemVer(1, 0, 0, "", ""),
Ok(pc.Repository(pc.Github, "johndoe", "blog")),
)

let compare_url = "https://github.com/johndoe/blog/compare/v1.0.0...v1.1.0"

let changelog =
cl.Changelog("v1.1.0", Ok(compare_url), [
cl.Section(ca.Feat, [
gen_commit(ca.Feat, option.Some("posts"), "add index endpoint"),
]),
])

release.generate_repository_provider_release_link(package_config, changelog)
|> should.equal(Ok(
"https://github.com/johndoe/blog/releases/new?tag=v1.1.0&title=v1.1.0&body=%5Bcompare%20changes%5D(https%3A%2F%2Fgithub.com%2Fjohndoe%2Fblog%2Fcompare%2Fv1.0.0...v1.1.0)%0A%0A%23%23%23%20%F0%9F%9A%80%20Enhancements%0A%0A-%20**posts**%3A%20Add%20index%20endpoint",
))
}

fn gen_commit(
commit_type: ca.CommitType,
scope: option.Option(String),
description: String,
) {
c.Commit(
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
"aaaaaaa",
c.Author("johndoe", "[email protected]"),
"",
conventional_attributes: ca.ConventionalAttributes(
commit_type,
scope,
description,
[],
[],
False,
),
)
}

0 comments on commit dce4002

Please sign in to comment.