use of io.jenkins.blueocean.rest.model.BlueOrganization in project blueocean-plugin by jenkinsci.
the class PipelineJobFiltersTest method testFolderJobFilter.
@Test
public void testFolderJobFilter() {
BlueOrganization organization = mockOrganization();
OrganizationFolder organizationFolder = mockOrgFolder(organization);
assertFalse(new PipelineJobFilters.FolderJobFilter().getFilter().apply(organizationFolder));
}
use of io.jenkins.blueocean.rest.model.BlueOrganization in project blueocean-plugin by jenkinsci.
the class PipelineJobFiltersTest method testIsPullRequest.
@Test
public void testIsPullRequest() {
BlueOrganization organization = mockOrganization();
OrganizationFolder organizationFolder = mockOrgFolder(organization);
PullRequestSCMHead changeRequestSCMHead = mock(PullRequestSCMHead.class);
mockStatic(SCMHead.HeadByItem.class);
when(SCMHead.HeadByItem.findHead(organizationFolder)).thenReturn(changeRequestSCMHead);
assertTrue(PipelineJobFilters.isPullRequest(organizationFolder));
assertFalse(new PipelineJobFilters.OriginFilter().getFilter().apply(organizationFolder));
assertTrue(new PipelineJobFilters.PullRequestFilter().getFilter().apply(organizationFolder));
}
use of io.jenkins.blueocean.rest.model.BlueOrganization in project blueocean-plugin by jenkinsci.
the class PipelineSearch method search.
@Override
public Pageable<BluePipeline> search(Query q) {
String s = q.param(EXCLUDED_FROM_FLATTENING_PARAM);
ItemGroup orgItemGroup = findItemGroup(q);
List<Class> excludeList = new ArrayList<>();
if (s != null) {
for (String s1 : s.split(",")) {
Class c = null;
try {
c = Class.forName(s1);
} catch (ClassNotFoundException e) {
try {
// TODO: There should be better ways to find a class from a plugin.
Plugin p = Jenkins.getInstance().getPlugin("blueocean-pipeline-api-impl");
if (p != null) {
c = p.getWrapper().classLoader.loadClass(s1);
} else {
logger.error("blueocean-pipeline-api-impl plugin not found!");
}
} catch (ClassNotFoundException e1) {
logger.error(e.getMessage(), e1);
}
// ignored, give other OmniSearch implementations chance, they might handle it
// throw new ServiceException.BadRequestException(String.format("%s parameter has invalid value: %s", EXCLUDED_FROM_FLATTENING_PARAM, s1), e);
}
if (c != null) {
excludeList.add(c);
}
}
}
Collection<Item> items = new ArrayList<>();
if (!excludeList.isEmpty()) {
for (Item item : getAllItems(orgItemGroup)) {
if (!exclude(item.getParent(), excludeList)) {
items.add(item);
}
}
} else {
items = getAllItems(orgItemGroup);
}
items = ContainerFilter.filter(items);
BlueOrganization org = OrganizationFactory.getInstance().getContainingOrg(orgItemGroup);
if (org == null) {
throw new ServiceException.UnexpectedErrorException("Could not find organization");
}
final Iterator<BluePipeline> pipelineIterator = new PipelineContainerImpl(org, orgItemGroup, org).getPipelines(items);
final List<BluePipeline> pipelines = new ArrayList<>();
String pipeline = q.param(getType());
if (pipeline == null) {
return Pageables.wrap(new Iterable<BluePipeline>() {
@Override
public Iterator<BluePipeline> iterator() {
return pipelineIterator;
}
});
} else {
GlobMatcher matcher = pipeline.contains("*") ? new GlobMatcher(pipeline) : null;
if (matcher != null) {
while (pipelineIterator.hasNext()) {
BluePipeline p = pipelineIterator.next();
String decodedName = null;
try {
decodedName = URLDecoder.decode(p.getFullDisplayName(), "UTF-8");
} catch (UnsupportedEncodingException e) {
throw new UnexpectedErrorException("Could not decode '" + p.getFullDisplayName() + "'", e);
}
if (matcher.matches(decodedName)) {
pipelines.add(p);
}
}
} else {
while (pipelineIterator.hasNext()) {
BluePipeline p = pipelineIterator.next();
if (pipeline.equals(p.getFullDisplayName())) {
pipelines.add(p);
}
}
}
return Pageables.wrap(pipelines);
}
}
use of io.jenkins.blueocean.rest.model.BlueOrganization in project blueocean-plugin by jenkinsci.
the class BluePipelineFactory method resolve.
/**
* Given a Job in Jenkins, map that to corresponding blue ocean API object,
* for example so that you can get its URL.
*/
public static Resource resolve(Item item) {
BlueOrganization org = OrganizationFactory.getInstance().getContainingOrg(item);
if (org == null) {
return null;
}
Item nextStep = findNextStep(Jenkins.getInstance(), item);
for (BluePipelineFactory f : all()) {
Resource r = f.resolve(nextStep, org.getPipelines(), item, org);
if (r != null)
return r;
}
return null;
}
use of io.jenkins.blueocean.rest.model.BlueOrganization in project blueocean-plugin by jenkinsci.
the class GithubOrganizationFolderTest method testGithubOrgFolderCreation.
@Test
public void testGithubOrgFolderCreation() throws IOException {
OrganizationFolder organizationFolder = j.jenkins.createProject(OrganizationFolder.class, "orgFolder1");
BlueOrganization blueOrganization = mock(BlueOrganization.class);
GithubOrganizationFolder githubOrganizationFolder = new GithubOrganizationFolder(blueOrganization, organizationFolder, new Link("abc"));
githubOrganizationFolder.addRepo("repo1", new GithubOrganizationFolder.BlueRepositoryProperty() {
@Override
public boolean meetsIndexingCriteria() {
return false;
}
});
assertEquals("orgFolder1", githubOrganizationFolder.getName());
assertEquals(1, githubOrganizationFolder.repos().size());
}
Aggregations