debian/changelog: collect LP: #NNN references from entry bodies
dpkg's Ubuntu vendor module collects 'LP: #NNN' changelog trailers into the .changes 'Launchpad-Bugs-Fixed' field, which Launchpad uses to link uploads to the bugs they fix. Port the same parsing (case-insensitive 'lp:' prefix with a mandatory space, '#'-prefixed comma-separated numbers) and rendering (numeric sort, de-duplication, space-joined) so pkh-built uploads can carry the same field.
This commit is contained in:
1 parent
581309fe80
commit
ef9c6d4f93
1 file changed
+78
@@ -34,6 +34,11 @@ pub struct ChangelogEntry {
|
||||
/// Bug numbers collected from `(Closes: #NNN)` mentions in the body,
|
||||
/// sorted numerically and de-duplicated (like dpkg's `find_closes`).
|
||||
pub closes: Option<String>,
|
||||
/// Launchpad bug numbers collected from `LP: #NNN` mentions in the
|
||||
/// body, sorted numerically and de-duplicated: a port of dpkg's Ubuntu
|
||||
/// vendor module (`Dpkg::Vendor::Ubuntu::find_launchpad_closes`),
|
||||
/// feeding the `.changes` `Launchpad-Bugs-Fixed` field.
|
||||
pub lp_bugs: Option<String>,
|
||||
}
|
||||
|
||||
/// Parse up to `limit` entries of a Debian changelog file, newest first
|
||||
@@ -213,6 +218,7 @@ fn parse_one_entry(
|
||||
}
|
||||
|
||||
let closes = find_closes(&body_lines);
|
||||
let lp_bugs = find_lp_bugs(&body_lines);
|
||||
|
||||
Ok(ChangelogEntry {
|
||||
source,
|
||||
@@ -226,6 +232,7 @@ fn parse_one_entry(
|
||||
timestamp,
|
||||
changes_field,
|
||||
closes,
|
||||
lp_bugs,
|
||||
})
|
||||
}
|
||||
|
||||
@@ -260,6 +267,41 @@ fn find_closes(body_lines: &[String]) -> Option<String> {
|
||||
)
|
||||
}
|
||||
|
||||
/// Extract Launchpad bug numbers from `LP: #NNN` mentions in changelog
|
||||
/// body lines, sorted numerically and de-duplicated: a port of dpkg's
|
||||
/// Ubuntu vendor module (`Dpkg::Vendor::Ubuntu::find_launchpad_closes`),
|
||||
/// which fills the `.changes` `Launchpad-Bugs-Fixed` field. Same `lp:`
|
||||
/// prefix (case-insensitive, at least one space), same `#`-prefixed
|
||||
/// comma-separated list, same space-joined rendering.
|
||||
fn find_lp_bugs(body_lines: &[String]) -> Option<String> {
|
||||
let re = Regex::new(r"(?i)lp:\s+#\d+(?:,\s*#\d+)*").ok()?;
|
||||
let number = Regex::new(r"#?\s?(\d+)").ok()?;
|
||||
let mut numbers: Vec<u64> = Vec::new();
|
||||
for line in body_lines {
|
||||
for statement in re.find_iter(line) {
|
||||
for capture in number.captures_iter(statement.as_str()) {
|
||||
if let Some(n) = capture.get(1)
|
||||
&& let Ok(parsed) = n.as_str().parse::<u64>()
|
||||
{
|
||||
numbers.push(parsed);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if numbers.is_empty() {
|
||||
return None;
|
||||
}
|
||||
numbers.sort_unstable();
|
||||
numbers.dedup();
|
||||
Some(
|
||||
numbers
|
||||
.iter()
|
||||
.map(u64::to_string)
|
||||
.collect::<Vec<_>>()
|
||||
.join(" "),
|
||||
)
|
||||
}
|
||||
|
||||
/// Heuristic check for a changelog entry header line
|
||||
/// (`name (version) dist; urgency=...`).
|
||||
fn looks_like_header(line: &str) -> bool {
|
||||
@@ -280,6 +322,42 @@ fn looks_like_header(line: &str) -> bool {
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
/// Parse one entry from a changelog text with this body.
|
||||
fn entry_with_body(body: &str) -> ChangelogEntry {
|
||||
parse_changelog_entries_from_str(
|
||||
&format!(
|
||||
"pkg (1.0-1) unstable; urgency=medium\n\n{body}\n \
|
||||
-- A B <a@b.c> Thu, 01 Jan 2026 00:00:00 +0000\n"
|
||||
),
|
||||
Some(1),
|
||||
)
|
||||
.unwrap()
|
||||
.remove(0)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn launchpad_bug_references() {
|
||||
// Single reference
|
||||
let entry = entry_with_body(" * Fix crash (LP: #123456)");
|
||||
assert_eq!(entry.lp_bugs.as_deref(), Some("123456"));
|
||||
|
||||
// Comma-separated list, sorted numerically like dpkg renders them
|
||||
let entry = entry_with_body(" * Fix crash (LP: #123456, #99, #45)");
|
||||
assert_eq!(entry.lp_bugs.as_deref(), Some("45 99 123456"));
|
||||
|
||||
// De-duplicated across several statements and lines
|
||||
let entry = entry_with_body(" * Fix A (LP: #5)\n * Fix B (lp: #5, #6)");
|
||||
assert_eq!(entry.lp_bugs.as_deref(), Some("5 6"));
|
||||
|
||||
// Without the space dpkg's Ubuntu parser requires: no match
|
||||
let entry = entry_with_body(" * Fix crash (LP:#123456)");
|
||||
assert_eq!(entry.lp_bugs, None);
|
||||
|
||||
// Plain bug mentions are not Launchpad references
|
||||
let entry = entry_with_body(" * Fix crash (#123456)\n * Closes: #42");
|
||||
assert_eq!(entry.lp_bugs, None);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn changelog_parsing() {
|
||||
let dir = tempfile::tempdir().unwrap();
|
||||
|
||||
Reference in new issue
Block a user