Skip to content

Commit

Permalink
improve heuristics for whether an update is ready for feedback again
Browse files Browse the repository at this point in the history
  • Loading branch information
decathorpe committed May 30, 2022
1 parent 72c6c1c commit de07995
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 16 deletions.
19 changes: 16 additions & 3 deletions src/input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,23 @@ pub struct Progress {
update_number: usize,
total_updates: usize,
prev_commented: bool,
karma_reset: bool,
prev_ignored: bool,
}

impl Progress {
pub fn new(update_number: usize, total_updates: usize, prev_commented: bool, prev_ignored: bool) -> Progress {
pub fn new(
update_number: usize,
total_updates: usize,
prev_commented: bool,
karma_reset: bool,
prev_ignored: bool,
) -> Progress {
Progress {
update_number,
total_updates,
prev_commented,
karma_reset,
prev_ignored,
}
}
Expand Down Expand Up @@ -104,8 +112,13 @@ pub fn ask_feedback<'a>(
);

if progress.prev_commented {
println!("A comment for this update has already been submitted.");
println!("Any feedback / karma that is provided now will overwrite previous values.");
if progress.karma_reset {
println!("A comment for this update has already been submitted.");
println!("However, the update has since been edited, and karma has been reset.");
} else {
println!("A comment for this update has already been submitted.");
println!("Any feedback / karma that is provided now will overwrite previous values.");
}
}

if progress.prev_ignored {
Expand Down
41 changes: 29 additions & 12 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,28 @@ use sysinfo::{

const USER_AGENT: &str = concat!("fedora-update-feedback v", env!("CARGO_PKG_VERSION"));

fn has_already_commented(update: &Update, user: &str) -> bool {
update
.comments
.as_ref()
.map_or(false, |comments| comments.iter().any(|c| c.user.name == user))
fn has_already_commented(update: &Update, user: &str) -> (bool, bool) {
if let Some(comments) = update.comments.as_ref() {
let mut already_commented = false;
let mut reset = false;

comments.iter().for_each(|comment| {
// user has commented, so karma reset either never happened or happened before the comment
if comment.user.name == user && comment.karma != Karma::Neutral {
already_commented = true;
reset = false;
}
// bodhi has reset karma, so old comments can be disregarded
if comment.user.name == "bodhi" && comment.text.contains("Karma") && comment.text.contains("reset") {
already_commented = false;
reset = true;
}
});

(already_commented, reset)
} else {
(false, false)
}
}

fn packages_in_update(update: &Update) -> Vec<String> {
Expand Down Expand Up @@ -332,20 +349,20 @@ async fn main() -> Result<(), String> {
installed_updates.retain(|update| !ignored.ignored_updates.contains(&update.alias));
}

// filter out previusly commented on updates
if !args.check_commented {
installed_updates.retain(|update| !has_already_commented(update, &username));
}

// keep track of the number of installed relevant updates
let total_updates = installed_updates.len();

// iterate over the list of installed relevant updates
for (update_number, update) in installed_updates.into_iter().enumerate() {
let prev_commented = has_already_commented(update, &username);
let (prev_commented, karma_reset) = has_already_commented(update, &username);
let prev_ignored = ignored.ignored_updates.contains(&update.alias);

let progress = Progress::new(update_number, total_updates, prev_commented, prev_ignored);
// skip updates that were already commented on and where no karma reset has happened
if !args.check_commented && prev_commented && !karma_reset {
continue;
}

let progress = Progress::new(update_number, total_updates, prev_commented, karma_reset, prev_ignored);

// this unwrap is safe since we definitely inserted a value for every update earlier
#[allow(clippy::unwrap_used)]
Expand Down
2 changes: 1 addition & 1 deletion src/nvr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use std::str::FromStr;
use crate::parse::parse_nvr;

/// This struct encapsulates a parsed NVR string.
#[derive(Debug, PartialEq)]
#[derive(Debug, Eq, PartialEq)]
#[allow(clippy::upper_case_acronyms)]
pub struct NVR {
/// name of the package
Expand Down

0 comments on commit de07995

Please sign in to comment.