Search in sources :

Example 6 with BlueOrganization

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));
}
Also used : OrganizationFolder(jenkins.branch.OrganizationFolder) BlueOrganization(io.jenkins.blueocean.rest.model.BlueOrganization) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 7 with BlueOrganization

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));
}
Also used : OrganizationFolder(jenkins.branch.OrganizationFolder) SCMHead(jenkins.scm.api.SCMHead) PullRequestSCMHead(org.jenkinsci.plugins.github_branch_source.PullRequestSCMHead) BlueOrganization(io.jenkins.blueocean.rest.model.BlueOrganization) PullRequestSCMHead(org.jenkinsci.plugins.github_branch_source.PullRequestSCMHead) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 8 with BlueOrganization

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);
    }
}
Also used : GlobMatcher(io.jenkins.blueocean.service.embedded.util.GlobMatcher) BlueOrganization(io.jenkins.blueocean.rest.model.BlueOrganization) ArrayList(java.util.ArrayList) UnexpectedErrorException(io.jenkins.blueocean.commons.ServiceException.UnexpectedErrorException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) Item(hudson.model.Item) ItemGroup(hudson.model.ItemGroup) Iterator(java.util.Iterator) BluePipeline(io.jenkins.blueocean.rest.model.BluePipeline) Plugin(hudson.Plugin)

Example 9 with BlueOrganization

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;
}
Also used : TopLevelItem(hudson.model.TopLevelItem) Item(hudson.model.Item) BlueOrganization(io.jenkins.blueocean.rest.model.BlueOrganization) Resource(io.jenkins.blueocean.rest.model.Resource)

Example 10 with BlueOrganization

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());
}
Also used : OrganizationFolder(jenkins.branch.OrganizationFolder) BlueOrganization(io.jenkins.blueocean.rest.model.BlueOrganization) Link(io.jenkins.blueocean.rest.hal.Link) PipelineBaseTest(io.jenkins.blueocean.rest.impl.pipeline.PipelineBaseTest) Test(org.junit.Test)

Aggregations

BlueOrganization (io.jenkins.blueocean.rest.model.BlueOrganization)19 Item (hudson.model.Item)4 Link (io.jenkins.blueocean.rest.hal.Link)4 BluePipeline (io.jenkins.blueocean.rest.model.BluePipeline)4 ArrayList (java.util.ArrayList)4 Test (org.junit.Test)4 Job (hudson.model.Job)3 Resource (io.jenkins.blueocean.rest.model.Resource)3 OrganizationFolder (jenkins.branch.OrganizationFolder)3 Run (hudson.model.Run)2 User (hudson.model.User)2 ModifiableTopLevelItemGroup (jenkins.model.ModifiableTopLevelItemGroup)2 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)2 CredentialsStore (com.cloudbees.plugins.credentials.CredentialsStore)1 Plugin (hudson.Plugin)1 FreeStyleProject (hudson.model.FreeStyleProject)1 ItemGroup (hudson.model.ItemGroup)1 Project (hudson.model.Project)1 Queue (hudson.model.Queue)1 TopLevelItem (hudson.model.TopLevelItem)1