From 92748f9fd4e6e65c25e82f2a6e41a0b9b82cf4dd Mon Sep 17 00:00:00 2001 From: Casey Rodarmor Date: Tue, 7 Apr 2020 20:17:03 -0700 Subject: [PATCH] Make changelog generator strict Make the changelog generator fail if commits don't contain metadata. type: changed pr: https://github.com/casey/intermodal/pull/341 --- CHANGELOG.md | 3 ++- bin/changelog/src/common.rs | 2 +- bin/changelog/src/entry.rs | 2 +- bin/changelog/src/main.rs | 4 ---- bin/changelog/src/metadata.rs | 40 +++++++++++++++++------------------ justfile | 12 ++++++++--- 6 files changed, 32 insertions(+), 31 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2aa64067..9428e5df 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,7 +4,8 @@ Changelog UNRELEASED - 2020-04-08 ----------------------- -- :wrench: [`xxxxxxxxxxxx`](https://github.com/casey/intermodal/commits/master) Generate changelog from git history ([#337](https://github.com/casey/intermodal/pull/337)) - Fixes [#336](https://github.com/casey/intermodal/issues/336) - _Casey Rodarmor _ +- :zap: [`xxxxxxxxxxxx`](https://github.com/casey/intermodal/commits/master) Make changelog generator strict ([#341](https://github.com/casey/intermodal/pull/341)) - _Casey Rodarmor _ +- :wrench: [`c33446b48135`](https://github.com/casey/intermodal/commit/c33446b481351009fc16335cbcd66ff2c2b7985e) Generate changelog from git history ([#337](https://github.com/casey/intermodal/pull/337)) - Fixes [#336](https://github.com/casey/intermodal/issues/336) - _Casey Rodarmor _ - :art: [`6edab1fa3fa8`](https://github.com/casey/intermodal/commit/6edab1fa3fa8461ac4ca02466a04b0f14e42dfc0) Use `TestEnv::assert_ok` everywhere - Fixes [#330](https://github.com/casey/intermodal/issues/330) - _Casey Rodarmor _ - :zap: [`8e3f5516aff8`](https://github.com/casey/intermodal/commit/8e3f5516aff8c89289203a2bc1b46505410c5f1f) Use attractive paths in user-facing messages - Fixes [#252](https://github.com/casey/intermodal/issues/252), [#332](https://github.com/casey/intermodal/issues/332) - _Casey Rodarmor _ - :bug: [`1cfc0214536c`](https://github.com/casey/intermodal/commit/1cfc0214536c607fff7c29d9e878cbcd7f3a9ffc) Forbid empty input, output, and path targets - _Casey Rodarmor _ diff --git a/bin/changelog/src/common.rs b/bin/changelog/src/common.rs index 7aa93a12..f9cd3ce4 100644 --- a/bin/changelog/src/common.rs +++ b/bin/changelog/src/common.rs @@ -5,7 +5,7 @@ pub(crate) use std::{ fs, str, }; -pub(crate) use anyhow::Error; +pub(crate) use anyhow::{anyhow, Error}; pub(crate) use cargo_toml::Manifest; pub(crate) use chrono::{DateTime, NaiveDateTime, Utc}; pub(crate) use fehler::throws; diff --git a/bin/changelog/src/entry.rs b/bin/changelog/src/entry.rs index 87251594..bc4906f6 100644 --- a/bin/changelog/src/entry.rs +++ b/bin/changelog/src/entry.rs @@ -18,7 +18,7 @@ impl Entry { Utc, ); - let metadata = Metadata::from_commit(commit).unwrap_or_default(); + let metadata = Metadata::from_commit(commit)?; Entry { version: version.into(), diff --git a/bin/changelog/src/main.rs b/bin/changelog/src/main.rs index c4561a50..a88b819c 100644 --- a/bin/changelog/src/main.rs +++ b/bin/changelog/src/main.rs @@ -1,7 +1,3 @@ -// TODO: -// - parse URL in fixed: -// - figure out how to check labels before merge - use crate::common::*; mod changelog; diff --git a/bin/changelog/src/metadata.rs b/bin/changelog/src/metadata.rs index c2df7fe2..57e7714b 100644 --- a/bin/changelog/src/metadata.rs +++ b/bin/changelog/src/metadata.rs @@ -2,8 +2,8 @@ use crate::common::*; #[derive(Deserialize, Serialize)] pub(crate) struct Metadata { - #[serde(default, rename = "type")] - pub(crate) kind: Option, + #[serde(rename = "type")] + pub(crate) kind: Kind, #[serde(default)] pub(crate) pr: Option, #[serde(default)] @@ -11,37 +11,35 @@ pub(crate) struct Metadata { } impl Metadata { - #[throws(as Option)] + #[throws] pub(crate) fn from_commit(commit: &Commit) -> Metadata { const BLANK: &str = "\n\n"; let message = String::from_utf8_lossy(commit.message_bytes()); - let blank = message.rfind(BLANK)?; + let blank = message + .rfind(BLANK) + .ok_or_else(|| anyhow!("Commit message missing metadata: {}", message))?; let yaml = &message[blank + BLANK.len()..]; - let metadata = serde_yaml::from_str(yaml).ok()?; + let metadata = serde_yaml::from_str(yaml)?; metadata } pub(crate) fn emoji(&self) -> &'static str { - if let Some(kind) = self.kind { - match kind { - Kind::Added => ":sparkles:", - Kind::Breaking => ":boom:", - Kind::Changed => ":zap:", - Kind::Development => ":wrench:", - Kind::Distribution => ":package:", - Kind::Documentation => ":books:", - Kind::Fixed => ":bug:", - Kind::Reform => ":art:", - Kind::Release => ":bookmark:", - Kind::Testing => ":white_check_mark:", - } - } else { - ":construction:" + match self.kind { + Kind::Added => ":sparkles:", + Kind::Breaking => ":boom:", + Kind::Changed => ":zap:", + Kind::Development => ":wrench:", + Kind::Distribution => ":package:", + Kind::Documentation => ":books:", + Kind::Fixed => ":bug:", + Kind::Reform => ":art:", + Kind::Release => ":bookmark:", + Kind::Testing => ":white_check_mark:", } } } @@ -49,7 +47,7 @@ impl Metadata { impl Default for Metadata { fn default() -> Metadata { Metadata { - kind: None, + kind: Kind::Changed, pr: None, fixes: Vec::new(), } diff --git a/justfile b/justfile index 504585cd..dbc3d000 100644 --- a/justfile +++ b/justfile @@ -24,7 +24,7 @@ push: check git push github # clean up feature branch BRANCH -done BRANCH=`git rev-parse --abbrev-ref HEAD`: +done BRANCH=`git rev-parse --abbrev-ref HEAD`: check git diff --no-ext-diff --quiet --exit-code git push github {{BRANCH}}:master git checkout master @@ -86,16 +86,19 @@ check-man: man check-minimal-versions: ./bin/check-minimal-versions -check: test clippy lint check-minimal-versions +check: test clippy lint check-minimal-versions changelog git diff --no-ext-diff --quiet --exit-code cargo +nightly fmt --all -- --check cargo run --package update-readme toc git diff --no-ext-diff --quiet --exit-code +draft: push + hub pull-request -o --draft + pr: push hub pull-request -o -merge: +merge: check #!/usr/bin/env bash set -euxo pipefail while ! hub ci-status --verbose; do @@ -113,6 +116,9 @@ publish: publish-check git push github {{version}} cargo publish +changelog: + cargo run --package changelog update + # record demo animation record: #!/usr/bin/env bash