@@ -126,18 +126,18 @@ fn is_valid_review_template_path_github(path: &path::Path) -> bool {
126
126
}
127
127
128
128
fn get_gitlab_directory_path ( root_path : & path:: Path ) -> path:: PathBuf {
129
- // TODO: implement
130
- root_path. to_path_buf ( )
129
+ let mut path = root_path. to_path_buf ( ) ;
130
+ path. push ( ".gitlab" ) ;
131
+ path
131
132
}
132
133
133
- fn is_review_template_gitlab ( _path_str : & str ) -> bool {
134
- // TODO: implement
135
- false
134
+ fn is_review_template_gitlab ( path_str : & str ) -> bool {
135
+ let normalized_path = path_str . replace ( '\\' , "/" ) ;
136
+ normalized_path . contains ( ".gitlab/merge_request_templates/" ) && normalized_path . ends_with ( ".md" )
136
137
}
137
138
138
- fn is_valid_review_template_path_gitlab ( _path : & path:: Path ) -> bool {
139
- // TODO: implement
140
- false
139
+ fn is_valid_review_template_path_gitlab ( path : & path:: Path ) -> bool {
140
+ is_review_template_gitlab ( path. to_str ( ) . unwrap_or_default ( ) )
141
141
}
142
142
143
143
fn get_bitbucket_directory_path ( root_path : & path:: Path ) -> path:: PathBuf {
@@ -234,4 +234,62 @@ mod tests {
234
234
invalid_review_template_path,
235
235
) ) ;
236
236
}
237
+
238
+ #[ test]
239
+ fn test_is_valid_review_template_path_gitlab ( ) {
240
+ let valid_review_template_path_1 = Path :: new ( ".gitlab/merge_request_templates/Default.md" ) ;
241
+ let valid_review_template_path_2 = Path :: new ( ".gitlab/merge_request_templates/Documentation.md" ) ;
242
+ let valid_review_template_path_3 = Path :: new ( ".gitlab/merge_request_templates/Security Fix.md" ) ;
243
+ let invalid_review_template_path_1 = Path :: new ( "README.md" ) ;
244
+ let invalid_review_template_path_2 = Path :: new ( ".gitlab/issue_templates/Bug.md" ) ;
245
+ let invalid_review_template_path_3 = Path :: new ( ".gitlab/merge_request_templates/Default.txt" ) ;
246
+
247
+ assert ! ( is_valid_review_template_path_gitlab( valid_review_template_path_1) ) ;
248
+ assert ! ( is_valid_review_template_path_gitlab( valid_review_template_path_2) ) ;
249
+ assert ! ( is_valid_review_template_path_gitlab( valid_review_template_path_3) ) ;
250
+ assert ! ( !is_valid_review_template_path_gitlab( invalid_review_template_path_1) ) ;
251
+ assert ! ( !is_valid_review_template_path_gitlab( invalid_review_template_path_2) ) ;
252
+ assert ! ( !is_valid_review_template_path_gitlab( invalid_review_template_path_3) ) ;
253
+ }
254
+
255
+ #[ test]
256
+ fn test_is_valid_review_template_path_gitlab_windows ( ) {
257
+ let valid_review_template_path_1 = Path :: new ( ".gitlab\\ merge_request_templates\\ Default.md" ) ;
258
+ let valid_review_template_path_2 = Path :: new ( ".gitlab\\ merge_request_templates\\ Documentation.md" ) ;
259
+ let valid_review_template_path_3 = Path :: new ( ".gitlab\\ merge_request_templates\\ Security Fix.md" ) ;
260
+ let invalid_review_template_path_1 = Path :: new ( "README.md" ) ;
261
+ let invalid_review_template_path_2 = Path :: new ( ".gitlab\\ issue_templates\\ Bug.md" ) ;
262
+ let invalid_review_template_path_3 = Path :: new ( ".gitlab\\ merge_request_templates\\ Default.txt" ) ;
263
+
264
+ assert ! ( is_valid_review_template_path_gitlab( valid_review_template_path_1) ) ;
265
+ assert ! ( is_valid_review_template_path_gitlab( valid_review_template_path_2) ) ;
266
+ assert ! ( is_valid_review_template_path_gitlab( valid_review_template_path_3) ) ;
267
+ assert ! ( !is_valid_review_template_path_gitlab( invalid_review_template_path_1) ) ;
268
+ assert ! ( !is_valid_review_template_path_gitlab( invalid_review_template_path_2) ) ;
269
+ assert ! ( !is_valid_review_template_path_gitlab( invalid_review_template_path_3) ) ;
270
+ }
271
+
272
+ #[ test]
273
+ fn test_get_gitlab_directory_path ( ) {
274
+ let root_path = Path :: new ( "/path/to/project" ) ;
275
+ let gitlab_path = get_gitlab_directory_path ( root_path) ;
276
+ assert_eq ! ( gitlab_path, Path :: new( "/path/to/project/.gitlab" ) ) ;
277
+ }
278
+
279
+ #[ test]
280
+ fn test_is_review_template_gitlab ( ) {
281
+ // Valid GitLab merge request templates
282
+ assert ! ( is_review_template_gitlab( ".gitlab/merge_request_templates/Default.md" ) ) ;
283
+ assert ! ( is_review_template_gitlab( ".gitlab/merge_request_templates/Documentation.md" ) ) ;
284
+ assert ! ( is_review_template_gitlab( ".gitlab/merge_request_templates/Security Fix.md" ) ) ;
285
+
286
+ // Invalid paths
287
+ assert ! ( !is_review_template_gitlab( "README.md" ) ) ;
288
+ assert ! ( !is_review_template_gitlab( ".gitlab/issue_templates/Bug.md" ) ) ;
289
+ assert ! ( !is_review_template_gitlab( ".gitlab/merge_request_templates/Default.txt" ) ) ;
290
+ assert ! ( !is_review_template_gitlab( "merge_request_templates/Default.md" ) ) ;
291
+
292
+ // Windows path separators should work
293
+ assert ! ( is_review_template_gitlab( ".gitlab\\ merge_request_templates\\ Default.md" ) ) ;
294
+ }
237
295
}
0 commit comments