jenkins.scm.api.mixin.ChangeRequestSCMHead Java Examples

The following examples show how to use jenkins.scm.api.mixin.ChangeRequestSCMHead. 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: NamedBranchBuildStrategyImpl.java    From basic-branch-build-strategies-plugin with MIT License 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public boolean isAutomaticBuild(@NonNull SCMSource source, @NonNull SCMHead head, @NonNull SCMRevision currRevision,
                                @CheckForNull SCMRevision lastBuiltRevision, @CheckForNull SCMRevision lastSeenRevision, @NonNull TaskListener taskListener) {
    if (head instanceof ChangeRequestSCMHead) {
        return false;
    }
    if (head instanceof TagSCMHead) {
        return false;
    }
    String name = head.getName();
    for (NameFilter filter: filters) {
        if (filter.isMatch(name)) {
            return true;
        }
    }
    return false;
}
 
Example #2
Source File: Caches.java    From blueocean-plugin with MIT License 6 votes vote down vote up
@Override
public Optional<PullRequest> load(String key) throws Exception {
    Jenkins jenkins = Objects.firstNonNull(this.jenkins, Jenkins.getInstance());
    Job job = jenkins.getItemByFullName(key, Job.class);
    if (job == null) {
        return Optional.absent();
    }
    // TODO probably want to be using SCMHeadCategory instances to categorize them instead of hard-coding for PRs
    SCMHead head = SCMHead.HeadByItem.findHead(job);
    if (head instanceof ChangeRequestSCMHead) {
        ChangeRequestSCMHead cr = (ChangeRequestSCMHead) head;
        ObjectMetadataAction om = job.getAction(ObjectMetadataAction.class);
        ContributorMetadataAction cm = job.getAction(ContributorMetadataAction.class);
        return Optional.of(new PullRequest(
                cr.getId(),
                om != null ? om.getObjectUrl() : null,
                om != null ? om.getObjectDisplayName() : null,
                cm != null ? cm.getContributor() : null
            )
        );
    }
    return Optional.absent();
}
 
Example #3
Source File: BranchBuildStrategyImpl.java    From basic-branch-build-strategies-plugin with MIT License 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public boolean isAutomaticBuild(@NonNull SCMSource source, @NonNull SCMHead head, @NonNull SCMRevision currRevision,
                                @CheckForNull SCMRevision lastBuiltRevision, @CheckForNull SCMRevision lastSeenRevision, @NonNull TaskListener taskListener) {
    if (head instanceof ChangeRequestSCMHead) {
        return false;
    }
    if (head instanceof TagSCMHead) {
        return false;
    }
    return true;
}
 
Example #4
Source File: ChangeRequestBuildStrategyImpl.java    From basic-branch-build-strategies-plugin with MIT License 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Restricted(ProtectedExternally.class)
@Override
public boolean isAutomaticBuild(@NonNull SCMSource source, @NonNull SCMHead head, @NonNull SCMRevision currRevision,
                                @CheckForNull SCMRevision lastBuiltRevision, @CheckForNull SCMRevision lastSeenRevision, @NonNull TaskListener listener) {
    if (!(head instanceof ChangeRequestSCMHead)) {
        return false;
    }
    if (ignoreTargetOnlyChanges
            && currRevision instanceof ChangeRequestSCMRevision
            && lastBuiltRevision instanceof ChangeRequestSCMRevision) {
        ChangeRequestSCMRevision<?> curr = (ChangeRequestSCMRevision<?>) currRevision;
        if (curr.isMerge() && curr.equivalent((ChangeRequestSCMRevision<?>) lastBuiltRevision)) {
            return false;
        }
    }
    try {
        if (ignoreUntrustedChanges && !currRevision.equals(source.getTrustedRevision(currRevision, listener))) {
            return false;
        }
    } catch (IOException | InterruptedException e) {
        LogRecord lr = new LogRecord(Level.WARNING,
                "Could not determine trust status for revision {0} of {1}, assuming untrusted");
        lr.setParameters(new Object[] {currRevision, head});
        lr.setThrown(e);
        Functions.printLogRecord(lr);
        return false;
    }
    return true;
}
 
Example #5
Source File: SourceActions.java    From gitlab-branch-source-plugin with GNU General Public License v2.0 5 votes vote down vote up
@Nonnull
private List<Action> retrieve(@Nonnull GitLabSCMHead head, @CheckForNull SCMHeadEvent event, @Nonnull TaskListener listener) throws IOException, InterruptedException {
    List<Action> actions = new ArrayList<>();

    actions.add(new GitLabSCMPublishAction(head, source.getSourceSettings()));

    Action linkAction;

    if (head instanceof ChangeRequestSCMHead) {
        GitLabMergeRequest mr = retrieveMergeRequest((ChangeRequestSCMHead) head, listener);
        linkAction = GitLabLinkAction.toMergeRequest(mr.getWebUrl());
        actions.add(createAuthorMetadataAction(mr));
        actions.add(createHeadMetadataAction(((GitLabSCMMergeRequestHead) head).getDescription(), ((GitLabSCMMergeRequestHead) head).getSource(), null, linkAction.getUrlName()));
        if (acceptMergeRequest(head)) {
            boolean removeSourceBranch = mr.getRemoveSourceBranch() || removeSourceBranch(head);
            actions.add(new GitLabSCMAcceptMergeRequestAction(mr, mr.getIid(), source.getSourceSettings().getMergeCommitMessage(), removeSourceBranch));
        }
    } else {
        linkAction = (head instanceof TagSCMHead) ? GitLabLinkAction.toTag(source.getProject(), head.getName()) : GitLabLinkAction.toBranch(source.getProject(), head.getName());
        if (head instanceof GitLabSCMBranchHead && StringUtils.equals(source.getProject().getDefaultBranch(), head.getName())) {
            actions.add(new PrimaryInstanceMetadataAction());
        }
    }

    actions.add(linkAction);
    return actions;
}
 
Example #6
Source File: ActionableBuilder.java    From office-365-connector-plugin with Apache License 2.0 5 votes vote down vote up
private void pullRequestActionable() {
    Job job = run.getParent();
    SCMHead head = SCMHead.HeadByItem.findHead(job);
    if (head instanceof ChangeRequestSCMHead) {
        String pronoun = StringUtils.defaultIfBlank(
                head.getPronoun(),
                Messages.Office365ConnectorWebhookNotifier_ChangeRequestPronoun()
        );
        String viewHeader = Messages.Office365ConnectorWebhookNotifier_ViewHeader(pronoun);
        String titleHeader = Messages.Office365ConnectorWebhookNotifier_TitleHeader(pronoun);
        String authorHeader = Messages.Office365ConnectorWebhookNotifier_AuthorHeader(pronoun);

        ObjectMetadataAction oma = job.getAction(ObjectMetadataAction.class);
        if (oma != null) {
            String urlString = oma.getObjectUrl();
            PotentialAction viewPRPotentialAction = new PotentialAction(viewHeader, urlString);
            potentialActions.add(viewPRPotentialAction);
            factsBuilder.addFact(titleHeader, oma.getObjectDisplayName());
        }
        ContributorMetadataAction cma = job.getAction(ContributorMetadataAction.class);
        if (cma != null) {
            String contributor = cma.getContributor();
            String contributorDisplayName = cma.getContributorDisplayName();

            if (StringUtils.isNotBlank(contributor) && StringUtils.isNotBlank(contributorDisplayName)) {
                factsBuilder.addFact(authorHeader, String.format("%s (%s)", contributor, contributorDisplayName));
            } else {
                factsBuilder.addFact(authorHeader, StringUtils.defaultIfBlank(contributor, contributorDisplayName));
            }
        }
    }
}
 
Example #7
Source File: SourceActions.java    From gitlab-branch-source-plugin with GNU General Public License v2.0 4 votes vote down vote up
private GitLabMergeRequest retrieveMergeRequest(@Nonnull ChangeRequestSCMHead head, @Nonnull TaskListener listener) throws GitLabAPIException {
    listener.getLogger().format(Messages.GitLabSCMSource_retrievingMergeRequest(head.getId()) + "\n");
    return gitLabAPI(source.getSourceSettings()).getMergeRequest(source.getProjectId(), head.getId());
}
 
Example #8
Source File: PipelineJobFilters.java    From blueocean-plugin with MIT License 4 votes vote down vote up
public static boolean isPullRequest(Item item) {
    // TODO probably want to be using SCMHeadCategory instances to categorize them instead of hard-coding for PRs
    return SCMHead.HeadByItem.findHead(item) instanceof ChangeRequestSCMHead;
}