pcu_lib/ops/
update_from_pr.rs1use std::str::FromStr;
2
3use keep_a_changelog::ChangeKind;
4use url::Url;
5
6use crate::{Client, Error, PrTitle};
7
8pub trait UpdateFromPr {
9 fn update_changelog(&mut self) -> Result<Option<(ChangeKind, String)>, Error>;
10 fn create_entry(&mut self) -> Result<(), Error>;
11}
12
13impl UpdateFromPr for Client {
14 fn create_entry(&mut self) -> Result<(), Error> {
15 let mut pr_title = PrTitle::parse(self.title())?;
16 pr_title.pr_id = Some(self.pr_number());
17 pr_title.pr_url = Some(Url::from_str(self.pull_request())?);
18 pr_title.calculate_section_and_entry();
19
20 self.changelog_update = Some(pr_title);
21
22 Ok(())
23 }
24
25 fn update_changelog(&mut self) -> Result<Option<(ChangeKind, String)>, Error> {
26 log::debug!(
27 "Updating changelog: {:?} with entry {:?}",
28 self.changelog,
29 self.changelog_update
30 );
31
32 if self.changelog.is_empty() {
33 return Err(Error::NoChangeLogFileFound);
34 }
35
36 let opts = self.changelog_parse_options.clone();
37
38 if let Some(update) = &mut self.changelog_update {
39 #[allow(clippy::needless_question_mark)]
40 return Ok(update.update_changelog(&self.changelog, opts)?);
41 }
42 Ok(None)
43 }
44}