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

Merge branch 'malowe/main/message-fix' into 'main'

Fix support for GH project org and ignored repos

See merge request !137
parents a5739a2a 85fa9d3c
No related branches found
No related tags found
1 merge request!137Fix support for GH project org and ignored repos
Pipeline #18226 passed
...@@ -23,8 +23,7 @@ import com.google.auto.value.AutoValue; ...@@ -23,8 +23,7 @@ import com.google.auto.value.AutoValue;
import com.google.auto.value.extension.memoized.Memoized; import com.google.auto.value.extension.memoized.Memoized;
/** /**
* Represents a project in the Eclipse API, along with the users and repos that * Represents a project in the Eclipse API, along with the users and repos that exist within the context of the project.
* exist within the context of the project.
* *
* @author Martin Lowe * @author Martin Lowe
* *
...@@ -53,6 +52,8 @@ public abstract class Project { ...@@ -53,6 +52,8 @@ public abstract class Project {
public abstract GitlabProject getGitlab(); public abstract GitlabProject getGitlab();
public abstract GithubProject getGithub();
@Nullable @Nullable
@Memoized @Memoized
public String getSpecWorkingGroup() { public String getSpecWorkingGroup() {
...@@ -71,8 +72,12 @@ public abstract class Project { ...@@ -71,8 +72,12 @@ public abstract class Project {
public static Builder builder() { public static Builder builder() {
// adds empty lists as default values // adds empty lists as default values
return new AutoValue_Project.Builder().setRepos(new ArrayList<>()).setCommitters(new ArrayList<>()) return new AutoValue_Project.Builder()
.setGithubRepos(new ArrayList<>()).setGitlabRepos(new ArrayList<>()).setGerritRepos(new ArrayList<>()); .setRepos(new ArrayList<>())
.setCommitters(new ArrayList<>())
.setGithubRepos(new ArrayList<>())
.setGitlabRepos(new ArrayList<>())
.setGerritRepos(new ArrayList<>());
} }
@AutoValue.Builder @AutoValue.Builder
...@@ -98,6 +103,8 @@ public abstract class Project { ...@@ -98,6 +103,8 @@ public abstract class Project {
public abstract Builder setGitlab(GitlabProject gitlab); public abstract Builder setGitlab(GitlabProject gitlab);
public abstract Builder setGithub(GithubProject github);
public abstract Project build(); public abstract Project build();
} }
...@@ -145,6 +152,28 @@ public abstract class Project { ...@@ -145,6 +152,28 @@ public abstract class Project {
} }
} }
@AutoValue
@JsonDeserialize(builder = AutoValue_Project_GithubProject.Builder.class)
public abstract static class GithubProject {
public abstract String getOrg();
public abstract List<String> getIgnoredRepos();
public static Builder builder() {
return new AutoValue_Project_GithubProject.Builder();
}
@AutoValue.Builder
@JsonPOJOBuilder(withPrefix = "set")
public abstract static class Builder {
public abstract Builder setOrg(String org);
public abstract Builder setIgnoredRepos(List<String> ignoredRepos);
public abstract GithubProject build();
}
}
/** /**
* Does not use autovalue as the value should be mutable. * Does not use autovalue as the value should be mutable.
* *
......
...@@ -23,6 +23,7 @@ import javax.annotation.PostConstruct; ...@@ -23,6 +23,7 @@ import javax.annotation.PostConstruct;
import javax.enterprise.context.ApplicationScoped; import javax.enterprise.context.ApplicationScoped;
import javax.inject.Inject; import javax.inject.Inject;
import org.apache.commons.lang3.StringUtils;
import org.eclipse.microprofile.config.inject.ConfigProperty; import org.eclipse.microprofile.config.inject.ConfigProperty;
import org.eclipse.microprofile.context.ManagedExecutor; import org.eclipse.microprofile.context.ManagedExecutor;
import org.eclipse.microprofile.rest.client.inject.RestClient; import org.eclipse.microprofile.rest.client.inject.RestClient;
...@@ -166,11 +167,11 @@ public class PaginationProjectsService implements ProjectsService { ...@@ -166,11 +167,11 @@ public class PaginationProjectsService implements ProjectsService {
} }
LOGGER.debug("Checking projects for repos that end with: {}", repoUrl); LOGGER.debug("Checking projects for repos that end with: {}", repoUrl);
String projectNamespace = URI.create(repoUrl).getPath().substring(1).toLowerCase();
// filter the projects based on the repo URL. At least one repo in project must // filter the projects based on the repo URL. At least one repo in project must
// match the repo URL to be valid // match the repo URL to be valid
switch (provider) { switch (provider) {
case GITLAB: case GITLAB:
String projectNamespace = URI.create(repoUrl).getPath().substring(1).toLowerCase();
return availableProjects return availableProjects
.stream() .stream()
.filter(p -> projectNamespace.startsWith(p.getGitlab().getProjectGroup() + "/") .filter(p -> projectNamespace.startsWith(p.getGitlab().getProjectGroup() + "/")
...@@ -179,7 +180,9 @@ public class PaginationProjectsService implements ProjectsService { ...@@ -179,7 +180,9 @@ public class PaginationProjectsService implements ProjectsService {
case GITHUB: case GITHUB:
return availableProjects return availableProjects
.stream() .stream()
.filter(p -> p.getGithubRepos().stream().anyMatch(re -> re.getUrl() != null && re.getUrl().endsWith(repoUrl))) .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)))
.collect(Collectors.toList()); .collect(Collectors.toList());
case GERRIT: case GERRIT:
return availableProjects return availableProjects
......
...@@ -28,6 +28,7 @@ import org.eclipsefoundation.git.eca.api.ProjectsAPI; ...@@ -28,6 +28,7 @@ import org.eclipsefoundation.git.eca.api.ProjectsAPI;
import org.eclipsefoundation.git.eca.api.models.InterestGroupData; import org.eclipsefoundation.git.eca.api.models.InterestGroupData;
import org.eclipsefoundation.git.eca.api.models.Project; import org.eclipsefoundation.git.eca.api.models.Project;
import org.eclipsefoundation.git.eca.api.models.InterestGroupData.Descriptor; import org.eclipsefoundation.git.eca.api.models.InterestGroupData.Descriptor;
import org.eclipsefoundation.git.eca.api.models.Project.GithubProject;
import org.eclipsefoundation.git.eca.api.models.Project.GitlabProject; import org.eclipsefoundation.git.eca.api.models.Project.GitlabProject;
import org.eclipsefoundation.git.eca.api.models.Project.Repo; import org.eclipsefoundation.git.eca.api.models.Project.Repo;
import org.eclipsefoundation.git.eca.api.models.Project.User; import org.eclipsefoundation.git.eca.api.models.Project.User;
...@@ -52,8 +53,6 @@ public class MockProjectsAPI implements ProjectsAPI { ...@@ -52,8 +53,6 @@ public class MockProjectsAPI implements ProjectsAPI {
r2.setUrl("http://www.github.com/eclipsefdn/test"); r2.setUrl("http://www.github.com/eclipsefdn/test");
Repo r3 = new Repo(); Repo r3 = new Repo();
r3.setUrl("http://www.github.com/eclipsefdn/prototype.git"); r3.setUrl("http://www.github.com/eclipsefdn/prototype.git");
Repo r4 = new Repo();
r4.setUrl("http://www.github.com/eclipsefdn/tck-proto");
Repo r5 = new Repo(); Repo r5 = new Repo();
r5.setUrl("/gitroot/sample/gerrit.project.git"); r5.setUrl("/gitroot/sample/gerrit.project.git");
Repo r6 = new Repo(); Repo r6 = new Repo();
...@@ -78,6 +77,7 @@ public class MockProjectsAPI implements ProjectsAPI { ...@@ -78,6 +77,7 @@ public class MockProjectsAPI implements ProjectsAPI {
.setCommitters(Arrays.asList(u1, u2)) .setCommitters(Arrays.asList(u1, u2))
.setProjectLeads(Collections.emptyList()) .setProjectLeads(Collections.emptyList())
.setGitlab(GitlabProject.builder().setIgnoredSubGroups(Collections.emptyList()).setProjectGroup("").build()) .setGitlab(GitlabProject.builder().setIgnoredSubGroups(Collections.emptyList()).setProjectGroup("").build())
.setGithub(GithubProject.builder().setIgnoredRepos(Collections.emptyList()).setOrg("").build())
.build(); .build();
src.add(p1); src.add(p1);
...@@ -93,6 +93,7 @@ public class MockProjectsAPI implements ProjectsAPI { ...@@ -93,6 +93,7 @@ public class MockProjectsAPI implements ProjectsAPI {
.setProjectLeads(Collections.emptyList()) .setProjectLeads(Collections.emptyList())
.setGitlab( .setGitlab(
GitlabProject.builder().setIgnoredSubGroups(Collections.emptyList()).setProjectGroup("eclipse/dash-second").build()) GitlabProject.builder().setIgnoredSubGroups(Collections.emptyList()).setProjectGroup("eclipse/dash-second").build())
.setGithub(GithubProject.builder().setIgnoredRepos(Collections.emptyList()).setOrg("").build())
.build(); .build();
src.add(p2); src.add(p2);
...@@ -103,13 +104,18 @@ public class MockProjectsAPI implements ProjectsAPI { ...@@ -103,13 +104,18 @@ public class MockProjectsAPI implements ProjectsAPI {
.setName("Spec project") .setName("Spec project")
.setProjectId("spec.proj") .setProjectId("spec.proj")
.setSpecProjectWorkingGroup(map) .setSpecProjectWorkingGroup(map)
.setGithubRepos(Arrays.asList(r4)) .setGithubRepos(Collections.emptyList())
.setGitlabRepos(Arrays.asList(r7)) .setGitlabRepos(Arrays.asList(r7))
.setGitlab(GitlabProject .setGitlab(GitlabProject
.builder() .builder()
.setIgnoredSubGroups(Arrays.asList("eclipse/dash/mirror")) .setIgnoredSubGroups(Arrays.asList("eclipse/dash/mirror"))
.setProjectGroup("eclipse/dash") .setProjectGroup("eclipse/dash")
.build()) .build())
.setGithub(GithubProject
.builder()
.setIgnoredRepos(Arrays.asList("eclipsefdn-tck/tck-ignored"))
.setOrg("eclipsefdn-tck")
.build())
.setCommitters(Arrays.asList(u1, u2)) .setCommitters(Arrays.asList(u1, u2))
.setProjectLeads(Collections.emptyList()) .setProjectLeads(Collections.emptyList())
.build(); .build();
......
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