-
Notifications
You must be signed in to change notification settings - Fork 89
Synchronize GitHub Releases with the in-repo changelog #811
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Mark-Simulacrum
merged 5 commits into
rust-lang:master
from
pietroalbini:github-releases
Sep 7, 2020
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
5299997
changelogs: add support for parsing rustc changelogs
pietroalbini 7c7260d
add support for the push and create events
pietroalbini d7710c5
make event time optional
pietroalbini c5f9dae
implement synchronization for github releases
pietroalbini 92d931f
changelogs: avoid line breaks in the github release output
pietroalbini File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
mod rustc; | ||
|
||
use comrak::{nodes::AstNode, Arena, ComrakOptions, ComrakRenderOptions}; | ||
use std::collections::HashMap; | ||
|
||
#[derive(Copy, Clone, PartialEq, Eq, Debug, serde::Deserialize)] | ||
#[serde(rename_all = "kebab-case")] | ||
pub(crate) enum ChangelogFormat { | ||
Rustc, | ||
} | ||
|
||
pub(crate) struct Changelog { | ||
versions: HashMap<String, String>, | ||
} | ||
|
||
impl Changelog { | ||
pub(crate) fn parse(format: ChangelogFormat, content: &str) -> anyhow::Result<Self> { | ||
match format { | ||
ChangelogFormat::Rustc => rustc::RustcFormat::new(&Arena::new()).parse(content), | ||
} | ||
} | ||
|
||
pub(crate) fn version(&self, version: &str) -> Option<&str> { | ||
self.versions.get(version).map(|s| s.as_str()) | ||
} | ||
} | ||
|
||
fn render_for_github_releases<'a>(document: &'a AstNode<'a>) -> anyhow::Result<String> { | ||
let mut content = Vec::new(); | ||
comrak::format_commonmark( | ||
document, | ||
&ComrakOptions { | ||
render: ComrakRenderOptions { | ||
// Prevent column width line breaks from appearing in the generated release | ||
// notes. GitHub Releases insert <br>s for every line break in the markdown, | ||
// mangling the output. | ||
width: std::usize::MAX, | ||
|
||
..ComrakRenderOptions::default() | ||
}, | ||
..ComrakOptions::default() | ||
}, | ||
&mut content, | ||
)?; | ||
Ok(String::from_utf8(content)?) | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.