File tree Expand file tree Collapse file tree 3 files changed +20
-4
lines changed Expand file tree Collapse file tree 3 files changed +20
-4
lines changed Original file line number Diff line number Diff line change @@ -496,7 +496,11 @@ pub(crate) struct BotPullRequests {}
496
496
#[ serde( rename_all = "kebab-case" ) ]
497
497
#[ serde( deny_unknown_fields) ]
498
498
pub ( crate ) struct RenderedLinkConfig {
499
+ /// List of paths to watch for modifications
499
500
pub ( crate ) trigger_files : Vec < String > ,
501
+ /// List of paths to exclude from watching for modifications
502
+ #[ serde( default ) ]
503
+ pub ( crate ) exclude_files : Vec < String > ,
500
504
}
501
505
502
506
#[ derive( PartialEq , Eq , Debug , serde:: Deserialize ) ]
@@ -720,7 +724,8 @@ mod tests {
720
724
merge_conflicts: None ,
721
725
bot_pull_requests: None ,
722
726
rendered_link: Some ( RenderedLinkConfig {
723
- trigger_files: vec![ "posts/" . to_string( ) ]
727
+ trigger_files: vec![ "posts/" . to_string( ) ] ,
728
+ exclude_files: vec![ ] ,
724
729
} ) ,
725
730
issue_links: Some ( IssueLinksConfig {
726
731
check_commits: true ,
Original file line number Diff line number Diff line change @@ -1122,6 +1122,9 @@ pub struct PullRequestFile {
1122
1122
pub sha : String ,
1123
1123
pub filename : String ,
1124
1124
pub blob_url : String ,
1125
+ pub additions : u64 ,
1126
+ pub deletions : u64 ,
1127
+ pub changes : u64 ,
1125
1128
}
1126
1129
1127
1130
#[ derive( Debug , serde:: Deserialize ) ]
Original file line number Diff line number Diff line change @@ -42,13 +42,20 @@ 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 ( )
49
49
. any ( |tf| f. filename . starts_with ( tf) )
50
+ && !config
51
+ . exclude_files
52
+ . iter ( )
53
+ . any ( |tf| f. filename . starts_with ( tf) )
50
54
} )
51
- . 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| {
52
59
let head = e. issue . head . as_ref ( ) ?;
53
60
let base = e. issue . base . as_ref ( ) ?;
54
61
@@ -84,7 +91,8 @@ async fn add_rendered_link(
84
91
} ,
85
92
file. filename
86
93
) )
87
- } ) ;
94
+ } )
95
+ . flatten ( ) ;
88
96
89
97
let new_body: Cow < ' _ , str > = if !e. issue . body . contains ( "[Rendered]" ) {
90
98
if let Some ( rendered_link) = rendered_link {
You can’t perform that action at this time.
0 commit comments