Skip to content

Commit a16ea19

Browse files
authored
Merge pull request #9768 from rhmndnt/feature/forge/enable-gitlab-template
Enable Gitlab merge request template
2 parents 00c89af + 82dd114 commit a16ea19

File tree

1 file changed

+114
-53
lines changed

1 file changed

+114
-53
lines changed

crates/gitbutler-forge/src/review.rs

Lines changed: 114 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -126,18 +126,18 @@ fn is_valid_review_template_path_github(path: &path::Path) -> bool {
126126
}
127127

128128
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
131132
}
132133

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")
136137
}
137138

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())
141141
}
142142

143143
fn get_bitbucket_directory_path(root_path: &path::Path) -> path::PathBuf {
@@ -176,62 +176,123 @@ mod tests {
176176

177177
use super::*;
178178

179+
fn p(path: &str) -> &Path {
180+
Path::new(path)
181+
}
182+
179183
#[test]
180184
fn test_is_valid_review_template_path_github() {
181-
let valid_review_template_path_1 = Path::new(".github/PULL_REQUEST_TEMPLATE.md");
182-
let valid_review_template_path_2 = Path::new(".github/pull_request_template.md");
183-
let valid_review_template_path_3 = Path::new(".github/PULL_REQUEST_TEMPLATE/something.md");
184-
let valid_review_template_path_4 = Path::new(".docs/PULL_REQUEST_TEMPLATE.md");
185-
let valid_review_template_path_5 = Path::new("PULL_REQUEST_TEMPLATE.md");
186-
let invalid_review_template_path = Path::new("README.md");
187-
188-
assert!(is_valid_review_template_path_github(
189-
valid_review_template_path_1,
190-
));
191-
assert!(is_valid_review_template_path_github(
192-
valid_review_template_path_2,
193-
));
194-
assert!(is_valid_review_template_path_github(
195-
valid_review_template_path_3,
196-
));
197-
assert!(is_valid_review_template_path_github(
198-
valid_review_template_path_4,
199-
));
200-
assert!(is_valid_review_template_path_github(
201-
valid_review_template_path_5,
202-
));
203-
assert!(!is_valid_review_template_path_github(
204-
invalid_review_template_path,
205-
));
185+
assert!(is_valid_review_template_path_github(p(
186+
".github/PULL_REQUEST_TEMPLATE.md"
187+
)));
188+
assert!(is_valid_review_template_path_github(p(
189+
".github/pull_request_template.md"
190+
)));
191+
assert!(is_valid_review_template_path_github(p(
192+
".github/PULL_REQUEST_TEMPLATE/something.md"
193+
)));
194+
assert!(is_valid_review_template_path_github(p(
195+
".docs/PULL_REQUEST_TEMPLATE.md"
196+
)));
197+
assert!(is_valid_review_template_path_github(p(
198+
"PULL_REQUEST_TEMPLATE.md"
199+
)));
200+
assert!(!is_valid_review_template_path_github(p("README.md"),));
206201
}
207202

208203
#[test]
209204
fn test_is_valid_review_template_path_github_windows() {
210-
let valid_review_template_path_1 = Path::new(".github\\PULL_REQUEST_TEMPLATE.md");
211-
let valid_review_template_path_2 = Path::new(".github\\pull_request_template.md");
212-
let valid_review_template_path_3 =
213-
Path::new(".github\\PULL_REQUEST_TEMPLATE\\something.md");
214-
let valid_review_template_path_4 = Path::new(".docs\\PULL_REQUEST_TEMPLATE.md");
215-
let valid_review_template_path_5 = Path::new("PULL_REQUEST_TEMPLATE.md");
216-
let invalid_review_template_path = Path::new("README.md");
217-
218-
assert!(is_valid_review_template_path_github(
219-
valid_review_template_path_1,
205+
assert!(is_valid_review_template_path_github(p(
206+
".github\\PULL_REQUEST_TEMPLATE.md"
207+
),));
208+
assert!(is_valid_review_template_path_github(p(
209+
".github\\pull_request_template.md"
210+
),));
211+
assert!(is_valid_review_template_path_github(p(
212+
".github\\PULL_REQUEST_TEMPLATE\\something.md"
213+
),));
214+
assert!(is_valid_review_template_path_github(p(
215+
".docs\\PULL_REQUEST_TEMPLATE.md"
216+
),));
217+
assert!(is_valid_review_template_path_github(p(
218+
"PULL_REQUEST_TEMPLATE.md"
219+
),));
220+
assert!(!is_valid_review_template_path_github(p("README.md"),));
221+
}
222+
223+
#[test]
224+
fn test_is_valid_review_template_path_gitlab() {
225+
assert!(is_valid_review_template_path_gitlab(p(
226+
".gitlab/merge_request_templates/Default.md"
227+
)));
228+
assert!(is_valid_review_template_path_gitlab(p(
229+
".gitlab/merge_request_templates/Documentation.md"
230+
)));
231+
assert!(is_valid_review_template_path_gitlab(p(
232+
".gitlab/merge_request_templates/Security Fix.md"
233+
)));
234+
assert!(!is_valid_review_template_path_gitlab(p("README.md")));
235+
assert!(!is_valid_review_template_path_gitlab(p(
236+
".gitlab/issue_templates/Bug.md"
237+
)));
238+
assert!(!is_valid_review_template_path_gitlab(p(
239+
".gitlab/merge_request_templates/Default.txt"
240+
)));
241+
}
242+
243+
#[test]
244+
fn test_is_valid_review_template_path_gitlab_windows() {
245+
assert!(is_valid_review_template_path_gitlab(p(
246+
".gitlab\\merge_request_templates\\Default.md"
247+
)));
248+
assert!(is_valid_review_template_path_gitlab(p(
249+
".gitlab\\merge_request_templates\\Documentation.md"
250+
)));
251+
assert!(is_valid_review_template_path_gitlab(p(
252+
".gitlab\\merge_request_templates\\Security Fix.md"
253+
)));
254+
assert!(!is_valid_review_template_path_gitlab(p("README.md")));
255+
assert!(!is_valid_review_template_path_gitlab(p(
256+
".gitlab\\issue_templates\\Bug.md"
257+
)));
258+
assert!(!is_valid_review_template_path_gitlab(p(
259+
".gitlab\\merge_request_templates\\Default.txt"
260+
)));
261+
}
262+
263+
#[test]
264+
fn test_get_gitlab_directory_path() {
265+
let root_path = p("/path/to/project");
266+
let gitlab_path = get_gitlab_directory_path(root_path);
267+
assert_eq!(gitlab_path, p("/path/to/project/.gitlab"));
268+
}
269+
270+
#[test]
271+
fn test_is_review_template_gitlab() {
272+
// Valid GitLab merge request templates
273+
assert!(is_review_template_gitlab(
274+
".gitlab/merge_request_templates/Default.md"
220275
));
221-
assert!(is_valid_review_template_path_github(
222-
valid_review_template_path_2,
276+
assert!(is_review_template_gitlab(
277+
".gitlab/merge_request_templates/Documentation.md"
223278
));
224-
assert!(is_valid_review_template_path_github(
225-
valid_review_template_path_3,
279+
assert!(is_review_template_gitlab(
280+
".gitlab/merge_request_templates/Security Fix.md"
226281
));
227-
assert!(is_valid_review_template_path_github(
228-
valid_review_template_path_4,
282+
283+
// Invalid paths
284+
assert!(!is_review_template_gitlab("README.md"));
285+
assert!(!is_review_template_gitlab(".gitlab/issue_templates/Bug.md"));
286+
assert!(!is_review_template_gitlab(
287+
".gitlab/merge_request_templates/Default.txt"
229288
));
230-
assert!(is_valid_review_template_path_github(
231-
valid_review_template_path_5,
289+
assert!(!is_review_template_gitlab(
290+
"merge_request_templates/Default.md"
232291
));
233-
assert!(!is_valid_review_template_path_github(
234-
invalid_review_template_path,
292+
293+
// Windows path separators should work
294+
assert!(is_review_template_gitlab(
295+
".gitlab\\merge_request_templates\\Default.md"
235296
));
236297
}
237298
}

0 commit comments

Comments
 (0)