Repository navigation
refactor(core): improve the generation API - #1306
Conversation
|
cc @marcoieni (for release-plz downstream) |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #1306 +/- ##
==========================================
+ Coverage 43.86% 43.88% +0.02%
==========================================
Files 23 23
Lines 2214 2220 +6
==========================================
+ Hits 971 974 +3
- Misses 1243 1246 +3
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
ognis1205
left a comment
There was a problem hiding this comment.
nit: as mentioned on Discord, a few clones could be reduced.
See the suggestion for the exact changes. Otherwise, LGTM!
The arguments of run_with_changelog_modifier could also be reconsidered later.
|
Thanks for the great review! I applied your suggestions |
There was a problem hiding this comment.
Thanks for accepting the previous suggestion!
I left a suggestion regarding a point I missed in the last review. As an additional note, I changed the lifetime from 'static to 'a for Changelog<'a>. This allows the caller to decide the appropriate lifetime. Although we kept the 'a lifetime for flexibility, in practice the returned Changelog is always 'static because it owns all its data internally. This is mostly a stylistic choice, so feel free to ignore if you prefer.
I'm also quoting here the discussion from Discord about Cow:
Considering
git-cliffas a CLI tool, currently the only place callingChangelog::neworChangelog::from_contextisrun_with_changelog_modifier, so I don't think usingCow<'a, Config>is necessary.However, if we view
git-cliff-coreas an SDK that could be used by external applications, implementingimpl<'a> From<Config> for Cow<'a, Config>andimpl<'a> From<&'a Config> for Cow<'a, Config>and changing the arguments ofChangelog::new/Changelog::build/Changelog::from_contexttoconfig: impl Into<Cow<'a, Config>>seems like a reasonable option. This would also preserve backward compatibility.
|
In another thread, I discussed with @orhun the idea of changing the struct to something like: pub struct Changelog<'a> {
/// Releases that the changelog will contain.
pub releases: Vec<Release<'a>>,
/// Configuration used for generating the changelog.
pub config: Cow<'a, Config>,
header_template: Option<Template>,
body_template: Template,
footer_template: Option<Template>,
additional_context: HashMap<String, serde_json::Value>,
}and updating the API in pub fn new(releases: Vec<Release<'a>>, config: impl Into<Cow<'a, Config>>, range: Option<&str>) -> Result<Self>I think this approach, using That said, I don't want to burden everyone with extra review work, so I think it's fine to proceed with the current approach for now. If any compatibility issues arise later, we can revisit and implement this change separately, it shouldn't require too much additional effort. |
|
As @orhun mentioned earlier, in the long term, we'll likely need a broader overhaul of In particular, it might be worth reconsidering whether the For this PR, I think we can proceed as is, but it could be good to open a separate long-term issue to track that discussion. |
|
I have no time to review this unfortunately. Feel free to do all the updates you want. I'll just fix them in release-plz. If you bump the major version of git-cliff-core when publishing the breaking changes it would be great! |
* `init_config`: initializes and writes a configuration file. * `write_changelog`: writes the generated changelog to a file or stdout. * `Changelog::new` now takes ownership of `Config` (`Config` instead of `&Config`). * `Changelog::from_context` and internal `build` methods also updated to take `Config` by value. * `run` now returns `Result<Changelog<'static>>` instead of `Result<()>`. * Configuration initialization logic moved out of `run_with_changelog_modifier()` into the new `init_config()` function. * The main entry point (`main.rs`) now explicitly calls `check_new_version()`, `init_config()`, `run()`, and `write_changelog()` instead of relying on `run()` for all logic. * Example renamed from `examples/run.rs` to `examples/basic.rs` and updated to use the new API (`write_changelog`). * `check_new_version()` made public. * `Opt` now derives `Clone` to allow reuse across function calls.
bf58b09 to
f6933a4
Compare
|
Thanks for the review again Shingo! |
No problem :) If there’s anything I can help with, just ping me anytime. |
Description
New Methods
init_config: initializes and writes a configuration file.write_changelog: writes the generated changelog to a file or stdout.Breaking Changes
Changelog::newnow takes ownership ofConfig(Configinstead of&Config).Changelog::from_contextand internalbuildmethods also updated to takeConfigby value.runnow returnsResult<Changelog<'static>>instead ofResult<()>.Refactors
run_with_changelog_modifier()into the newinit_config()function.main.rs) now explicitly callscheck_new_version(),init_config(),run(), andwrite_changelog()instead of relying onrun()for all logic.examples/run.rstoexamples/basic.rsand updated to use the new API (write_changelog).Minor Changes
check_new_version()made public.Optnow derivesCloneto allow reuse across function calls.Motivation and Context
closes #1046
How Has This Been Tested?
Locally.
Types of Changes
Checklist: