Skip to content
Snippets Groups Projects

Iss #156 - Add handling of Gitlab repo field from projects API

Merged Iss #156 - Add handling of Gitlab repo field from projects API
1 unresolved thread
Merged Martin Lowe requested to merge malowe/main/156 into main
1 unresolved thread
4 files
+ 253
139
Compare changes
  • Side-by-side
  • Inline
Files
4
@@ -32,8 +32,8 @@ import jakarta.enterprise.context.ApplicationScoped;
import jakarta.inject.Inject;
/**
* Helps manage projects by providing filters on top of the generic service as well as operations like adapting interest
* groups to projects for easier processing.
* Helps manage projects by providing filters on top of the generic service as well as operations like adapting interest groups to projects
* for easier processing.
*
* @author Martin Lowe
*
@@ -74,18 +74,9 @@ public final class ProjectHelper {
// match the repo URL to be valid
switch (provider) {
case GITLAB:
return availableProjects
.stream()
.filter(p -> projectNamespace.startsWith(p.getGitlab().getProjectGroup() + "/")
&& p.getGitlab().getIgnoredSubGroups().stream().noneMatch(sg -> projectNamespace.startsWith(sg + "/")))
.toList();
return availableProjects.stream().filter(p -> doesProjectMatchGitlabRepos(p, repoUrl, projectNamespace)).toList();
case GITHUB:
return availableProjects
.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();
return availableProjects.stream().filter(p -> doesProjectMatchGithubRepos(p, repoUrl, projectNamespace)).toList();
case GERRIT:
return availableProjects
.stream()
@@ -164,4 +155,34 @@ public final class ProjectHelper {
.setSpecProjectWorkingGroup(Collections.emptyMap())
.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));
}
}
Loading