From ddcf9262f5a3cfba6452d009a9b09cd5044be71b Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Wed, 18 Sep 2024 02:22:52 +0200 Subject: Fix duplicated contributions in `changelog` tool --- examples/changelog/src/changelog.rs | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/examples/changelog/src/changelog.rs b/examples/changelog/src/changelog.rs index 9421f91c..784efaa8 100644 --- a/examples/changelog/src/changelog.rs +++ b/examples/changelog/src/changelog.rs @@ -2,6 +2,7 @@ use serde::Deserialize; use tokio::fs; use tokio::process; +use std::collections::BTreeSet; use std::env; use std::fmt; use std::io; @@ -261,7 +262,7 @@ impl fmt::Display for Category { } } -#[derive(Debug, Clone)] +#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord)] pub struct Contribution { pub id: u64, } @@ -281,7 +282,7 @@ impl Contribution { let log = String::from_utf8_lossy(&output.stdout); - Ok(log + let mut contributions: Vec<_> = log .lines() .filter(|title| !title.is_empty()) .filter_map(|title| { @@ -292,7 +293,12 @@ impl Contribution { id: pull_request.parse().ok()?, }) }) - .collect()) + .collect(); + + let mut unique = BTreeSet::from_iter(contributions.clone()); + contributions.retain_mut(|contribution| unique.remove(contribution)); + + Ok(contributions) } } -- cgit