@@ -4,7 +4,7 @@ use anyhow::bail;
4
4
5
5
use crate :: {
6
6
config:: RenderedLinkConfig ,
7
- github:: { Event , IssuesAction , IssuesEvent } ,
7
+ github:: { Event , IssuesAction , IssuesEvent , PullRequestFile } ,
8
8
handlers:: Context ,
9
9
} ;
10
10
@@ -42,7 +42,7 @@ async fn add_rendered_link(
42
42
43
43
let rendered_link = files
44
44
. iter ( )
45
- . find ( |f| {
45
+ . filter ( |f| {
46
46
config
47
47
. trigger_files
48
48
. iter ( )
@@ -52,7 +52,10 @@ async fn add_rendered_link(
52
52
. iter ( )
53
53
. any ( |tf| f. filename . starts_with ( tf) )
54
54
} )
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 ( |f1, f2| total_lines_changed ( f1) . cmp ( & total_lines_changed ( f2) ) )
58
+ . map ( |file| {
56
59
let head = e. issue . head . as_ref ( ) ?;
57
60
let base = e. issue . base . as_ref ( ) ?;
58
61
@@ -88,7 +91,8 @@ async fn add_rendered_link(
88
91
} ,
89
92
file. filename
90
93
) )
91
- } ) ;
94
+ } )
95
+ . flatten ( ) ;
92
96
93
97
let new_body: Cow < ' _ , str > = if !e. issue . body . contains ( "[Rendered]" ) {
94
98
if let Some ( rendered_link) = rendered_link {
@@ -128,3 +132,7 @@ async fn add_rendered_link(
128
132
129
133
Ok ( ( ) )
130
134
}
135
+
136
+ fn total_lines_changed ( f : & PullRequestFile ) -> u64 {
137
+ f. additions + f. deletions + f. changes
138
+ }
0 commit comments