jenkins.branch.OrganizationFolder Java Examples

The following examples show how to use jenkins.branch.OrganizationFolder. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: BitbucketOrg.java    From blueocean-plugin with MIT License 6 votes vote down vote up
@Override
public boolean isJenkinsOrganizationPipeline() {
    for(TopLevelItem item: Jenkins.getInstance().getItems()){
        if(item instanceof OrganizationFolder){
            OrganizationFolder folder = (OrganizationFolder) item;
            for(SCMNavigator navigator: folder.getNavigators()) {
                if (navigator instanceof BitbucketSCMNavigator) {
                    BitbucketSCMNavigator scmNavigator = (BitbucketSCMNavigator) navigator;
                    if(scmNavigator.getRepoOwner().equals(getName())){
                        return true;
                    }
                }
            }
        }
    }
    return false;
}
 
Example #2
Source File: GithubScmContentProvider.java    From blueocean-plugin with MIT License 6 votes vote down vote up
@Override
public String getApiUrl(@Nonnull Item item) {
    if (item instanceof OrganizationFolder) {
        List<SCMNavigator> navigators = ((OrganizationFolder) item).getSCMNavigators();
        if ((!navigators.isEmpty() && navigators.get(0) instanceof GitHubSCMNavigator)) {
            return ((GitHubSCMNavigator) navigators.get(0)).getApiUri();
        }
    } else if (item instanceof MultiBranchProject) {
        List<SCMSource> sources = ((MultiBranchProject) item).getSCMSources();
        if ((!sources.isEmpty() && sources.get(0) instanceof GitHubSCMSource)) {
            return ((GitHubSCMSource) sources.get(0)).getApiUri();
        }
    }

    return null;
}
 
Example #3
Source File: AbstractGithubOrganization.java    From blueocean-plugin with MIT License 6 votes vote down vote up
@Override
public boolean isJenkinsOrganizationPipeline() {
    for(TopLevelItem item: Jenkins.getInstance().getItems()){
        if(item instanceof OrganizationFolder){
            OrganizationFolder folder = (OrganizationFolder) item;
            for(SCMNavigator navigator: folder.getNavigators()) {
                if (navigator instanceof GitHubSCMNavigator) {
                    GitHubSCMNavigator scmNavigator = (GitHubSCMNavigator) navigator;
                    if(scmNavigator.getRepoOwner().equals(getName())){
                        return true;
                    }
                }
            }
        }
    }
    return false;

}
 
Example #4
Source File: ScmResourceImpl.java    From blueocean-plugin with MIT License 6 votes vote down vote up
private @Nonnull User checkPermission(){
    ACL acl;
    if(item.getParent() != null && item.getParent() instanceof OrganizationFolder){
        acl = ((OrganizationFolder) item.getParent()).getACL();
    }else{
        acl = item.getACL();
    }
    Authentication a = Jenkins.getAuthentication();
    User user = User.get(a);
    if(user == null){
        throw new ServiceException.UnauthorizedException("No logged in user found");
    }
    if(!acl.hasPermission(a, Item.CONFIGURE)){
        throw new ServiceException.ForbiddenException(
                String.format("User %s must have Job configure permission to access content", a.getName()));
    }

    return user;
}
 
Example #5
Source File: ScmContentProviderParams.java    From blueocean-plugin with MIT License 6 votes vote down vote up
@SuppressWarnings("unchecked")
public ScmContentProviderParams(Item item) {
    String apiUrl = null;
    String owner=null;
    String repo = null;
    if (item instanceof OrganizationFolder) {
        List<SCMNavigator> navigators = ((OrganizationFolder) item).getSCMNavigators();
        if (!navigators.isEmpty()) {
            SCMNavigator navigator = navigators.get(0);
            apiUrl = apiUrl(navigator);
            owner = owner(navigator);
        }
    } else if (item instanceof MultiBranchProject) {
        List<SCMSource> sources = ((MultiBranchProject) item).getSCMSources();
        if (!sources.isEmpty()) {
            SCMSource source = sources.get(0);
            apiUrl = apiUrl(source);
            owner = owner(source);
            repo = repo(source);
        }
    }
    this.apiUrl = apiUrl == null ? GitHubSCMSource.GITHUB_URL : apiUrl;;
    this.owner = owner;
    this.repo = repo;
    this.credentials = getCredentialForUser(item, this.apiUrl);;
}
 
Example #6
Source File: GithubOrganisationFolderTest.java    From configuration-as-code-plugin with MIT License 5 votes vote down vote up
@ConfiguredWithCode("GithubOrganisationFolderTest.yml")
public void configure_github_organisation_folder_seed_job() throws Exception {
    final TopLevelItem job = Jenkins.get().getItem("ndeloof");
    assertNotNull(job);
    assertTrue(job instanceof OrganizationFolder);
    OrganizationFolder folder = (OrganizationFolder) job;
    assertEquals(1, folder.getNavigators().size());
    final GitHubSCMNavigator github = folder.getNavigators().get(GitHubSCMNavigator.class);
    assertNotNull(github);
    assertEquals("ndeloof", github.getRepoOwner());
}
 
Example #7
Source File: OrganizationFolderTest2.java    From blueocean-plugin with MIT License 5 votes vote down vote up
@Test
public void testWorkflowPipieline() throws Exception {
    Map<String, Object> expectedDisabledResponse = new HashMap<>();
    expectedDisabledResponse.put("message", "Cannot disable this item");
    expectedDisabledResponse.put("code", Integer.valueOf(405));
    expectedDisabledResponse.put("errors", Collections.emptyList());

    OrganizationFolder orgFolder = j.jenkins.createProject(OrganizationFolder.class, "orgFolder1");
    login();
    assertNull(get("/organizations/jenkins/pipelines/" + orgFolder.getFullName() + "/").get("disabled"));

    assertThat(expectedDisabledResponse, is(put("/organizations/jenkins/pipelines/" + orgFolder.getFullName() + "/disable", "{}", 405)));
    assertThat(expectedDisabledResponse, is(put("/organizations/jenkins/pipelines/" + orgFolder.getFullName() + "/enable", "{}", 405)));
}
 
Example #8
Source File: OrganizationFolderTest2.java    From blueocean-plugin with MIT License 5 votes vote down vote up
@Override
protected OrganizationFolderPipelineImpl getFolder(jenkins.branch.OrganizationFolder folder, Reachable parent, BlueOrganization organization) {
    if (folder.getName() == "orgFolder1") {
        return new FakeOrg(organization, folder, parent.getLink());
    }
    return null;
}
 
Example #9
Source File: OrganizationFolderTest.java    From blueocean-plugin with MIT License 5 votes vote down vote up
@Override
protected OrganizationFolderPipelineImpl getFolder(jenkins.branch.OrganizationFolder folder, Reachable parent, BlueOrganization organization) {
    if (folder.getName() != "orgFolder1") {
        OrganizationFolder orgFolder = mockOrgFolder(organization);
        return new OrganizationFolderPipelineImpl(organization, orgFolder, organization.getLink().rel("/pipelines/")) {
        };
    }
    return null;
}
 
Example #10
Source File: OrganizationFolderTest.java    From blueocean-plugin with MIT License 5 votes vote down vote up
static OrganizationFolder mockOrgFolder(BlueOrganization organization){
    OrganizationFolder orgFolder = PowerMockito.mock(OrganizationFolder.class);

    OrganizationFactory organizationFactory = mock(OrganizationFactory.class);
    PowerMockito.mockStatic(OrganizationFactory.class);
    PowerMockito.when(OrganizationFactory.getInstance()).thenReturn(organizationFactory);
    when(organizationFactory.getContainingOrg((ItemGroup) orgFolder)).thenReturn(organization);
    PowerMockito.when(orgFolder.getDisplayName()).thenReturn("vivek");
    PowerMockito.when(orgFolder.getName()).thenReturn("vivek");
    PowerMockito.when(orgFolder.getFullName()).thenReturn("vivek");

    return orgFolder;
}
 
Example #11
Source File: PipelineJobFiltersTest.java    From blueocean-plugin with MIT License 5 votes vote down vote up
@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));
}
 
Example #12
Source File: OrganizationFolderPipelineImpl.java    From blueocean-plugin with MIT License 5 votes vote down vote up
@Override
public OrganizationFolderPipelineImpl getPipeline(Item item, Reachable parent, BlueOrganization organization) {
    if (item instanceof jenkins.branch.OrganizationFolder) {
        return getFolder( (jenkins.branch.OrganizationFolder)item, parent, organization);
    }
    return null;
}
 
Example #13
Source File: GithubPipelineCreateRequestTest.java    From blueocean-plugin with MIT License 5 votes vote down vote up
@Override
protected OrganizationFolderPipelineImpl getFolder(jenkins.branch.OrganizationFolder folder, Reachable parent, BlueOrganization organization) {
    if (folder.getName().equals("p")){
        return new TestOrganizationFolder(organization, folder, parent.getLink());
    }
    return null;
}
 
Example #14
Source File: GithubPipelineCreateRequestTest.java    From blueocean-plugin with MIT License 5 votes vote down vote up
@Test
public void testOrgFolderIndexing() throws IOException, UnirestException {
    User user = login();
    OrganizationFolder orgFolder = j.jenkins.createProject(OrganizationFolder.class, "p");
    orgFolder.getSCMNavigators().add(new GitHubSCMNavigator("cloudbeers"));
    Map map = new RequestBuilder(baseUrl)
            .post("/organizations/jenkins/pipelines/p/runs/")
            .jwtToken(getJwtToken(j.jenkins, user.getId(), user.getId()))
            .crumb( this.crumb )
            .data(ImmutableMap.of())
            .status(200)
            .build(Map.class);

    assertNotNull(map);
}
 
Example #15
Source File: GithubOrganizationFolderTest.java    From blueocean-plugin with MIT License 5 votes vote down vote up
@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());
}
 
Example #16
Source File: OrganizationFolderPipelineImpl.java    From blueocean-plugin with MIT License 4 votes vote down vote up
public OrganizationFolderPipelineImpl(BlueOrganization organization, OrganizationFolder folder, Link parent) {
    this.organization = organization;
    this.folder = folder;
    this.pipelineFolder = new PipelineFolderImpl(organization, folder, parent);
}
 
Example #17
Source File: MultiBranchPipelineContainerImpl.java    From blueocean-plugin with MIT License 4 votes vote down vote up
public MultiBranchPipelineContainerImpl(BlueOrganization organization, OrganizationFolder folder, Reachable parent) {
    super(organization);
    this.folder = folder;
    this.self = parent.getLink();
}
 
Example #18
Source File: OrganizationFolderPipelineImpl.java    From blueocean-plugin with MIT License 4 votes vote down vote up
protected OrganizationFolder getFolder() {
    return folder;
}
 
Example #19
Source File: GithubPipelineCreateRequestTest.java    From blueocean-plugin with MIT License 4 votes vote down vote up
public TestOrganizationFolder(BlueOrganization organization, OrganizationFolder folder, Link parent) {
    super(organization, folder, parent);
}
 
Example #20
Source File: PipelineJobFiltersTest.java    From blueocean-plugin with MIT License 4 votes vote down vote up
@Test
public void testFolderJobFilter(){
    BlueOrganization organization = mockOrganization();
    OrganizationFolder organizationFolder = mockOrgFolder(organization);
    assertFalse(new PipelineJobFilters.FolderJobFilter().getFilter().apply(organizationFolder));
}
 
Example #21
Source File: PipelineScmTest.java    From blueocean-plugin with MIT License 4 votes vote down vote up
@Override
public boolean support(@Nonnull Item item) {
    return item instanceof OrganizationFolder || item instanceof MultiBranchProject;
}
 
Example #22
Source File: OrganizationFolderTest.java    From blueocean-plugin with MIT License 4 votes vote down vote up
@Override
public boolean support(@Nonnull Item item) {
    return item instanceof OrganizationFolder;
}
 
Example #23
Source File: GithubOrganizationFolder.java    From blueocean-plugin with MIT License 4 votes vote down vote up
@Override
protected OrganizationFolderPipelineImpl getFolder(jenkins.branch.OrganizationFolder folder, Reachable parent, BlueOrganization organization) {
    SCMNavigator navigator = Iterables.getFirst(folder.getNavigators(), null);
    return GitHubSCMNavigator.class.isInstance(navigator) ? new GithubOrganizationFolder(organization, folder, parent.getLink()) : null;
}
 
Example #24
Source File: OrganizationFolderTest2.java    From blueocean-plugin with MIT License 4 votes vote down vote up
public FakeOrg(BlueOrganization organization, OrganizationFolder folder, Link parent) {
    super(organization, folder, parent);
}
 
Example #25
Source File: GithubOrganizationFolder.java    From blueocean-plugin with MIT License 4 votes vote down vote up
public GithubOrganizationFolder(BlueOrganization organization, OrganizationFolder folder, Link parent) {
    super(organization, folder, parent);
}
 
Example #26
Source File: NoTriggerOrganizationFolderMigration.java    From basic-branch-build-strategies-plugin with MIT License 4 votes vote down vote up
public NoTriggerOrganizationFolderMigration() {
    super(OrganizationFolder.class, NoTriggerOrganizationFolderProperty.class);
}
 
Example #27
Source File: WorkflowJobDependencyTrigger.java    From pipeline-maven-plugin with MIT License 4 votes vote down vote up
@Override
public boolean isApplicable(Item item) {
    return item instanceof WorkflowJob || item instanceof MultiBranchProject || item instanceof OrganizationFolder;
}
 
Example #28
Source File: OrganizationFolderPipelineImpl.java    From blueocean-plugin with MIT License votes vote down vote up
protected abstract OrganizationFolderPipelineImpl getFolder(jenkins.branch.OrganizationFolder folder, Reachable parent, BlueOrganization organization);