File tree Expand file tree Collapse file tree 2 files changed +16
-4
lines changed Expand file tree Collapse file tree 2 files changed +16
-4
lines changed Original file line number Diff line number Diff line change @@ -1100,6 +1100,9 @@ pub struct PullRequestFile {
1100
1100
pub sha : String ,
1101
1101
pub filename : String ,
1102
1102
pub blob_url : String ,
1103
+ pub additions : u64 ,
1104
+ pub deletions : u64 ,
1105
+ pub changes : u64 ,
1103
1106
}
1104
1107
1105
1108
#[ derive( Debug , serde:: Deserialize ) ]
Original file line number Diff line number Diff line change @@ -40,9 +40,9 @@ async fn add_rendered_link(
40
40
{
41
41
let files = e. issue . files ( & ctx. github ) . await ?;
42
42
43
- let rendered_link = files
43
+ let mut relevant_files : Vec < _ > = files
44
44
. iter ( )
45
- . find ( |f| {
45
+ . filter ( |f| {
46
46
config
47
47
. trigger_files
48
48
. iter ( )
@@ -52,7 +52,15 @@ async fn add_rendered_link(
52
52
. iter ( )
53
53
. any ( |tf| f. filename . starts_with ( tf) )
54
54
} )
55
- . and_then ( |file| {
55
+ . collect ( ) ;
56
+
57
+ // Sort the relavant files by the total number of lines changed, as to
58
+ // improve our guess for the relevant file to show the link to.
59
+ relevant_files. sort_by_key ( |f| f. additions + f. deletions + f. changes ) ;
60
+
61
+ let rendered_link = relevant_files
62
+ . last ( )
63
+ . map ( |file| {
56
64
let head = e. issue . head . as_ref ( ) ?;
57
65
let base = e. issue . base . as_ref ( ) ?;
58
66
@@ -88,7 +96,8 @@ async fn add_rendered_link(
88
96
} ,
89
97
file. filename
90
98
) )
91
- } ) ;
99
+ } )
100
+ . flatten ( ) ;
92
101
93
102
let new_body: Cow < ' _ , str > = if !e. issue . body . contains ( "[Rendered]" ) {
94
103
if let Some ( rendered_link) = rendered_link {
You can’t perform that action at this time.
0 commit comments