@@ -779,6 +779,21 @@ pub struct CommitBase {
779
779
sha : String ,
780
780
}
781
781
782
+ pub fn files_changed ( diff : & str ) -> Vec < & str > {
783
+ let mut files = Vec :: new ( ) ;
784
+ for line in diff. lines ( ) {
785
+ // mostly copied from highfive
786
+ if line. starts_with ( "diff --git " ) {
787
+ files. push (
788
+ line[ line. find ( " b/" ) . unwrap ( ) ..]
789
+ . strip_prefix ( " b/" )
790
+ . unwrap ( ) ,
791
+ ) ;
792
+ }
793
+ }
794
+ files
795
+ }
796
+
782
797
impl IssuesEvent {
783
798
/// Returns the diff in this event, for Open and Synchronize events for now.
784
799
pub async fn diff_between ( & self , client : & GithubClient ) -> anyhow:: Result < Option < String > > {
@@ -1331,3 +1346,73 @@ pub trait IssuesQuery {
1331
1346
client : & ' a GithubClient ,
1332
1347
) -> anyhow:: Result < Vec < crate :: actions:: IssueDecorator > > ;
1333
1348
}
1349
+
1350
+ #[ cfg( test) ]
1351
+ mod tests {
1352
+ use super :: * ;
1353
+
1354
+ #[ test]
1355
+ fn extract_one_file ( ) {
1356
+ let input = r##"\
1357
+ diff --git a/triagebot.toml b/triagebot.toml
1358
+ index fb9cee43b2d..b484c25ea51 100644
1359
+ --- a/triagebot.toml
1360
+ +++ b/triagebot.toml
1361
+ @@ -114,6 +114,15 @@ trigger_files = [
1362
+ "src/tools/rustdoc-themes",
1363
+ ]
1364
+ +[autolabel."T-compiler"]
1365
+ +trigger_files = [
1366
+ + # Source code
1367
+ + "compiler",
1368
+ +
1369
+ + # Tests
1370
+ + "src/test/ui",
1371
+ +]
1372
+ +
1373
+ [notify-zulip."I-prioritize"]
1374
+ zulip_stream = 245100 # #t-compiler/wg-prioritization/alerts
1375
+ topic = "#{number} {title}"
1376
+ "## ;
1377
+ assert_eq ! ( files_changed( input) , vec![ "triagebot.toml" . to_string( ) ] ) ;
1378
+ }
1379
+
1380
+ #[ test]
1381
+ fn extract_several_files ( ) {
1382
+ let input = r##"\
1383
+ diff --git a/library/stdarch b/library/stdarch
1384
+ index b70ae88ef2a..cfba59fccd9 160000
1385
+ --- a/library/stdarch
1386
+ +++ b/library/stdarch
1387
+ @@ -1 +1 @@
1388
+ -Subproject commit b70ae88ef2a6c83acad0a1e83d5bd78f9655fd05
1389
+ +Subproject commit cfba59fccd90b3b52a614120834320f764ab08d1
1390
+ diff --git a/src/librustdoc/clean/types.rs b/src/librustdoc/clean/types.rs
1391
+ index 1fe4aa9023e..f0330f1e424 100644
1392
+ --- a/src/librustdoc/clean/types.rs
1393
+ +++ b/src/librustdoc/clean/types.rs
1394
+ @@ -2322,3 +2322,4 @@ impl SubstParam {
1395
+ if let Self::Lifetime(lt) = self { Some(lt) } else { None }
1396
+ }
1397
+ }
1398
+ +
1399
+ diff --git a/src/librustdoc/core.rs b/src/librustdoc/core.rs
1400
+ index c58310947d2..3b0854d4a9b 100644
1401
+ --- a/src/librustdoc/core.rs
1402
+ +++ b/src/librustdoc/core.rs
1403
+ @@ -591,3 +591,4 @@ fn from(idx: u32) -> Self {
1404
+ ImplTraitParam::ParamIndex(idx)
1405
+ }
1406
+ }
1407
+ +
1408
+ "## ;
1409
+ assert_eq ! (
1410
+ files_changed( input) ,
1411
+ vec![
1412
+ "library/stdarch" . to_string( ) ,
1413
+ "src/librustdoc/clean/types.rs" . to_string( ) ,
1414
+ "src/librustdoc/core.rs" . to_string( ) ,
1415
+ ]
1416
+ )
1417
+ }
1418
+ }
0 commit comments