Java Code Examples for jenkins.scm.api.SCMSourceOwner#getSCMSources()

The following examples show how to use jenkins.scm.api.SCMSourceOwner#getSCMSources() . 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: GitHubSCMSourceRepositoryNameContributor.java    From github-branch-source-plugin with MIT License 6 votes vote down vote up
@Override
public void parseAssociatedNames(Item item, Collection<GitHubRepositoryName> result) {
    if (item instanceof SCMSourceOwner) {
        SCMSourceOwner mp = (SCMSourceOwner) item;
        for (Object o : mp.getSCMSources()) {
            if (o instanceof GitHubSCMSource) {
                GitHubSCMSource gitHubSCMSource = (GitHubSCMSource) o;
                result.add(new GitHubRepositoryName(
                        RepositoryUriResolver.hostnameFromApiUri(gitHubSCMSource.getApiUri()),
                        gitHubSCMSource.getRepoOwner(),
                        gitHubSCMSource.getRepository()));

            }
        }
    }
}
 
Example 2
Source File: GHPRMultiBranchSubscriber.java    From github-integration-plugin with MIT License 6 votes vote down vote up
@Override
protected boolean isApplicable(@Nullable Item item) {
    if (item instanceof SCMSourceOwner) {
        SCMSourceOwner scmSourceOwner = (SCMSourceOwner) item;
        for (SCMSource source : scmSourceOwner.getSCMSources()) {
            if (source instanceof GitHubSCMSource) {
                GitHubSCMSource gitHubSCMSource = (GitHubSCMSource) source;
                for (GitHubHandler hubHandler : gitHubSCMSource.getHandlers()) {
                    if (hubHandler instanceof GitHubPRHandler) {
                        return true;
                    }
                }
            }
        }
    }

    return false;
}
 
Example 3
Source File: GHMultiBranchSubscriber.java    From github-integration-plugin with MIT License 6 votes vote down vote up
@Override
protected boolean isApplicable(@Nullable Item item) {
    if (item instanceof SCMSourceOwner) {
        SCMSourceOwner scmSourceOwner = (SCMSourceOwner) item;
        for (SCMSource source : scmSourceOwner.getSCMSources()) {
            if (source instanceof GitHubSCMSource) {
                GitHubSCMSource gitHubSCMSource = (GitHubSCMSource) source;
                for (GitHubHandler hubHandler : gitHubSCMSource.getHandlers()) {
                    if (hubHandler instanceof GitHubBranchHandler) {
                        return true;
                    }
                }
            }
        }
    }

    return false;
}
 
Example 4
Source File: Functions.java    From github-integration-plugin with MIT License 6 votes vote down vote up
public static <ITEM extends Item> Predicate<ITEM> withBranchHandler() {
    return item -> {
        if (item instanceof SCMSourceOwner) {
            SCMSourceOwner scmSourceOwner = (SCMSourceOwner) item;
            for (SCMSource source : scmSourceOwner.getSCMSources()) {
                if (source instanceof GitHubSCMSource) {
                    GitHubSCMSource gitHubSCMSource = (GitHubSCMSource) source;
                    for (GitHubHandler hubHandler : gitHubSCMSource.getHandlers()) {
                        if (hubHandler instanceof GitHubBranchHandler) {
                            return true;
                        }
                    }
                }
            }
        }
        return false;
    };
}
 
Example 5
Source File: IssueCommentGHEventSubscriber.java    From github-pr-comment-build-plugin with MIT License 5 votes vote down vote up
@Override
protected boolean isApplicable(Item item) {
    if (item != null && item instanceof Job<?, ?>) {
        Job<?, ?> project = (Job<?, ?>) item;
        if (project.getParent() instanceof SCMSourceOwner) {
            SCMSourceOwner owner = (SCMSourceOwner) project.getParent();
            for (SCMSource source : owner.getSCMSources()) {
                if (source instanceof GitHubSCMSource) {
                    return true;
                }
            }
        }
    }
    return false;
}
 
Example 6
Source File: PRUpdateGHEventSubscriber.java    From github-pr-comment-build-plugin with MIT License 5 votes vote down vote up
@Override
protected boolean isApplicable(Item item) {
    if (item != null && item instanceof Job<?, ?>) {
        Job<?, ?> project = (Job<?, ?>) item;
        if (project.getParent() instanceof SCMSourceOwner) {
            SCMSourceOwner owner = (SCMSourceOwner) project.getParent();
            for (SCMSource source : owner.getSCMSources()) {
                if (source instanceof GitHubSCMSource) {
                    return true;
                }
            }
        }
    }
    return false;
}
 
Example 7
Source File: PRReviewGHEventSubscriber.java    From github-pr-comment-build-plugin with MIT License 5 votes vote down vote up
@Override
protected boolean isApplicable(Item item) {
    if (item != null && item instanceof Job<?, ?>) {
        Job<?, ?> project = (Job<?, ?>) item;
        if (project.getParent() instanceof SCMSourceOwner) {
            SCMSourceOwner owner = (SCMSourceOwner) project.getParent();
            for (SCMSource source : owner.getSCMSources()) {
                if (source instanceof GitHubSCMSource) {
                    return true;
                }
            }
        }
    }
    return false;
}
 
Example 8
Source File: GitLabSCMWebHookItemListener.java    From gitlab-branch-source-plugin with GNU General Public License v2.0 5 votes vote down vote up
private void onCreated(SCMSourceOwner item) {
    for (SCMSource source : item.getSCMSources()) {
        if (source instanceof GitLabSCMSource) {
            register((GitLabSCMSource) source, item);
        }
    }
}
 
Example 9
Source File: GitLabSCMWebHookItemListener.java    From gitlab-branch-source-plugin with GNU General Public License v2.0 5 votes vote down vote up
private void onDeleted(SCMSourceOwner owner) {
    for (SCMSource source : owner.getSCMSources()) {
        if (source instanceof GitLabSCMSource) {
            unregister((GitLabSCMSource) source, owner);
        }
    }
}
 
Example 10
Source File: GitHubStatusNotificationStep.java    From pipeline-githubnotify-step-plugin with MIT License 5 votes vote down vote up
private GitHubSCMSource getSource() {
    ItemGroup parent = run.getParent().getParent();
    if (parent instanceof SCMSourceOwner) {
        SCMSourceOwner owner = (SCMSourceOwner)parent;
        for (SCMSource source : owner.getSCMSources()) {
            if (source instanceof GitHubSCMSource) {
                return ((GitHubSCMSource) source);
            }
        }
        throw new IllegalArgumentException(UNABLE_TO_INFER_DATA);
    } else {
        throw new IllegalArgumentException(UNABLE_TO_INFER_DATA);
    }
}
 
Example 11
Source File: GitHubScmSourceRepositoryNameContributor.java    From github-integration-plugin with MIT License 5 votes vote down vote up
@Override
public void parseAssociatedNames(Item item, Collection<GitHubRepositoryName> result) {
    if (item instanceof SCMSourceOwner) {
        SCMSourceOwner sourceOwner = (SCMSourceOwner) item;
        for (SCMSource source : sourceOwner.getSCMSources()) {
            if (source instanceof GitHubSCMSource) {
                GitHubSCMSource gitHubSCMSource = (GitHubSCMSource) source;
                result.add(gitHubSCMSource.getRepoFullName());
            }
        }
    }
}
 
Example 12
Source File: GitLabMergeRequestCommentTrigger.java    From gitlab-branch-source-plugin with MIT License 4 votes vote down vote up
@Override
public void isMatch() {
    if (getPayload().getObjectAttributes().getNoteableType()
        .equals(NoteEvent.NoteableType.MERGE_REQUEST)) {
        Integer mergeRequestId = getPayload().getMergeRequest().getIid();
        final Pattern mergeRequestJobNamePattern = Pattern
            .compile("^MR-" + mergeRequestId + "\\b.*$",
                Pattern.CASE_INSENSITIVE);
        final String commentBody = getPayload().getObjectAttributes().getNote();
        final String commentUrl = getPayload().getObjectAttributes().getUrl();
        try (ACLContext ctx = ACL.as(ACL.SYSTEM)) {
            boolean jobFound = false;
            for (final SCMSourceOwner owner : SCMSourceOwners.all()) {
                LOGGER.log(Level.FINEST, String.format("Source Owner: %s", owner.getFullDisplayName()));
                // This is a hack to skip owners which are children of a SCMNavigator
                if (owner.getFullDisplayName().contains(" ยป ")) {
                    continue;
                }
                for (SCMSource source : owner.getSCMSources()) {
                    if (!(source instanceof GitLabSCMSource)) {
                        continue;
                    }
                    GitLabSCMSource gitLabSCMSource = (GitLabSCMSource) source;
                    final GitLabSCMSourceContext sourceContext = new GitLabSCMSourceContext(
                        null, SCMHeadObserver.none())
                        .withTraits(gitLabSCMSource.getTraits());
                    if (!sourceContext.mrCommentTriggerEnabled()) {
                        continue;
                    }
                    if (gitLabSCMSource.getProjectId() == getPayload().getMergeRequest()
                        .getTargetProjectId() && isTrustedMember(gitLabSCMSource, sourceContext.onlyTrustedMembersCanTrigger())) {
                        for (Job<?, ?> job : owner.getAllJobs()) {
                            if (mergeRequestJobNamePattern.matcher(job.getName()).matches()) {
                                String expectedCommentBody = sourceContext.getCommentBody();
                                Pattern pattern = Pattern.compile(expectedCommentBody,
                                    Pattern.CASE_INSENSITIVE | Pattern.DOTALL);
                                if (commentBody == null || pattern.matcher(commentBody)
                                    .matches()) {
                                    ParameterizedJobMixIn.scheduleBuild2(job, 0,
                                        new CauseAction(
                                            new GitLabMergeRequestCommentCause(commentUrl)));
                                    LOGGER.log(Level.INFO,
                                        "Triggered build for {0} due to MR comment on {1}",
                                        new Object[]{
                                            job.getFullName(),
                                            getPayload().getProject().getPathWithNamespace()
                                        }
                                    );
                                } else {
                                    LOGGER.log(Level.INFO,
                                        "MR comment does not match the trigger build string ({0}) for {1}",
                                        new Object[]{expectedCommentBody, job.getFullName()}
                                    );
                                }
                                break;
                            }
                            jobFound = true;
                        }
                    }
                }
            }
            if (!jobFound) {
                LOGGER.log(Level.INFO, "MR comment on {0} did not match any job",
                    new Object[]{
                        getPayload().getProject().getPathWithNamespace()
                    }
                );
            }
        }
    }
}