Skip to content
Snippets Groups Projects
Commit 8d456262 authored by Martin Lowe's avatar Martin Lowe :flag_ca:
Browse files

Separate out logic for matching Github/lab repos into own methods

This was done to make the code a little more readable and add additional
documentation.
parent 9bb34460
No related branches found
No related tags found
1 merge request!185Iss #156 - Add handling of Gitlab repo field from projects API
Pipeline #43568 passed
...@@ -74,22 +74,9 @@ public final class ProjectHelper { ...@@ -74,22 +74,9 @@ public final class ProjectHelper {
// match the repo URL to be valid // match the repo URL to be valid
switch (provider) { switch (provider) {
case GITLAB: case GITLAB:
return availableProjects return availableProjects.stream().filter(p -> doesProjectMatchGitlabRepos(p, repoUrl, projectNamespace)).toList();
.stream()
.filter(p -> p.getGitlabRepos().stream().anyMatch(re -> re.getUrl() != null && re.getUrl().endsWith(repoUrl))
|| (projectNamespace.startsWith(p.getGitlab().getProjectGroup() + "/") && p
.getGitlab()
.getIgnoredSubGroups()
.stream()
.noneMatch(sg -> projectNamespace.startsWith(sg + "/"))))
.toList();
case GITHUB: case GITHUB:
return availableProjects return availableProjects.stream().filter(p -> doesProjectMatchGithubRepos(p, repoUrl, projectNamespace)).toList();
.stream()
.filter(p -> p.getGithubRepos().stream().anyMatch(re -> re.getUrl() != null && re.getUrl().endsWith(repoUrl))
|| (StringUtils.isNotBlank(p.getGithub().getOrg()) && projectNamespace.startsWith(p.getGithub().getOrg())
&& p.getGithub().getIgnoredRepos().stream().noneMatch(repoUrl::endsWith)))
.toList();
case GERRIT: case GERRIT:
return availableProjects return availableProjects
.stream() .stream()
...@@ -168,4 +155,34 @@ public final class ProjectHelper { ...@@ -168,4 +155,34 @@ public final class ProjectHelper {
.setSpecProjectWorkingGroup(Collections.emptyMap()) .setSpecProjectWorkingGroup(Collections.emptyMap())
.build(); .build();
} }
/**
* Check if the passed projects Gitlab repos field has a match for the given repo URL, or if the Gitlab project group is set and matches
* the project namespace of the request.
*
* @param p project being checked
* @param repoUrl URL of the repo that was the origin of the request
* @param projectNamespace the namespace of the project of the repo that created the request.
* @return true if the project is a match via Gitlab repos or project namespace, false otherwise
*/
private boolean doesProjectMatchGitlabRepos(Project p, String repoUrl, String projectNamespace) {
return p.getGitlabRepos().stream().anyMatch(re -> re.getUrl() != null && re.getUrl().endsWith(repoUrl))
|| (projectNamespace.startsWith(p.getGitlab().getProjectGroup() + "/")
&& p.getGitlab().getIgnoredSubGroups().stream().noneMatch(sg -> projectNamespace.startsWith(sg + "/")));
}
/**
* Check if the passed projects Github repos field has a match for the given repo URL, or if the Github project organization is set and
* matches the project namespace of the request.
*
* @param p project being checked
* @param repoUrl URL of the repo that was the origin of the request
* @param projectNamespace the namespace of the project of the repo that created the request.
* @return true if the project is a match via Github repos or organization, false otherwise
*/
private boolean doesProjectMatchGithubRepos(Project p, String repoUrl, String projectNamespace) {
return p.getGithubRepos().stream().anyMatch(re -> re.getUrl() != null && re.getUrl().endsWith(repoUrl))
|| (StringUtils.isNotBlank(p.getGithub().getOrg()) && projectNamespace.startsWith(p.getGithub().getOrg())
&& p.getGithub().getIgnoredRepos().stream().noneMatch(repoUrl::endsWith));
}
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment