1
+ use std:: sync:: LazyLock ;
2
+
3
+ use regex:: Regex ;
4
+
1
5
use crate :: github:: FileDiff ;
2
6
3
7
const SUBMODULE_WARNING_MSG : & str = "Some commits in this PR modify **submodules**." ;
4
8
9
+ static SUBPROJECT_UPDATE_RE : LazyLock < Regex > =
10
+ LazyLock :: new ( || Regex :: new ( r"\+Subproject\scommit\s" ) . unwrap ( ) ) ;
11
+
5
12
/// Returns a message if the PR modifies a git submodule.
6
13
pub ( super ) fn modifies_submodule ( diff : & [ FileDiff ] ) -> Option < String > {
7
- let re = regex:: Regex :: new ( r"\+Subproject\scommit\s" ) . unwrap ( ) ;
8
- if diff. iter ( ) . any ( |fd| re. is_match ( & fd. patch ) ) {
14
+ if diff
15
+ . iter ( )
16
+ . any ( |fd| SUBPROJECT_UPDATE_RE . is_match ( & fd. patch ) )
17
+ {
9
18
Some ( SUBMODULE_WARNING_MSG . to_string ( ) )
10
19
} else {
11
20
None
@@ -15,8 +24,8 @@ pub(super) fn modifies_submodule(diff: &[FileDiff]) -> Option<String> {
15
24
#[ test]
16
25
fn no_submodule_update ( ) {
17
26
let filediff = FileDiff {
18
- path : "src/lib.rs" . to_string ( ) ,
19
- diff : "@@ -1 +1 @@\
27
+ filename : "src/lib.rs" . to_string ( ) ,
28
+ patch : "@@ -1 +1 @@\
20
29
-let mut my_var = 5;\
21
30
+let mut my_var = \" tmp\" ;"
22
31
. to_string ( ) ,
@@ -29,8 +38,8 @@ fn no_submodule_update() {
29
38
fn simple_submodule_update ( ) {
30
39
// Taken from https://api.github.com/repos/rust-lang/rust/compare/5af801b687e6e8b860ae970e725c8b9a3820d0ce...d6c4ab81be200855df856468ddedde057958441a
31
40
let filediff = FileDiff {
32
- path : "src/tools/rustc-perf" . to_string ( ) ,
33
- diff : "@@ -1 +1 @@\n \
41
+ filename : "src/tools/rustc-perf" . to_string ( ) ,
42
+ patch : "@@ -1 +1 @@\n \
34
43
-Subproject commit c0f3b53c8e5de87714d18a5f42998859302ae03a\n \
35
44
+Subproject commit 8158f78f738715c060d230351623a7f7cc01bf97"
36
45
. to_string ( ) ,
@@ -45,8 +54,8 @@ fn simple_submodule_update() {
45
54
#[ test]
46
55
fn no_submodule_update_tricky_case ( ) {
47
56
let filediff = FileDiff {
48
- path : "src/tools.sh" . to_string ( ) ,
49
- diff : "@@ -1 +1 @@\
57
+ filename : "src/tools.sh" . to_string ( ) ,
58
+ patch : "@@ -1 +1 @@\
50
59
-let mut subproject_commit = 5;\
51
60
+let mut subproject_commit = \" +Subproject commit \" ;"
52
61
. to_string ( ) ,
0 commit comments