Skip to content

Commit 899d7b2

Browse files
committed
update OK Bot
1 parent 75376bb commit 899d7b2

File tree

3 files changed

+52
-13
lines changed

3 files changed

+52
-13
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "OK"
3-
version = "0.1.2"
3+
version = "0.1.3"
44
edition = "2024"
55

66
[dependencies]

src/main.rs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use std::{
1111
use args::{OKAction, OKArgs};
1212
use commit::Commit;
1313
use diff::find_differences;
14-
use objdiff_core::bindings::report::{Report, ReportItem};
14+
use objdiff_core::bindings::report::Report;
1515
use pr::PullRequestReport;
1616

1717
fn main() {
@@ -20,7 +20,17 @@ fn main() {
2020
let previous = load_report(&args.previous);
2121
let current = load_report(&args.current);
2222

23-
let diffs = find_differences(previous.units, current.units);
23+
let mut diffs = find_differences(previous.units, current.units);
24+
25+
diffs.sections = diffs
26+
.sections
27+
.iter()
28+
// ghetto hack to remove this one text section which is showing up in all PRS:
29+
// might be related to this:
30+
// https://github.com/encounter/objdiff/issues/120#issuecomment-2770545367
31+
.filter(|x| !(x.unit_name == "main/SB/Game/zNPCTypeCommon" && x.name == ".text"))
32+
.map(|x| x.clone())
33+
.collect();
2434

2535
let diff_json = serde_json::to_string_pretty(&diffs).expect("Failed to serialize diffs");
2636
let mut file = File::create("diff.json").unwrap();

src/pr.rs

Lines changed: 39 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,10 @@ use crate::diff::{DifferenceReport, ReportItemDifference};
1818
pub struct DiffSummary {
1919
pub unit_name: String,
2020
pub name: String,
21+
pub fuzzy_percent: f32,
2122
pub percent_difference: f32,
2223
pub size: u64,
23-
pub size_difference: u64,
24+
pub size_difference: i64,
2425
}
2526

2627
// test
@@ -34,31 +35,33 @@ impl DiffSummary {
3435
None => diff.name.clone(),
3536
},
3637
size: diff.size,
38+
fuzzy_percent: diff.new_fuzzy_match_percent,
3739
percent_difference: percent_diff,
38-
size_difference: (((diff.size as f32) * (percent_diff / 100.0)) as u64),
40+
size_difference: (((diff.size as f32) * (percent_diff / 100.0)) as i64),
3941
}
4042
}
4143

4244
pub fn to_string(&self) -> String {
4345
let direction = if self.percent_difference > 0.0 {
4446
"+"
4547
} else {
46-
"-"
48+
"" // Don't need to add the minus sign, Rust will do it on its own
4749
};
50+
4851
//println!("{:?}", self);
49-
let percent = format!("{:.2}%", self.percent_difference);
52+
let percent = format!("{:.2}%", self.fuzzy_percent);
5053

51-
let emoji = match self.percent_difference {
54+
let emoji = match self.fuzzy_percent {
5255
100.00 => "✅",
5356
_ => match self.percent_difference > 0.0 {
5457
true => "📈",
55-
false => "📉",
58+
false => "⚠️",
5659
},
5760
};
5861

5962
format!(
60-
"{emoji} `{}` - `{}`: {direction}{} ({direction}{})",
61-
self.unit_name, self.name, percent, self.size_difference
63+
"{emoji} `{} - {}` {direction}{} bytes -> {percent}",
64+
self.unit_name, self.name, self.size_difference
6265
)
6366
}
6467
}
@@ -90,17 +93,22 @@ impl PullRequestReport {
9093
.iter()
9194
.filter(|i| i.new_fuzzy_match_percent < i.old_fuzzy_match_percent)
9295
.map(|i| Regression(DiffSummary::new(i)))
96+
.filter(|x| x.0.size_difference != 0)
9397
.collect()
9498
}
9599

96100
pub fn get_progressions(&self) -> Vec<Progression> {
97101
let mut items: Vec<ReportItemDifference> = self.diffs.sections.clone();
98-
items.extend(self.diffs.functions.clone());
102+
items.sort_by_key(|x| x.size as i32 * -1);
103+
let mut fns = self.diffs.functions.clone();
104+
fns.sort_by_key(|x| x.size as i32 * -1);
105+
items.extend(fns);
99106

100107
items
101108
.iter()
102109
.filter(|i| i.new_fuzzy_match_percent > i.old_fuzzy_match_percent)
103110
.map(|i| Progression(DiffSummary::new(i)))
111+
.filter(|x| x.0.size_difference != 0)
104112
.collect()
105113
}
106114

@@ -122,6 +130,7 @@ impl PullRequestReport {
122130
false => "No Regressions 🎉".to_owned(),
123131
true => format!("Regressions: {regression_count}"),
124132
};
133+
125134
let regressions_string = match regressions_exist {
126135
false => "".to_owned(),
127136
true => {
@@ -144,9 +153,29 @@ impl PullRequestReport {
144153
}
145154
};
146155

156+
let size_diff = progressions
157+
.iter()
158+
.map(|x| x.0.size_difference)
159+
.sum::<i64>();
160+
let size_direction = if size_diff >= 0 { "+" } else { "" };
161+
162+
let ok_rating = match size_diff {
163+
diff if diff >= 5_000 => "You are a decomp GOD, can I have your autograph?",
164+
diff if diff >= 2_000 => "Amazing contribution, you are the decomp GOAT 🐐",
165+
diff if diff >= 1_000 => "A Fantastic contribution! ✨🎉",
166+
diff if diff > 750 => "Ay, dios mio, gracias por la contribución!",
167+
diff if diff > 500 => "A solid contribution, Спасибо!",
168+
diff if diff > 250 => "A decent contribution. Thank you!",
169+
diff if diff < 100 => "A small but commendable contribution",
170+
diff if diff < 0 => "You're going in the wrong direction..?",
171+
diff if diff < -1_000 => "You really screwed up 🙉",
172+
_ => "I don't have an opinion",
173+
};
174+
147175
let lines: Vec<String> = vec![
148-
// h
149176
format!("# {}", header),
177+
format!("{}{} bytes", size_direction, size_diff),
178+
format!("🆗 Bot Rating: {}", ok_rating),
150179
format!("## {}", regressions_header),
151180
regressions_string,
152181
format!("## {}", progress_header),

0 commit comments

Comments
 (0)