Skip to content

Commit

Permalink
Make changelog generator strict
Browse files Browse the repository at this point in the history
Make the changelog generator fail if commits don't contain metadata.

type: changed
pr: #341
  • Loading branch information
casey committed Apr 8, 2020
1 parent c33446b commit 92748f9
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 31 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 <casey@rodarmor.com>_
- :zap: [`xxxxxxxxxxxx`](https://github.com/casey/intermodal/commits/master) Make changelog generator strict ([#341](https://github.com/casey/intermodal/pull/341)) - _Casey Rodarmor <casey@rodarmor.com>_
- :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 <casey@rodarmor.com>_
- :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 <casey@rodarmor.com>_
- :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 <casey@rodarmor.com>_
- :bug: [`1cfc0214536c`](https://github.com/casey/intermodal/commit/1cfc0214536c607fff7c29d9e878cbcd7f3a9ffc) Forbid empty input, output, and path targets - _Casey Rodarmor <casey@rodarmor.com>_
Expand Down
2 changes: 1 addition & 1 deletion bin/changelog/src/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion bin/changelog/src/entry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
4 changes: 0 additions & 4 deletions bin/changelog/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
// TODO:
// - parse URL in fixed:
// - figure out how to check labels before merge

use crate::common::*;

mod changelog;
Expand Down
40 changes: 19 additions & 21 deletions bin/changelog/src/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,54 +2,52 @@ use crate::common::*;

#[derive(Deserialize, Serialize)]
pub(crate) struct Metadata {
#[serde(default, rename = "type")]
pub(crate) kind: Option<Kind>,
#[serde(rename = "type")]
pub(crate) kind: Kind,
#[serde(default)]
pub(crate) pr: Option<Url>,
#[serde(default)]
pub(crate) fixes: Vec<Url>,
}

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:",
}
}
}

impl Default for Metadata {
fn default() -> Metadata {
Metadata {
kind: None,
kind: Kind::Changed,
pr: None,
fixes: Vec::new(),
}
Expand Down
12 changes: 9 additions & 3 deletions justfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit 92748f9

Please sign in to comment.