Skip to content

Commit 87d3faf

Browse files
Merge pull request #811 from pietroalbini/github-releases
Synchronize GitHub Releases with the in-repo changelog
2 parents 92071ff + 92d931f commit 87d3faf

File tree

10 files changed

+575
-4
lines changed

10 files changed

+575
-4
lines changed

Cargo.lock

Lines changed: 111 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ postgres-native-tls = "0.3"
3434
native-tls = "0.2"
3535
serde_path_to_error = "0.1.2"
3636
octocrab = "0.5"
37+
comrak = "0.8.2"
3738

3839
[dependencies.serde]
3940
version = "1"

src/changelogs/mod.rs

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
mod rustc;
2+
3+
use comrak::{nodes::AstNode, Arena, ComrakOptions, ComrakRenderOptions};
4+
use std::collections::HashMap;
5+
6+
#[derive(Copy, Clone, PartialEq, Eq, Debug, serde::Deserialize)]
7+
#[serde(rename_all = "kebab-case")]
8+
pub(crate) enum ChangelogFormat {
9+
Rustc,
10+
}
11+
12+
pub(crate) struct Changelog {
13+
versions: HashMap<String, String>,
14+
}
15+
16+
impl Changelog {
17+
pub(crate) fn parse(format: ChangelogFormat, content: &str) -> anyhow::Result<Self> {
18+
match format {
19+
ChangelogFormat::Rustc => rustc::RustcFormat::new(&Arena::new()).parse(content),
20+
}
21+
}
22+
23+
pub(crate) fn version(&self, version: &str) -> Option<&str> {
24+
self.versions.get(version).map(|s| s.as_str())
25+
}
26+
}
27+
28+
fn render_for_github_releases<'a>(document: &'a AstNode<'a>) -> anyhow::Result<String> {
29+
let mut content = Vec::new();
30+
comrak::format_commonmark(
31+
document,
32+
&ComrakOptions {
33+
render: ComrakRenderOptions {
34+
// Prevent column width line breaks from appearing in the generated release
35+
// notes. GitHub Releases insert <br>s for every line break in the markdown,
36+
// mangling the output.
37+
width: std::usize::MAX,
38+
39+
..ComrakRenderOptions::default()
40+
},
41+
..ComrakOptions::default()
42+
},
43+
&mut content,
44+
)?;
45+
Ok(String::from_utf8(content)?)
46+
}

0 commit comments

Comments
 (0)