Java Code Examples for jenkins.scm.api.SCMHeadOrigin#DEFAULT

The following examples show how to use jenkins.scm.api.SCMHeadOrigin#DEFAULT . 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: BranchBuildStrategyImplTest.java    From basic-branch-build-strategies-plugin with MIT License 6 votes vote down vote up
@Test
public void given__cr_head__when__isAutomaticBuild__then__returns_false() throws Exception {
    try (MockSCMController c = MockSCMController.create()) {
        MockChangeRequestSCMHead head = new MockChangeRequestSCMHead(SCMHeadOrigin.DEFAULT, 1, "master",
                ChangeRequestCheckoutStrategy.MERGE, true);
        assertThat(
                new BranchBuildStrategyImpl().isAutomaticBuild(
                        new MockSCMSource(c, "dummy"),
                        head,
                        new MockChangeRequestSCMRevision(head,
                                new MockSCMRevision(new MockSCMHead("master"), "dummy"), "dummy"),
                        null,
                        null,
                        null
                ),
                is(false)
        );
    }
}
 
Example 2
Source File: ChangeRequestBuildStrategyImplTest.java    From basic-branch-build-strategies-plugin with MIT License 6 votes vote down vote up
@Test
public void given__cr_head__when__isAutomaticBuild__then__returns_true() throws Exception {
    try (MockSCMController c = MockSCMController.create()) {
        MockChangeRequestSCMHead head = new MockChangeRequestSCMHead(SCMHeadOrigin.DEFAULT, 1, "master",
                ChangeRequestCheckoutStrategy.MERGE, true);
        assertThat(
                new ChangeRequestBuildStrategyImpl(false, false).isAutomaticBuild(
                        new MockSCMSource(c, "dummy"),
                        head,
                        new MockChangeRequestSCMRevision(head,
                                new MockSCMRevision(new MockSCMHead("master"), "dummy"), "dummy"),
                        null,
                        null,
                        null
                ),
                is(true)
        );
    }
}
 
Example 3
Source File: ChangeRequestBuildStrategyImplTest.java    From basic-branch-build-strategies-plugin with MIT License 6 votes vote down vote up
@Test
public void given__cr_head_ignoring_untrusted_changes_when__trusted_revision__then__isAutomaticBuild_returns_true() throws Exception {
    try (MockSCMController c = MockSCMController.create()) {
        c.createRepository("dummy", MockRepositoryFlags.TRUST_AWARE);
        Integer crNum = c.openChangeRequest("dummy", "master");

        MockChangeRequestSCMHead head = new MockChangeRequestSCMHead(SCMHeadOrigin.DEFAULT, crNum, "master",
                ChangeRequestCheckoutStrategy.MERGE, true);
        assertThat(
                new ChangeRequestBuildStrategyImpl(false, true).isAutomaticBuild(
                        new MockSCMSource(c, "dummy"),
                        head,
                        new MockChangeRequestSCMRevision(head,
                                new MockSCMRevision(new MockSCMHead("master"), "dummy"), "dummy"),
                        null,
                        null,
                        null
                ),
                is(true)
        );
    }
}
 
Example 4
Source File: ChangeRequestBuildStrategyImplTest.java    From basic-branch-build-strategies-plugin with MIT License 6 votes vote down vote up
@Test
public void given__cr_head_ignoring_untrusted_changes_when__untrusted_revision__then__isAutomaticBuild_returns_false() throws Exception {
    try (MockSCMController c = MockSCMController.create()) {
        c.createRepository("dummy", MockRepositoryFlags.TRUST_AWARE);
        Integer crNum = c.openChangeRequest("dummy", "master", MockChangeRequestFlags.UNTRUSTED);

        MockChangeRequestSCMHead head = new MockChangeRequestSCMHead(SCMHeadOrigin.DEFAULT, crNum, "master",
                ChangeRequestCheckoutStrategy.MERGE, true);
        assertThat(
                new ChangeRequestBuildStrategyImpl(false, true).isAutomaticBuild(
                        new MockSCMSource(c, "dummy"),
                        head,
                        new MockChangeRequestSCMRevision(head,
                                new MockSCMRevision(new MockSCMHead("master"), "dummy"), "dummy"),
                        null,
                        null,
                        null
                ),
                is(false)
        );
    }
}
 
Example 5
Source File: ChangeRequestBuildStrategyImplTest.java    From basic-branch-build-strategies-plugin with MIT License 6 votes vote down vote up
@Test
public void given__cr_head_ignoring_target_changes__when__first_build__then__isAutomaticBuild_returns_true() throws Exception {
    try (MockSCMController c = MockSCMController.create()) {
        MockChangeRequestSCMHead head = new MockChangeRequestSCMHead(SCMHeadOrigin.DEFAULT, 1, "master",
                ChangeRequestCheckoutStrategy.MERGE, true);
        assertThat(
                new ChangeRequestBuildStrategyImpl(true, false).isAutomaticBuild(
                        new MockSCMSource(c, "dummy"),
                        head,
                        new MockChangeRequestSCMRevision(head,
                                new MockSCMRevision(new MockSCMHead("master"), "dummy"), "dummy"),
                        null,
                        null,
                        null
                ),
                is(true)
        );
    }
}
 
Example 6
Source File: ChangeRequestBuildStrategyImplTest.java    From basic-branch-build-strategies-plugin with MIT License 6 votes vote down vote up
@Test
public void given__cr_head_ignoring_target_changes__when__origin_change__then__isAutomaticBuild_returns_true() throws Exception {
    try (MockSCMController c = MockSCMController.create()) {
        MockChangeRequestSCMHead head = new MockChangeRequestSCMHead(SCMHeadOrigin.DEFAULT, 1, "master",
                ChangeRequestCheckoutStrategy.MERGE, true);
        assertThat(
                new ChangeRequestBuildStrategyImpl(true, false).isAutomaticBuild(
                        new MockSCMSource(c, "dummy"),
                        head,
                        new MockChangeRequestSCMRevision(head,
                                new MockSCMRevision(new MockSCMHead("master"), "dummy"), "new-dummy"),
                        new MockChangeRequestSCMRevision(head,
                                new MockSCMRevision(new MockSCMHead("master"), "dummy"), "dummy")
                ),
                is(true)
        );
    }
}
 
Example 7
Source File: ChangeRequestBuildStrategyImplTest.java    From basic-branch-build-strategies-plugin with MIT License 6 votes vote down vote up
@Test
public void given__cr_head_ignoring_target_changes__when__both_change__then__isAutomaticBuild_returns_true() throws Exception {
    try (MockSCMController c = MockSCMController.create()) {
        MockChangeRequestSCMHead head = new MockChangeRequestSCMHead(SCMHeadOrigin.DEFAULT, 1, "master",
                ChangeRequestCheckoutStrategy.MERGE, true);
        assertThat(
                new ChangeRequestBuildStrategyImpl(true, false).isAutomaticBuild(
                        new MockSCMSource(c, "dummy"),
                        head,
                        new MockChangeRequestSCMRevision(head,
                                new MockSCMRevision(new MockSCMHead("master"), "dummy"), "new-dummy"),
                        new MockChangeRequestSCMRevision(head,
                                new MockSCMRevision(new MockSCMHead("master"), "old-dummy"), "dummy"),
                        null,
                        null
                ),
                is(true)
        );
    }
}
 
Example 8
Source File: ChangeRequestBuildStrategyImplTest.java    From basic-branch-build-strategies-plugin with MIT License 6 votes vote down vote up
@Test
public void given__cr_head_ignoring_target_changes__when__target_change__then__isAutomaticBuild_returns_false() throws Exception {
    try (MockSCMController c = MockSCMController.create()) {
        MockChangeRequestSCMHead head = new MockChangeRequestSCMHead(SCMHeadOrigin.DEFAULT, 1, "master",
                ChangeRequestCheckoutStrategy.MERGE, true);
        assertThat(
                new ChangeRequestBuildStrategyImpl(true, false).isAutomaticBuild(
                        new MockSCMSource(c, "dummy"),
                        head,
                        new MockChangeRequestSCMRevision(head,
                                new MockSCMRevision(new MockSCMHead("master"), "dummy"), "dummy"),
                        new MockChangeRequestSCMRevision(head,
                                new MockSCMRevision(new MockSCMHead("master"), "old-dummy"), "dummy"),
                        null,
                        null
                ),
                is(false)
        );
    }
}
 
Example 9
Source File: TagBuildStrategyImplTest.java    From basic-branch-build-strategies-plugin with MIT License 6 votes vote down vote up
@Test
public void given__cr_head__when__isAutomaticBuild__then__returns_false() throws Exception {
    try (MockSCMController c = MockSCMController.create()) {
        MockChangeRequestSCMHead head = new MockChangeRequestSCMHead(SCMHeadOrigin.DEFAULT, 1, "master",
                ChangeRequestCheckoutStrategy.MERGE, true);
        assertThat(
                new TagBuildStrategyImpl(null, null).isAutomaticBuild(
                        new MockSCMSource(c, "dummy"),
                        head,
                        new MockChangeRequestSCMRevision(head,
                                new MockSCMRevision(new MockSCMHead("master"), "dummy"), "dummy"),
                        null,
                        null,
                        null
                ),
                is(false)
        );
    }
}
 
Example 10
Source File: NamedBranchBuildStrategyImplTest.java    From basic-branch-build-strategies-plugin with MIT License 6 votes vote down vote up
@Test
public void given__cr_head__when__isAutomaticBuild__then__returns_false() throws Exception {
    try (MockSCMController c = MockSCMController.create()) {
        MockChangeRequestSCMHead head = new MockChangeRequestSCMHead(SCMHeadOrigin.DEFAULT, 1, "master",
                ChangeRequestCheckoutStrategy.MERGE, true);
        assertThat(
                new NamedBranchBuildStrategyImpl(Collections.<NamedBranchBuildStrategyImpl.NameFilter>singletonList(
                        new NamedBranchBuildStrategyImpl.RegexNameFilter("^.*$", false))
                ).isAutomaticBuild(
                        new MockSCMSource(c, "dummy"),
                        head,
                        new MockChangeRequestSCMRevision(head,
                                new MockSCMRevision(new MockSCMHead("master"), "dummy"), "dummy"),
                        null,
                        null,
                        null
                ),
                is(false)
        );
    }
}
 
Example 11
Source File: PullRequestSCMHead.java    From github-branch-source-plugin with MIT License 6 votes vote down vote up
PullRequestSCMHead(GHPullRequest pr, String name, boolean merge) {
    super(name);
    // the merge flag is encoded into the name, so safe to store here
    this.merge = merge;
    this.number = pr.getNumber();
    this.target = new BranchSCMHead(pr.getBase().getRef());
    // the source stuff is immutable for a pull request on github, so safe to store here
    GHRepository repository = pr.getHead().getRepository(); // may be null for deleted forks JENKINS-41246
    this.sourceOwner = repository == null ? null : repository.getOwnerName();
    this.sourceRepo = repository == null ? null : repository.getName();
    this.sourceBranch = pr.getHead().getRef();

    if (pr.getRepository().getOwnerName().equalsIgnoreCase(sourceOwner)) {
        this.origin = SCMHeadOrigin.DEFAULT;
    } else {
        // if the forked repo name differs from the upstream repo name
        this.origin = pr.getBase().getRepository().getName().equalsIgnoreCase(sourceRepo)
                ? new SCMHeadOrigin.Fork(this.sourceOwner)
                : new SCMHeadOrigin.Fork(repository == null ? this.sourceOwner : repository.getFullName());
    }
}
 
Example 12
Source File: ChangeRequestBuildStrategyImplTest.java    From basic-branch-build-strategies-plugin with MIT License 5 votes vote down vote up
@Test
public void given__cr_head_ignoring_untrusted_changes_when__trusted_unavailable__then__isAutomaticBuild_returns_false() throws Exception {
    try (MockSCMController c = MockSCMController.create()) {
        c.createRepository("dummy", MockRepositoryFlags.TRUST_AWARE);
        Integer crNum = c.openChangeRequest("dummy", "master");

        MockChangeRequestSCMHead head = new MockChangeRequestSCMHead(SCMHeadOrigin.DEFAULT, crNum, "master",
                ChangeRequestCheckoutStrategy.MERGE, true);

        c.addFault(new MockFailure() {
            @Override
            public void check(String repository, String branchOrCR, String revision, boolean actions)
                    throws IOException {
                throw new IOException("Fail");
            }
        });
        assertThat(
                new ChangeRequestBuildStrategyImpl(false, true).isAutomaticBuild(
                        new MockSCMSource(c, "dummy"),
                        head,
                        new MockChangeRequestSCMRevision(head,
                                new MockSCMRevision(new MockSCMHead("master"), "dummy"), "dummy"),
                        null,
                        null,
                        null
                ),
                is(false)
        );
    }
}
 
Example 13
Source File: PullRequestSCMHead.java    From github-branch-source-plugin with MIT License 5 votes vote down vote up
@Override
public PullRequestSCMHead migrate(@NonNull GitHubSCMSource source, @NonNull FixOrigin head) {
    return new PullRequestSCMHead(head.getName(), head.getSourceOwner(), head.getSourceRepo(),
            head.getSourceBranch(), head.getNumber(), head.getTarget(), source.getRepoOwner().equalsIgnoreCase(head.getSourceOwner())
                                ? SCMHeadOrigin.DEFAULT
                                : new SCMHeadOrigin.Fork(head.getSourceOwner()), head.getCheckoutStrategy());
}
 
Example 14
Source File: PullRequestSCMHead.java    From github-branch-source-plugin with MIT License 5 votes vote down vote up
@Override
public PullRequestSCMHead migrate(@NonNull GitHubSCMSource source, @NonNull FixMetadata head) {
    PullRequestSource src = source.retrievePullRequestSource(head.getNumber());
    return new PullRequestSCMHead(head.getName(), src == null ? null : src.getSourceOwner(),
            src == null ? null : src.getSourceRepo(), src == null ? null : src.getSourceBranch(),
            head.getNumber(), head.getTarget(), src != null && source.getRepoOwner().equalsIgnoreCase(src.getSourceOwner())
                                ? SCMHeadOrigin.DEFAULT
                                : new SCMHeadOrigin.Fork(head.getSourceOwner()), head.getCheckoutStrategy());
}
 
Example 15
Source File: GitLabMergeRequestSCMEvent.java    From gitlab-branch-source-plugin with MIT License 4 votes vote down vote up
@NonNull
@Override
public Map<SCMHead, SCMRevision> headsFor(GitLabSCMSource source) {
    Map<SCMHead, SCMRevision> result = new HashMap<>();
    try (GitLabSCMSourceRequest request = new GitLabSCMSourceContext(null,
        SCMHeadObserver.none())
        .withTraits(source.getTraits())
        .newRequest(source, null)) {
        MergeRequestEvent.ObjectAttributes m = getPayload().getObjectAttributes();
        Map<Boolean, Set<ChangeRequestCheckoutStrategy>> strategies = request.getMRStrategies();
        boolean fork = !getPayload().getObjectAttributes().getSourceProjectId()
            .equals(getPayload().getObjectAttributes().getTargetProjectId());
        String originOwner = getPayload().getUser().getUsername();
        String originProjectPath = m.getSource().getPathWithNamespace();
        for (ChangeRequestCheckoutStrategy strategy : strategies.get(fork)) {
            MergeRequestSCMHead h = new MergeRequestSCMHead(
                "MR-" + m.getIid() + (strategies.get(fork).size() > 1 ? "-" + strategy.name()
                    .toLowerCase(Locale.ENGLISH) : ""),
                m.getIid(),
                new BranchSCMHead(m.getTargetBranch()),
                strategy,
                fork
                    ? new SCMHeadOrigin.Fork(originProjectPath)
                    : SCMHeadOrigin.DEFAULT,
                originOwner,
                originProjectPath,
                m.getSourceBranch(),
                m.getTitle()
            );
            result.put(h, m.getState().equals("closed")
                ? null
                : new MergeRequestSCMRevision(
                    h,
                    new BranchSCMRevision(
                        h.getTarget(),
                        "HEAD"
                    ),
                    new BranchSCMRevision(
                        new BranchSCMHead(h.getOriginName()),
                        m.getLastCommit().getId()
                    )
                ));
        }
    } catch (IOException e) {
        LOGGER.log(Level.SEVERE, "Exception caught: " + e, e);
    }
    return result;
}
 
Example 16
Source File: PullRequestSCMHead.java    From github-branch-source-plugin with MIT License 4 votes vote down vote up
@NonNull
@Override
public SCMHeadOrigin getOrigin() {
    return origin == null ? SCMHeadOrigin.DEFAULT : origin;
}