Skip to content

Commit

Permalink
Make minor improvements and cleanups
Browse files Browse the repository at this point in the history
  • Loading branch information
noritada committed Dec 15, 2022
1 parent 0c6fd4d commit fccc094
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 18 deletions.
14 changes: 7 additions & 7 deletions xtask/src/publish.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ impl flags::PublishReleaseNotes {
format!("\nSee also [original changelog]({original_changelog_url}).");
markdown.push_str(&additional_paragraph);
if self.dry_run {
println!("{}", markdown);
println!("{markdown}");
} else {
update_release(sh, &tag_name, &markdown)?;
update_release(sh, tag_name, &markdown)?;
}
Ok(())
}
Expand Down Expand Up @@ -67,7 +67,7 @@ fn update_release(sh: &Shell, tag_name: &str, release_notes: &str) -> Result<()>
Err(_) => bail!("Please obtain a personal access token from https://github.com/settings/tokens and set the `GITHUB_TOKEN` environment variable."),
};
let accept = "Accept: application/vnd.github+json";
let authorization = format!("Authorization: Bearer {}", token);
let authorization = format!("Authorization: Bearer {token}");
let api_version = "X-GitHub-Api-Version: 2022-11-28";
let release_url = "https://api.github.com/repos/rust-lang/rust-analyzer/releases";

Expand All @@ -80,10 +80,10 @@ fn update_release(sh: &Shell, tag_name: &str, release_notes: &str) -> Result<()>

let mut patch = String::new();
write_json::object(&mut patch)
.string("tag_name", &tag_name)
.string("tag_name", tag_name)
.string("target_commitish", "master")
.string("name", &tag_name)
.string("body", &release_notes)
.string("name", tag_name)
.string("body", release_notes)
.bool("draft", false)
.bool("prerelease", false);
let _ = cmd!(
Expand All @@ -102,7 +102,7 @@ mod tests {
#[test]
fn original_changelog_url_creation() {
let input = "2019-07-24-changelog-0.adoc";
let actual = create_original_changelog_url(&input);
let actual = create_original_changelog_url(input);
let expected = "https://rust-analyzer.github.io/thisweek/2019/07/24/changelog-0.html";
assert_eq!(actual, expected);
}
Expand Down
21 changes: 10 additions & 11 deletions xtask/src/publish/notes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ use std::{
iter::Peekable,
};

const LISTING_DELIMITER: &'static str = "----";
const IMAGE_BLOCK_PREFIX: &'static str = "image::";
const VIDEO_BLOCK_PREFIX: &'static str = "video::";
const LISTING_DELIMITER: &str = "----";
const IMAGE_BLOCK_PREFIX: &str = "image::";
const VIDEO_BLOCK_PREFIX: &str = "video::";

struct Converter<'a, 'b, R: BufRead> {
iter: &'a mut Peekable<Lines<R>>,
Expand Down Expand Up @@ -89,7 +89,7 @@ impl<'a, 'b, R: BufRead> Converter<'a, 'b, R> {
while let Some(line) = self.iter.peek() {
let line = line.as_deref().map_err(|e| anyhow!("{e}"))?;

if get_list_item(&line).is_some() {
if get_list_item(line).is_some() {
let line = self.iter.next().unwrap()?;
let line = process_inline_macros(&line)?;
let (marker, item) = get_list_item(&line).unwrap();
Expand Down Expand Up @@ -253,17 +253,16 @@ impl<'a, 'b, R: BufRead> Converter<'a, 'b, R> {
{
while let Some(line) = self.iter.peek() {
let line = line.as_deref().map_err(|e| anyhow!("{e}"))?;
if predicate(&line) {
if predicate(line) {
break;
}

self.write_indent(level);
let line = self.iter.next().unwrap()?;
let line = line.trim_start();
let line = process_inline_macros(&line)?;
if line.ends_with('+') {
let line = &line[..(line.len() - 1)];
self.output.push_str(line);
let line = process_inline_macros(line)?;
if let Some(stripped) = line.strip_suffix('+') {
self.output.push_str(stripped);
self.output.push('\\');
} else {
self.output.push_str(&line);
Expand Down Expand Up @@ -339,8 +338,8 @@ fn get_title(line: &str) -> Option<(usize, &str)> {
}

fn get_list_item(line: &str) -> Option<(ListMarker, &str)> {
const HYPHYEN_MARKER: &'static str = "- ";
if let Some(text) = line.strip_prefix(HYPHYEN_MARKER) {
const HYPHEN_MARKER: &str = "- ";
if let Some(text) = line.strip_prefix(HYPHEN_MARKER) {
Some((ListMarker::Hyphen, text))
} else if let Some((count, text)) = strip_prefix_symbol(line, '*') {
Some((ListMarker::Asterisk(count), text))
Expand Down

0 comments on commit fccc094

Please sign in to comment.