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 log::trace!("******************/n** create entry **/n******************/n");
16 let mut pr_title = PrTitle::parse(self.title())?;
17 pr_title.pr_id = Some(self.pr_number());
18 pr_title.pr_url = Some(Url::from_str(self.pull_request())?);
19 pr_title.calculate_section_and_entry();
20 log::trace!("pr_title: {:#?}", pr_title);
21
22 self.changelog_update = Some(pr_title);
23
24 Ok(())
25 }
26
27 fn update_changelog(&mut self) -> Result<Option<(ChangeKind, String)>, Error> {
28 log::debug!(
29 "Updating changelog: {:?} with entry {:?}",
30 self.changelog,
31 self.changelog_update
32 );
33
34 if self.changelog.is_empty() {
35 return Err(Error::NoChangeLogFileFound);
36 }
37
38 let opts = self.changelog_parse_options.clone();
39
40 if let Some(update) = &mut self.changelog_update {
41 #[allow(clippy::needless_question_mark)]
42 return Ok(update.update_changelog(&self.changelog, opts)?);
43 }
44 Ok(None)
45 }
46}