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

Merge branch 'malowe/master/66' into 'master'

Iss. #66 - Add support for new Gitlab nesting strategy

See merge request eclipsefdn/it/api/git-eca-rest-api!84
parents 9eff7663 b97f2815
No related branches found
No related tags found
1 merge request!84Iss. #66 - Add support for new Gitlab nesting strategy
Pipeline #5536 passed
......@@ -45,6 +45,8 @@ public abstract class Project {
public abstract List<Repo> getGerritRepos();
public abstract Object getSpecProjectWorkingGroup();
public abstract GitlabProject getGitlab();
@Nullable
@Memoized
......@@ -86,6 +88,8 @@ public abstract class Project {
public abstract Builder setGerritRepos(List<Repo> gerritRepos);
public abstract Builder setSpecProjectWorkingGroup(Object specProjectWorkingGroup);
public abstract Builder setGitlab(GitlabProject gitlab);
public abstract Project build();
}
......@@ -112,6 +116,28 @@ public abstract class Project {
}
}
@AutoValue
@JsonDeserialize(builder = AutoValue_Project_GitlabProject.Builder.class)
public static abstract class GitlabProject {
public abstract String getProjectGroup();
public abstract List<String> getIgnoredSubGroups();
public static Builder builder() {
return new AutoValue_Project_GitlabProject.Builder();
}
@AutoValue.Builder
@JsonPOJOBuilder(withPrefix = "set")
public abstract static class Builder {
public abstract Builder setProjectGroup(String projectGroup);
public abstract Builder setIgnoredSubGroups(List<String> ignoredSubGroups);
public abstract GitlabProject build();
}
}
/**
* Does not use autovalue as the value should be mutable.
*
......
......@@ -9,6 +9,7 @@
package org.eclipsefoundation.git.eca.resource;
import java.net.MalformedURLException;
import java.net.URI;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
......@@ -113,8 +114,8 @@ public class ValidationResource {
filteredProjects.isEmpty() ? null : filteredProjects.get(0).getProjectId());
for (Commit c : req.getCommits()) {
// get the current status if present
Optional<CommitValidationStatus> status = statuses.stream().filter(s -> c.getHash().equals(s.getCommitHash()))
.findFirst();
Optional<CommitValidationStatus> status = statuses.stream()
.filter(s -> c.getHash().equals(s.getCommitHash())).findFirst();
// skip the commit validation if already passed
if (status.isPresent() && status.get().getErrors().isEmpty()) {
r.addMessage(c.getHash(), "Commit was previously validated, skipping processing",
......@@ -386,9 +387,11 @@ public class ValidationResource {
// filter the projects based on the repo URL. At least one repo in project must
// match the repo URL to be valid
if (ProviderType.GITLAB.equals(req.getProvider())) {
// get the path of the project, removing the leading slash
String projectNamespace = URI.create(repoUrl).getPath().substring(1).toLowerCase();
return availableProjects.stream()
.filter(p -> p.getGitlabRepos().stream()
.anyMatch(re -> re.getUrl() != null && re.getUrl().endsWith(repoUrl)))
.filter(p -> projectNamespace.startsWith(p.getGitlab().getProjectGroup() + "/") && p.getGitlab()
.getIgnoredSubGroups().stream().noneMatch(sg -> projectNamespace.startsWith(sg + "/")))
.collect(Collectors.toList());
} else if (ProviderType.GITHUB.equals(req.getProvider())) {
return availableProjects.stream()
......
......@@ -571,7 +571,7 @@ class ValidationResourceTest {
commits.add(c1);
ValidationRequest vr = ValidationRequest.builder().setStrictMode(false).setProvider(ProviderType.GITLAB)
.setRepoUrl(new URI("https://gitlab.eclipse.org/eclipse/dash/dash.handbook.test")).setCommits(commits)
.setRepoUrl(new URI("https://gitlab.eclipse.org/eclipse/dash-second/dash.handbook.test")).setCommits(commits)
.build();
// test output w/ assertions
// Should be valid as bots should only commit on their own projects (including aliases)
......@@ -579,7 +579,7 @@ class ValidationResourceTest {
}
@Test
void validateBotCommiterAccessGitlab_untracked() throws URISyntaxException {
void validateBotCommiterAccessGitlab_ignored() throws URISyntaxException {
// set up test users
GitUser g1 = GitUser.builder().setName("protobot-gh").setMail("2.bot-github@eclipse.org").build();
......@@ -591,7 +591,7 @@ class ValidationResourceTest {
commits.add(c1);
ValidationRequest vr = ValidationRequest.builder().setStrictMode(false).setProvider(ProviderType.GITLAB)
.setRepoUrl(new URI("https://gitlab.eclipse.org/eclipse/dash/dash.handbook.untracked"))
.setRepoUrl(new URI("https://gitlab.eclipse.org/eclipse/dash/mirror/dash.handbook.untracked"))
.setCommits(commits).build();
// test output w/ assertions
// Should be valid as bots can commit on any untracked project (legacy support)
......@@ -611,7 +611,7 @@ class ValidationResourceTest {
commits.add(c1);
ValidationRequest vr = ValidationRequest.builder().setStrictMode(false).setProvider(ProviderType.GITLAB)
.setRepoUrl(new URI("https://gitlab.eclipse.org/eclipse/dash/dash.handbook.test")).setCommits(commits)
.setRepoUrl(new URI("https://gitlab.eclipse.org/eclipse/dash-second/dash.handbook.test")).setCommits(commits)
.build();
// test output w/ assertions
// Should be invalid as bots should only commit on their own projects
......
......@@ -22,6 +22,7 @@ import javax.enterprise.context.ApplicationScoped;
import org.eclipse.microprofile.rest.client.inject.RestClient;
import org.eclipsefoundation.git.eca.api.ProjectsAPI;
import org.eclipsefoundation.git.eca.model.Project;
import org.eclipsefoundation.git.eca.model.Project.GitlabProject;
import org.eclipsefoundation.git.eca.model.Project.Repo;
import org.eclipsefoundation.git.eca.model.Project.User;
......@@ -54,28 +55,32 @@ public class MockProjectsAPI implements ProjectsAPI {
Repo r7 = new Repo();
r7.setUrl("https://gitlab.eclipse.org/eclipse/dash/dash.git");
Repo r8 = new Repo();
r8.setUrl("https://gitlab.eclipse.org/eclipse/dash/dash.handbook.test");
r8.setUrl("https://gitlab.eclipse.org/eclipse/dash-second/dash.handbook.test");
// sample users, correlates to users in Mock projects API
User u1 = User.builder().setUrl("").setUsername("da_wizz").build();
User u2 = User.builder().setUrl("").setUsername("grunter").build();
// projects
Project p1 = Project.builder().setName("Sample project").setProjectId("sample.proj")
.setSpecProjectWorkingGroup(Collections.emptyList()).setGithubRepos(Arrays.asList(r1, r2))
.setGerritRepos(Arrays.asList(r5)).setCommitters(Arrays.asList(u1, u2)).build();
.setGerritRepos(Arrays.asList(r5)).setCommitters(Arrays.asList(u1, u2)).setGitlab(
GitlabProject.builder().setIgnoredSubGroups(Collections.emptyList()).setProjectGroup("").build()).build();
src.add(p1);
Project p2 = Project.builder().setName("Prototype thing").setProjectId("sample.proto")
.setSpecProjectWorkingGroup(Collections.emptyList()).setGithubRepos(Arrays.asList(r3))
.setGerritRepos(Arrays.asList(r6)).setGitlabRepos(Arrays.asList(r8)).setCommitters(Arrays.asList(u2))
.setGerritRepos(Arrays.asList(r6)).setGitlabRepos(Arrays.asList(r8)).setCommitters(Arrays.asList(u2)).setGitlab(
GitlabProject.builder().setIgnoredSubGroups(Collections.emptyList()).setProjectGroup("eclipse/dash-second").build())
.build();
src.add(p2);
Map<String, String> map = new HashMap<>();
map.put("id", "proj1");
Project p3 = Project.builder().setName("Spec project").setProjectId("spec.proj").setSpecProjectWorkingGroup(map)
.setGithubRepos(Arrays.asList(r4)).setGitlabRepos(Arrays.asList(r7))
.setGithubRepos(Arrays.asList(r4)).setGitlabRepos(Arrays.asList(r7)).setGitlab(
GitlabProject.builder().setIgnoredSubGroups(Arrays.asList("eclipse/dash/mirror")).setProjectGroup("eclipse/dash").build())
.setCommitters(Arrays.asList(u1, u2)).build();
src.add(p3);
}
......
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