Skip to content

Commit 1496c0c

Browse files
committed
Sort by total number of lines changed to improve rendered link guess
1 parent 25b1894 commit 1496c0c

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

src/github.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1100,6 +1100,9 @@ pub struct PullRequestFile {
11001100
pub sha: String,
11011101
pub filename: String,
11021102
pub blob_url: String,
1103+
pub additions: u64,
1104+
pub deletions: u64,
1105+
pub changes: u64,
11031106
}
11041107

11051108
#[derive(Debug, serde::Deserialize)]

src/handlers/rendered_link.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ async fn add_rendered_link(
4242

4343
let rendered_link = files
4444
.iter()
45-
.find(|f| {
45+
.filter(|f| {
4646
config
4747
.trigger_files
4848
.iter()
@@ -52,7 +52,10 @@ async fn add_rendered_link(
5252
.iter()
5353
.any(|tf| f.filename.starts_with(tf))
5454
})
55-
.and_then(|file| {
55+
// Sort the relavant files by the total number of lines changed, as to
56+
// improve our guess for the relevant file to show the link to.
57+
.max_by_key(|f| f.additions + f.deletions + f.changes)
58+
.map(|file| {
5659
let head = e.issue.head.as_ref()?;
5760
let base = e.issue.base.as_ref()?;
5861

@@ -88,7 +91,8 @@ async fn add_rendered_link(
8891
},
8992
file.filename
9093
))
91-
});
94+
})
95+
.flatten();
9296

9397
let new_body: Cow<'_, str> = if !e.issue.body.contains("[Rendered]") {
9498
if let Some(rendered_link) = rendered_link {

0 commit comments

Comments
 (0)