jenkins.scm.api.mixin.ChangeRequestSCMHead2 Java Examples

The following examples show how to use jenkins.scm.api.mixin.ChangeRequestSCMHead2. 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: ForkMergeRequestDiscoveryTrait.java    From gitlab-branch-source-plugin with MIT License 5 votes vote down vote up
/**
 * Constructor for stapler.
 *
 * @param strategyId the strategy id.
 * @param trust the authority to use.
 */
@DataBoundConstructor
public ForkMergeRequestDiscoveryTrait(int strategyId,
    @NonNull SCMHeadAuthority<? super GitLabSCMSourceRequest, ? extends
        ChangeRequestSCMHead2, ? extends SCMRevision> trust) {
    this.strategyId = strategyId;
    this.trust = trust;
}
 
Example #2
Source File: ForkMergeRequestDiscoveryTrait.java    From gitlab-branch-source-plugin with MIT License 5 votes vote down vote up
/**
 * Constructor for programmatic instantiation.
 *
 * @param strategies the {@link ChangeRequestCheckoutStrategy} instances.
 * @param trust the authority.
 */
public ForkMergeRequestDiscoveryTrait(@NonNull Set<ChangeRequestCheckoutStrategy> strategies,
    @NonNull SCMHeadAuthority<? super GitLabSCMSourceRequest, ? extends
        ChangeRequestSCMHead2, ? extends SCMRevision> trust) {
    this((strategies.contains(ChangeRequestCheckoutStrategy.MERGE) ? 1 : 0)
        + (strategies.contains(ChangeRequestCheckoutStrategy.HEAD) ? 2 : 0), trust);
}
 
Example #3
Source File: ForkPullRequestDiscoveryTrait.java    From gitea-plugin with MIT License 5 votes vote down vote up
/**
 * Constructor for stapler.
 *
 * @param strategyId the strategy id.
 * @param trust      the authority to use.
 */
@DataBoundConstructor
public ForkPullRequestDiscoveryTrait(int strategyId,
                                     @NonNull SCMHeadAuthority<? super GiteaSCMSourceRequest, ? extends
                                             ChangeRequestSCMHead2, ? extends SCMRevision> trust) {
    this.strategyId = strategyId;
    this.trust = trust;
}
 
Example #4
Source File: ForkPullRequestDiscoveryTrait.java    From gitea-plugin with MIT License 5 votes vote down vote up
/**
 * Constructor for programmatic instantiation.
 *
 * @param strategies the {@link ChangeRequestCheckoutStrategy} instances.
 * @param trust      the authority.
 */
public ForkPullRequestDiscoveryTrait(@NonNull Set<ChangeRequestCheckoutStrategy> strategies,
                                     @NonNull SCMHeadAuthority<? super GiteaSCMSourceRequest, ? extends
                                             ChangeRequestSCMHead2, ? extends SCMRevision> trust) {
    this((strategies.contains(ChangeRequestCheckoutStrategy.MERGE) ? 1 : 0)
            + (strategies.contains(ChangeRequestCheckoutStrategy.HEAD) ? 2 : 0), trust);
}
 
Example #5
Source File: ForkPullRequestDiscoveryTrait.java    From github-branch-source-plugin with MIT License 5 votes vote down vote up
/**
 * Constructor for stapler.
 *
 * @param strategyId the strategy id.
 * @param trust      the authority to use.
 */
@DataBoundConstructor
public ForkPullRequestDiscoveryTrait(int strategyId,
                                     @NonNull SCMHeadAuthority<? super GitHubSCMSourceRequest, ? extends ChangeRequestSCMHead2, ? extends SCMRevision> trust) {
    this.strategyId = strategyId;
    this.trust = trust;
}
 
Example #6
Source File: ForkPullRequestDiscoveryTrait2Test.java    From github-branch-source-plugin with MIT License 5 votes vote down vote up
private void assertRoundTrip(WorkflowMultiBranchProject p, SCMHeadAuthority<? super GitHubSCMSourceRequest, ? extends ChangeRequestSCMHead2, ? extends SCMRevision> trust, boolean configuredByUrl) throws Exception {

        GitHubSCMSource s;
        if (configuredByUrl)
            s = new GitHubSCMSource("", "", "https://github.com/nobody/nowhere", true);
        else
            s = new GitHubSCMSource("nobody", "nowhere", null, false);

        p.setSourcesList(Collections.singletonList(new BranchSource(s)));
        s.setTraits(Collections.singletonList(new ForkPullRequestDiscoveryTrait(0, trust)));
        r.configRoundtrip(p);
        List<SCMSourceTrait> traits = ((GitHubSCMSource) p.getSourcesList().get(0).getSource()).getTraits();
        assertEquals(1, traits.size());
        assertEquals(trust.getClass(), ((ForkPullRequestDiscoveryTrait) traits.get(0)).getTrust().getClass());
    }
 
Example #7
Source File: OriginMergeRequestDiscoveryTrait.java    From gitlab-branch-source-plugin with MIT License 4 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
protected boolean checkTrusted(@NonNull SCMSourceRequest request,
    @NonNull ChangeRequestSCMHead2 head) {
    return SCMHeadOrigin.DEFAULT.equals(head.getOrigin());
}
 
Example #8
Source File: ForkMergeRequestDiscoveryTrait.java    From gitlab-branch-source-plugin with MIT License 4 votes vote down vote up
/**
 * Gets the authority.
 *
 * @return the authority.
 */
@NonNull
public SCMHeadAuthority<? super GitLabSCMSourceRequest, ? extends ChangeRequestSCMHead2, ? extends SCMRevision>
getTrust() {
    return trust;
}
 
Example #9
Source File: ForkMergeRequestDiscoveryTrait.java    From gitlab-branch-source-plugin with MIT License 4 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public boolean checkTrusted(@NonNull SCMSourceRequest request,
    @NonNull ChangeRequestSCMHead2 head) {
    return false;
}
 
Example #10
Source File: ForkMergeRequestDiscoveryTrait.java    From gitlab-branch-source-plugin with MIT License 4 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
protected boolean checkTrusted(@NonNull SCMSourceRequest request,
    @NonNull ChangeRequestSCMHead2 head) {
    return true;
}
 
Example #11
Source File: YamlFlowDefinition.java    From simple-pull-request-job-plugin with Apache License 2.0 4 votes vote down vote up
@Override
public FlowExecution create(FlowExecutionOwner owner, TaskListener listener,
                            List<? extends Action> actions) throws Exception {
    Queue.Executable exec = owner.getExecutable();
    if (!(exec instanceof WorkflowRun)) {
        throw new IllegalStateException("inappropriate context");
    }

    WorkflowRun build = (WorkflowRun) exec;
    WorkflowJob job = build.getParent();
    BranchJobProperty property = job.getProperty(BranchJobProperty.class);

    Branch branch = property.getBranch();
    ItemGroup<?> parent = job.getParent();

    if (!(parent instanceof WorkflowMultiBranchProject)) {
        throw new IllegalStateException("inappropriate context");
    }

    SCMSource scmSource = ((WorkflowMultiBranchProject) parent).getSCMSource(branch.getSourceId());

    if (scmSource == null) {
        throw new IllegalStateException(branch.getSourceId() + " not found");
    }

    GitConfig gitConfig = new GitConfig();

    SCMHead head = branch.getHead();

    if ("Pull Request".equals(head.getPronoun())) {
        ChangeRequestSCMHead2 changeRequestSCMHead2 = (ChangeRequestSCMHead2) branch.getHead();
        head = changeRequestSCMHead2.getTarget();
    }

    SCMRevision tip = scmSource.fetch(head, listener);

    if (tip == null) {
        throw new IllegalStateException("Cannot determine the revision.");
    }

    SCMRevision rev = scmSource.getTrustedRevision(tip, listener);
    GitSCM gitSCM = (GitSCM) scmSource.build(head, rev);

    gitConfig.setGitUrl(gitSCM.getUserRemoteConfigs().get(0).getUrl());
    gitConfig.setCredentialsId(gitSCM.getUserRemoteConfigs().get(0).getCredentialsId());
    gitConfig.setGitBranch(head.getName());

    String script;
    try (SCMFileSystem fs = SCMFileSystem.of(scmSource, head, rev)) {
        if (fs != null) {
            InputStream yamlInputStream = fs.child(scriptPath).content();
            listener.getLogger().println("Path of yaml/yml config file: " + fs.child(scriptPath).getPath());
            YamlToPipeline y = new YamlToPipeline();
            script = y.generatePipeline(yamlInputStream, gitConfig, listener);
        } else {
            throw new IOException("SCM not supported");
            // FIXME implement full checkout
        }
    }

    listener.getLogger().println(script);
    return new CpsFlowExecution(script, false, owner);
}
 
Example #12
Source File: ForkPullRequestDiscoveryTrait.java    From gitea-plugin with MIT License 4 votes vote down vote up
/**
 * Gets the authority.
 *
 * @return the authority.
 */
@NonNull
public SCMHeadAuthority<? super GiteaSCMSourceRequest, ? extends ChangeRequestSCMHead2, ? extends SCMRevision>
getTrust() {
    return trust;
}
 
Example #13
Source File: OriginPullRequestDiscoveryTrait.java    From gitea-plugin with MIT License 4 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
protected boolean checkTrusted(@NonNull SCMSourceRequest request, @NonNull ChangeRequestSCMHead2 head) {
    return SCMHeadOrigin.DEFAULT.equals(head.getOrigin());
}
 
Example #14
Source File: OriginPullRequestDiscoveryTrait.java    From github-branch-source-plugin with MIT License 4 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
protected boolean checkTrusted(@NonNull SCMSourceRequest request, @NonNull ChangeRequestSCMHead2 head) {
    return SCMHeadOrigin.DEFAULT.equals(head.getOrigin());
}
 
Example #15
Source File: ForkPullRequestDiscoveryTrait.java    From github-branch-source-plugin with MIT License 2 votes vote down vote up
/**
 * Constructor for programmatic instantiation.
 *
 * @param strategies the {@link ChangeRequestCheckoutStrategy} instances.
 * @param trust      the authority.
 */
public ForkPullRequestDiscoveryTrait(@NonNull Set<ChangeRequestCheckoutStrategy> strategies,
                                     @NonNull SCMHeadAuthority<? super GitHubSCMSourceRequest, ? extends ChangeRequestSCMHead2, ? extends SCMRevision> trust) {
    this((strategies.contains(ChangeRequestCheckoutStrategy.MERGE) ? 1 : 0)
            + (strategies.contains(ChangeRequestCheckoutStrategy.HEAD) ? 2 : 0), trust);
}
 
Example #16
Source File: ForkPullRequestDiscoveryTrait.java    From github-branch-source-plugin with MIT License 2 votes vote down vote up
/**
 * Gets the authority.
 *
 * @return the authority.
 */
@NonNull
public SCMHeadAuthority<? super GitHubSCMSourceRequest, ? extends ChangeRequestSCMHead2, ? extends SCMRevision> getTrust() {
    return trust;
}