Skip to content

Commit

Permalink
chore: rename author to name
Browse files Browse the repository at this point in the history
  • Loading branch information
drahnr committed Apr 22, 2023
1 parent 6ea4ff1 commit 9de586f
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 25 deletions.
24 changes: 14 additions & 10 deletions src/rpm/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,9 @@ pub struct RPMBuilder {
pre_uninst_script: Option<String>,
post_uninst_script: Option<String>,

changelog_authors: Vec<String>,
/// The author name with email followed by a dash with the version
/// `Max Mustermann <max@example.com> - 0.1-1`
changelog_names: Vec<String>,
changelog_entries: Vec<String>,
changelog_times: Vec<chrono::DateTime<chrono::Utc>>,
compressor: Compressor,
Expand Down Expand Up @@ -201,35 +203,37 @@ impl RPMBuilder {
self
}

/// Add an entry to the changelog, compromised of author, description, and the date and time of the change.
/// Add an entry to the changelog, compromised of changelog name (which includes author, email followed by
/// a dash followed by a version number),
/// description, and the date and time of the change.
///
/// ```ignore
/// let pkg = rpm::RPMBuilder::new(..)
/// .add_changelog_entry(
/// "Alfred J. Quack <quack@example.com>",
/// "Alfred J. Quack <quack@example.com> - 0.1-27",
/// r#" - Obsolete `fn foo`, in favor of `fn bar`.
/// - Secondly."#,
/// rpm::chrono::Utc.timestamp_opt(1681411811, 0).unwrap(),
/// )
/// .add_changelog_entry(
/// "Gambl B. Xen <gbx@example.com>",
/// "Gambl B. Xen <gbx@example.com> - 0.1-26",
/// " - Add enumerator."
/// rpm::chrono::DateTime::parse_from_rfc3339("1996-12-19T16:39:57-08:00").unwrap(),
/// )
/// //..
/// ```
pub fn add_changelog_entry<A, E, TZ>(
pub fn add_changelog_entry<N, E, TZ>(
mut self,
author: A,
name: N,
entry: E,
datetime: chrono::DateTime<TZ>,
) -> Self
where
A: AsRef<str>,
N: AsRef<str>,
E: AsRef<str>,
TZ: chrono::TimeZone,
{
self.changelog_authors.push(author.as_ref().to_owned());
self.changelog_names.push(name.as_ref().to_owned());
self.changelog_entries.push(entry.as_ref().to_owned());
self.changelog_times
.push(datetime.with_timezone(&chrono::Utc));
Expand Down Expand Up @@ -1001,11 +1005,11 @@ impl RPMBuilder {
));
}

if !self.changelog_authors.is_empty() {
if !self.changelog_names.is_empty() {
actual_records.push(IndexEntry::new(
IndexTag::RPMTAG_CHANGELOGNAME,
offset,
IndexData::StringArray(self.changelog_authors),
IndexData::StringArray(self.changelog_names),
));
actual_records.push(IndexEntry::new(
IndexTag::RPMTAG_CHANGELOGTEXT,
Expand Down
2 changes: 1 addition & 1 deletion src/rpm/headers/header.rs
Original file line number Diff line number Diff line change
Expand Up @@ -469,7 +469,7 @@ impl FileDigest {
/// User facing accessor type for a changelog entry
#[derive(Debug, Clone, Hash, Eq, PartialEq)]
pub struct ChangelogEntry {
pub author: String,
pub name: String,
pub timestamp: u64,
pub description: String,
}
Expand Down
26 changes: 12 additions & 14 deletions src/rpm/package.rs
Original file line number Diff line number Diff line change
Expand Up @@ -782,7 +782,7 @@ impl RPMPackageMetadata {

/// Return a list of changelog entries
pub fn get_changelog_entries(&self) -> Result<Vec<ChangelogEntry>, RPMError> {
let authors = self
let names = self
.header
.get_entry_data_as_string_array(IndexTag::RPMTAG_CHANGELOGNAME);
let timestamps = self
Expand All @@ -793,26 +793,24 @@ impl RPMPackageMetadata {
.get_entry_data_as_string_array(IndexTag::RPMTAG_CHANGELOGTEXT);

// Return an empty list if the tags are not present
match (authors, timestamps, descriptions) {
match (names, timestamps, descriptions) {
(
Err(RPMError::TagNotFound(_)),
Err(RPMError::TagNotFound(_)),
Err(RPMError::TagNotFound(_)),
) => Ok(vec![]),
(Ok(authors), Ok(timestamps), Ok(descriptions)) => {
let v = Vec::from_iter(
itertools::multizip((authors, timestamps, descriptions)).map(
|(author, timestamp, description)| ChangelogEntry {
author: author.to_owned(),
timestamp: timestamp as u64,
description: description.to_owned(),
},
),
);
(Ok(names), Ok(timestamps), Ok(descriptions)) => {
let v = Vec::from_iter(itertools::multizip((names, timestamps, descriptions)).map(
|(name, timestamp, description)| ChangelogEntry {
name: name.to_owned(),
timestamp: timestamp as u64,
description: description.to_owned(),
},
));
Ok(v)
}
(author, timestamp, description) => {
author?;
(name, timestamp, description) => {
name?;
timestamp?;
description?;
unreachable!()
Expand Down

0 comments on commit 9de586f

Please sign in to comment.