env) {
36 | }
37 |
38 | @Override
39 | public void checkout(Run, ?> build, Launcher launcher, FilePath workspace, TaskListener listener,
40 | File changelogFile, SCMRevisionState baseline) throws IOException, InterruptedException {
41 | listener.getLogger().println("No SCM checkout.");
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/github-pullrequest-plugin/src/main/java/com/github/kostyasha/github/integration/branch/webhook/BranchInfo.java:
--------------------------------------------------------------------------------
1 | package com.github.kostyasha.github.integration.branch.webhook;
2 |
3 | /**
4 | * Main info from webhook event.
5 | *
6 | * @author Kanstantsin Shautsou
7 | * @see GHBranchSubscriber
8 | */
9 | public class BranchInfo {
10 | private String repo;
11 | private String branchName;
12 | private String fullRef;
13 | private boolean tag;
14 |
15 | public BranchInfo(String repo, String branchName, String fullRef, boolean tag) {
16 | this.repo = repo;
17 | this.branchName = branchName;
18 | this.fullRef = fullRef;
19 | this.tag = tag;
20 | }
21 |
22 | public boolean isTag() {
23 | return tag;
24 | }
25 |
26 | public String getRepo() {
27 | return repo;
28 | }
29 |
30 | public BranchInfo withRepo(String repo) {
31 | this.repo = repo;
32 | return this;
33 | }
34 |
35 | public String getBranchName() {
36 | return branchName;
37 | }
38 |
39 | public BranchInfo withBranchName(String branchName) {
40 | this.branchName = branchName;
41 | return this;
42 | }
43 |
44 | public String getFullRef() {
45 | return fullRef;
46 | }
47 |
48 | public BranchInfo withFullRef(String fullRef) {
49 | this.fullRef = fullRef;
50 | return this;
51 | }
52 | }
53 |
--------------------------------------------------------------------------------
/github-pullrequest-plugin/src/test/java/org/jenkinsci/plugins/github/pullrequest/trigger/check/SkippedCauseFilterTest.java:
--------------------------------------------------------------------------------
1 | package org.jenkinsci.plugins.github.pullrequest.trigger.check;
2 |
3 | import org.jenkinsci.plugins.github.pullrequest.GitHubPRCause;
4 | import org.jenkinsci.plugins.github.pullrequest.util.TaskListenerWrapperRule;
5 | import org.junit.Rule;
6 | import org.junit.Test;
7 | import org.junit.runner.RunWith;
8 | import org.mockito.Mock;
9 | import org.mockito.junit.MockitoJUnitRunner;
10 |
11 | import static org.hamcrest.MatcherAssert.assertThat;
12 | import static org.hamcrest.Matchers.is;
13 | import static org.mockito.Mockito.when;
14 |
15 | /**
16 | * @author lanwen (Merkushev Kirill)
17 | */
18 | @RunWith(MockitoJUnitRunner.class)
19 | public class SkippedCauseFilterTest {
20 |
21 | @Mock
22 | private GitHubPRCause cause;
23 |
24 | @Rule
25 | public TaskListenerWrapperRule tlRule = new TaskListenerWrapperRule();
26 |
27 | @Test
28 | public void shouldSkip() throws Exception {
29 | when(cause.isSkip()).thenReturn(true);
30 | assertThat("skip", new SkippedCauseFilter(tlRule.getListener()).apply(cause), is(false));
31 | }
32 |
33 | @Test
34 | public void shouldNotSkip() throws Exception {
35 | when(cause.isSkip()).thenReturn(false);
36 | assertThat("not skip", new SkippedCauseFilter(tlRule.getListener()).apply(cause), is(true));
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/github-pullrequest-plugin/src/test/java/com/github/kostyasha/github/integration/branch/test/InjectJenkinsMembersRule.java:
--------------------------------------------------------------------------------
1 | package com.github.kostyasha.github.integration.branch.test;
2 |
3 | import org.junit.rules.ExternalResource;
4 | import org.jvnet.hudson.test.JenkinsRule;
5 |
6 | /**
7 | * Helpful class to make possible usage of
8 | * {@code @Inject
9 | * public GitHubPluginConfig config;
10 | * }
11 | *
12 | * in test fields instead of static calls {@link org.jenkinsci.plugins.github.GitHubPlugin#configuration()}
13 | *
14 | * See {@link com.cloudbees.jenkins.GitHubSetCommitStatusBuilderTest} for example
15 | * Should be used after JenkinsRule initialized
16 | *
17 | * {@code public RuleChain chain = RuleChain.outerRule(jRule).around(new InjectJenkinsMembersRule(jRule, this)); }
18 | *
19 | * @author lanwen (Merkushev Kirill)
20 | */
21 | public class InjectJenkinsMembersRule extends ExternalResource {
22 |
23 | private JenkinsRule jRule;
24 | private Object instance;
25 |
26 | /**
27 | * @param jRule Jenkins rule
28 | * @param instance test class instance
29 | */
30 | public InjectJenkinsMembersRule(JenkinsRule jRule, Object instance) {
31 | this.jRule = jRule;
32 | this.instance = instance;
33 | }
34 |
35 | @Override
36 | protected void before() throws Throwable {
37 | jRule.getInstance().getInjector().injectMembers(instance);
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/github-pullrequest-plugin/src/test/resources/org/jenkinsci/plugins/github_integration/its/WorkflowITest/workflowTest.groovy:
--------------------------------------------------------------------------------
1 | package org.jenkinsci.plugins.github_integration.its.WorkflowITest
2 |
3 | node('master') {
4 | step([
5 | $class : 'GitHubPRStatusBuilder',
6 | statusMessage: [
7 | content: "Build #${env.BUILD_NUMBER} started"
8 | ]
9 | ])
10 | //
11 | // checkout([
12 | // $class: 'GitSCM',
13 | // branches: [[name: "origin-pull/pull/${GITHUB_PR_NUMBER}/merge"]],
14 | // doGenerateSubmoduleConfigurations: false,
15 | // extensions: [],
16 | // submoduleCfg: [],
17 | // userRemoteConfigs: [
18 | // [
19 | // credentialsId: 'df5e384b-e836-42a0-b5cc-445e88ac6700',
20 | // name: 'origin-pull',
21 | // refspec: "+refs/pull/${GITHUB_PR_NUMBER}/merge:refs/remotes/origin-pull/pull/${GITHUB_PR_NUMBER}/merge",
22 | // url: 'git://github.com/KostyaSha/test-repo.git'
23 | // ]
24 | // ]
25 | // ])
26 |
27 | sh 'sleep 10 && env'
28 | step([
29 | $class : 'GitHubPRBuildStatusPublisher',
30 | statusMsg : [
31 | content: 'Build #${BUILD_NUMBER} ended'
32 | ],
33 | unstableAs: 'FAILURE'
34 | ])
35 | }
36 |
--------------------------------------------------------------------------------
/github-pullrequest-plugin/src/main/java/com/github/kostyasha/github/integration/branch/dsl/GitHubBranchJobDslExtenstion.java:
--------------------------------------------------------------------------------
1 | package com.github.kostyasha.github.integration.branch.dsl;
2 |
3 | import antlr.ANTLRException;
4 | import com.github.kostyasha.github.integration.branch.GitHubBranchTrigger;
5 | import com.github.kostyasha.github.integration.branch.dsl.context.GitHubBranchTriggerDslContext;
6 | import hudson.Extension;
7 | import javaposse.jobdsl.dsl.helpers.triggers.TriggerContext;
8 | import javaposse.jobdsl.plugin.ContextExtensionPoint;
9 | import javaposse.jobdsl.plugin.DslExtensionMethod;
10 |
11 |
12 | /**
13 | * @author Kanstantsin Shautsou
14 | */
15 | @Extension(optional = true)
16 | public class GitHubBranchJobDslExtenstion extends ContextExtensionPoint {
17 | @DslExtensionMethod(context = TriggerContext.class)
18 | public Object onBranch(Runnable closure) throws ANTLRException {
19 |
20 | GitHubBranchTriggerDslContext context = new GitHubBranchTriggerDslContext();
21 | executeInContext(closure, context);
22 |
23 | GitHubBranchTrigger trigger = new GitHubBranchTrigger(context.cron(), context.mode(), context.events());
24 | trigger.setPreStatus(context.isSetPreStatus());
25 | trigger.setCancelQueued(context.isCancelQueued());
26 | trigger.setAbortRunning(context.isAbortRunning());
27 | trigger.setRepoProviders(context.repoProviders());
28 |
29 | return trigger;
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/github-pullrequest-plugin/src/main/java/com/github/kostyasha/github/integration/multibranch/hooks/GitHubTagSCMHeadEvent.java:
--------------------------------------------------------------------------------
1 | package com.github.kostyasha.github.integration.multibranch.hooks;
2 |
3 | import com.github.kostyasha.github.integration.branch.webhook.BranchInfo;
4 | import com.github.kostyasha.github.integration.multibranch.head.GitHubTagSCMHead;
5 | import jenkins.scm.api.SCMHead;
6 | import jenkins.scm.api.SCMRevision;
7 | import jenkins.scm.api.SCMSource;
8 |
9 | import edu.umd.cs.findbugs.annotations.CheckForNull;
10 | import edu.umd.cs.findbugs.annotations.NonNull;
11 | import java.util.Collections;
12 | import java.util.Map;
13 |
14 | /**
15 | * @author Kanstantsin Shautsou
16 | */
17 | public class GitHubTagSCMHeadEvent extends GitHubScmHeadEvent {
18 | public GitHubTagSCMHeadEvent(@NonNull Type type, long timestamp, @NonNull BranchInfo payload, @CheckForNull String origin) {
19 | super(type, timestamp, payload, origin);
20 | }
21 |
22 | @NonNull
23 | @Override
24 | protected String getSourceRepo() {
25 | return getPayload().getRepo();
26 | }
27 |
28 | @NonNull
29 | @Override
30 | public Map heads(@NonNull SCMSource source) {
31 | if (!isMatch(source)) {
32 | return Collections.emptyMap();
33 | }
34 | return Collections.singletonMap(new GitHubTagSCMHead(getPayload().getBranchName(), source.getId()), null);
35 | }
36 |
37 | }
38 |
--------------------------------------------------------------------------------
/github-pullrequest-plugin/src/main/java/com/github/kostyasha/github/integration/multibranch/hooks/GitHubBranchSCMHeadEvent.java:
--------------------------------------------------------------------------------
1 | package com.github.kostyasha.github.integration.multibranch.hooks;
2 |
3 | import com.github.kostyasha.github.integration.branch.webhook.BranchInfo;
4 | import com.github.kostyasha.github.integration.multibranch.head.GitHubBranchSCMHead;
5 | import jenkins.scm.api.SCMHead;
6 | import jenkins.scm.api.SCMRevision;
7 | import jenkins.scm.api.SCMSource;
8 |
9 | import edu.umd.cs.findbugs.annotations.CheckForNull;
10 | import edu.umd.cs.findbugs.annotations.NonNull;
11 | import java.util.Collections;
12 | import java.util.Map;
13 |
14 | /**
15 | * @author Kanstantsin Shautsou
16 | */
17 | public class GitHubBranchSCMHeadEvent extends GitHubScmHeadEvent {
18 | public GitHubBranchSCMHeadEvent(@NonNull Type type, long timestamp, @NonNull BranchInfo payload, @CheckForNull String origin) {
19 | super(type, timestamp, payload, origin);
20 | }
21 |
22 | @NonNull
23 | @Override
24 | protected String getSourceRepo() {
25 | return getPayload().getRepo();
26 | }
27 |
28 | @NonNull
29 | @Override
30 | public Map heads(@NonNull SCMSource source) {
31 | if (!isMatch(source)) {
32 | return Collections.emptyMap();
33 | }
34 | return Collections.singletonMap(new GitHubBranchSCMHead(getPayload().getBranchName(), source.getId()), null);
35 | }
36 |
37 | }
38 |
--------------------------------------------------------------------------------
/github-pullrequest-plugin/src/test/resources/org/jenkinsci/plugins/github_integration/its/WorkflowITest/testContextStatuses.groovy:
--------------------------------------------------------------------------------
1 | package org.jenkinsci.plugins.github_integration.its.WorkflowITest
2 |
3 |
4 | try {
5 | setGitHubPullRequestStatus state: 'PENDING', context: 'custom-context1', message: "Run #${env.BUILD_NUMBER} started"
6 | setGitHubPullRequestStatus state: 'PENDING', context: 'custom-context2', message: "Run #${env.BUILD_NUMBER} started"
7 |
8 | node('master') {
9 | step([
10 | $class : 'GitHubPRStatusBuilder',
11 | statusMessage: [
12 | content: "Run #${env.BUILD_NUMBER} started"
13 | ]
14 | ])
15 |
16 | sh 'sleep 10 && env'
17 |
18 | setGitHubPullRequestStatus state: 'SUCCESS', context: 'custom-context1', message: 'Tests passed'
19 | setGitHubPullRequestStatus state: 'SUCCESS', context: 'custom-context2', message: 'Tests passed'
20 | step([
21 | $class : 'GitHubPRBuildStatusPublisher',
22 | statusMsg : [
23 | content: 'Run #${BUILD_NUMBER} ended normally'
24 | ],
25 | unstableAs: 'FAILURE'
26 | ])
27 | }
28 | } catch (Exception e) {
29 | setGitHubPullRequestStatus state: 'FAILURE', context: 'custom-context1', message: 'Some tests failed'
30 | setGitHubPullRequestStatus state: 'FAILURE', context: 'custom-context2', message: 'Some tests failed'
31 | throw e
32 | }
33 |
--------------------------------------------------------------------------------
/github-pullrequest-plugin/src/main/java/com/github/kostyasha/github/integration/multibranch/repoprovider/GitHubRepoProvider2.java:
--------------------------------------------------------------------------------
1 | package com.github.kostyasha.github.integration.multibranch.repoprovider;
2 |
3 | import com.github.kostyasha.github.integration.multibranch.GitHubSCMSource;
4 | import hudson.DescriptorExtensionList;
5 | import hudson.ExtensionPoint;
6 | import hudson.model.AbstractDescribableImpl;
7 | import hudson.model.Descriptor;
8 | import jenkins.model.Jenkins;
9 | import org.kohsuke.github.GHRepository;
10 | import org.kohsuke.github.GitHub;
11 |
12 | import edu.umd.cs.findbugs.annotations.NonNull;
13 |
14 | /**
15 | * @author Kanstantsin Shautsou
16 | */
17 | public abstract class GitHubRepoProvider2 extends AbstractDescribableImpl implements ExtensionPoint {
18 |
19 |
20 | public abstract void registerHookFor(GitHubSCMSource source);
21 |
22 | public abstract boolean isManageHooks(GitHubSCMSource source);
23 |
24 | @NonNull
25 | public abstract GitHub getGitHub(GitHubSCMSource source);
26 |
27 | public abstract GHRepository getGHRepository(GitHubSCMSource source);
28 |
29 | public abstract static class GitHubRepoProviderDescriptor2
30 | extends Descriptor {
31 | @NonNull
32 | public abstract String getDisplayName();
33 |
34 | public static DescriptorExtensionList allRepoProviders2() {
35 | return Jenkins.getInstance().getDescriptorList(GitHubRepoProvider2.class);
36 | }
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/github-pullrequest-plugin/src/test/resources/com/github/kostyasha/github/integration/branch/GitHubBranchTriggerTest/someTest/jobs/project/com.github.kostyasha.github.integration.branch.GitHubBranchRepository.runtime.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | org/repo
4 | http://localhost/org/repo
5 | git://localhost/org/repo.git
6 | git@localhost:org/repo.git
7 |
8 |
9 | for-removal
10 |
11 | for-removal
12 | 6dcb09b5b57875f334f61aebed695e2e4193fffe
13 | http://localhost/org/repo/tree/for-removal
14 |
15 |
16 |
17 | should-change
18 |
19 | should-change
20 | 6dcb09b5b57875f334f61aebed695e2e4193ffbb
21 | http://localhost/org/repo/tree/should-change
22 |
23 |
24 |
25 |
26 |
--------------------------------------------------------------------------------
/github-pullrequest-plugin/src/test/java/org/jenkinsci/plugins/github_integration/awaitility/GHRepoAppeared.java:
--------------------------------------------------------------------------------
1 | package org.jenkinsci.plugins.github_integration.awaitility;
2 |
3 | import org.kohsuke.github.GHRepository;
4 | import org.kohsuke.github.GitHub;
5 | import org.slf4j.Logger;
6 | import org.slf4j.LoggerFactory;
7 |
8 | import java.io.FileNotFoundException;
9 | import java.util.concurrent.Callable;
10 |
11 | import static java.util.Objects.isNull;
12 | import static java.util.Objects.nonNull;
13 |
14 | /**
15 | * @author Kanstantsin Shautsou
16 | */
17 | public class GHRepoAppeared implements Callable {
18 | private static final Logger LOG = LoggerFactory.getLogger(GHRepoAppeared.class);
19 |
20 | private final GitHub gitHub;
21 | private final String repoName;
22 |
23 | public GHRepoAppeared(final GitHub gitHub, final String repoName) {
24 | this.gitHub = gitHub;
25 | this.repoName = repoName;
26 | }
27 |
28 | @Override
29 | public Boolean call() throws Exception {
30 | GHRepository repository = null;
31 | try {
32 | repository = gitHub.getRepository(repoName);
33 | } catch (FileNotFoundException ignore) {
34 | }
35 | LOG.debug("[WAIT] GitHub repository '{}' {}", repoName, isNull(repository) ? "doesn't appeared" : "appeared");
36 | return nonNull(repository);
37 | }
38 |
39 | public static Callable ghRepoAppeared(final GitHub gitHub, final String repoName) {
40 | return new GHRepoAppeared(gitHub, repoName);
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/github-pullrequest-plugin/src/main/java/com/github/kostyasha/github/integration/tag/events/GitHubTagEvent.java:
--------------------------------------------------------------------------------
1 | package com.github.kostyasha.github.integration.tag.events;
2 |
3 | import com.github.kostyasha.github.integration.generic.GitHubTagDecisionContext;
4 | import com.github.kostyasha.github.integration.tag.GitHubTagCause;
5 | import hudson.ExtensionPoint;
6 | import hudson.model.AbstractDescribableImpl;
7 |
8 | import edu.umd.cs.findbugs.annotations.CheckForNull;
9 | import edu.umd.cs.findbugs.annotations.NonNull;
10 | import java.io.IOException;
11 |
12 | /**
13 | * Different "events" that may want trigger run for tag.
14 | *
15 | * @author Kanstantsin Shautsou
16 | * @see com.github.kostyasha.github.integration.branch.events.GitHubBranchEvent
17 | */
18 | public abstract class GitHubTagEvent extends AbstractDescribableImpl implements ExtensionPoint {
19 |
20 | /**
21 | * indicates that branch was created
22 | *
23 | * @return cause object. null when no influence (other events will be checked.
24 | * If cause.isSkip() == true, then other checks wouldn't influence. And triggering for this branch will be skipped.
25 | * If cause.isSkip() == false, indicates that branch build should be run.
26 | */
27 | @CheckForNull
28 | public GitHubTagCause check(@NonNull GitHubTagDecisionContext context) throws IOException {
29 | return null;
30 | }
31 |
32 | @Override
33 | public GitHubTagEventDescriptor getDescriptor() {
34 | return (GitHubTagEventDescriptor) super.getDescriptor();
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/github-pullrequest-plugin/src/main/java/com/github/kostyasha/github/integration/branch/AbstractGitHubBranchCause.java:
--------------------------------------------------------------------------------
1 | package com.github.kostyasha.github.integration.branch;
2 |
3 | import com.github.kostyasha.github.integration.generic.GitHubCause;
4 |
5 | import edu.umd.cs.findbugs.annotations.CheckForNull;
6 |
7 | /**
8 | * @author Kanstantsin Shautsou
9 | */
10 | public abstract class AbstractGitHubBranchCause> extends GitHubCause {
11 |
12 | /**
13 | * null for deleted branch/tag
14 | */
15 | @CheckForNull
16 | private final String commitSha;
17 |
18 | @CheckForNull
19 | private final String fullRef;
20 |
21 | protected AbstractGitHubBranchCause(String commitSha, String fullRef) {
22 | this.commitSha = commitSha;
23 | this.fullRef = fullRef;
24 | }
25 |
26 | /**
27 | * Copy constructor
28 | */
29 | protected AbstractGitHubBranchCause(AbstractGitHubBranchCause cause) {
30 | this(cause.getCommitSha(), cause.getFullRef());
31 | withGitUrl(cause.getGitUrl());
32 | withSshUrl(cause.getSshUrl());
33 | withHtmlUrl(cause.getHtmlUrl());
34 | withPollingLog(cause.getPollingLog());
35 | withReason(cause.getReason());
36 | withSkip(cause.isSkip());
37 | withTitle(cause.getTitle());
38 | }
39 |
40 | @CheckForNull
41 | public String getCommitSha() {
42 | return commitSha;
43 | }
44 |
45 | @CheckForNull
46 | public String getFullRef() {
47 | return fullRef;
48 | }
49 |
50 | }
51 |
--------------------------------------------------------------------------------
/github-pullrequest-plugin/src/test/resources/com/github/kostyasha/github/integration/branch/GitHubBranchTriggerTest/actualiseRepo/jobs/project/com.github.kostyasha.github.integration.branch.GitHubBranchRepository.runtime.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | KostyaSha-auto/test
4 | https://github.com/KostyaSha-auto/test/
5 | git://github.com/KostyaSha-auto/test.git
6 | git@github.com:KostyaSha-auto/test.git
7 |
8 |
9 | old-repo
10 |
11 | old-repo
12 | 6dcb09b5b57875f334f61aebed695e2e4193fffb
13 | https://github.com/KostyaSha-auto/test/tree/old-repo
14 |
15 |
16 |
17 | old-branch
18 |
19 | old-branch
20 | 6dcb09b5b57875f334f61aebed695e2e4193ffbe
21 | https://github.com/KostyaSha-auto/test/tree/old-branch
22 |
23 |
24 |
25 |
26 |
--------------------------------------------------------------------------------
/github-pullrequest-plugin/src/test/java/org/jenkinsci/plugins/github_integration/awaitility/GHRepoDeleted.java:
--------------------------------------------------------------------------------
1 | package org.jenkinsci.plugins.github_integration.awaitility;
2 |
3 | import org.kohsuke.github.GHRepository;
4 | import org.kohsuke.github.GitHub;
5 | import org.slf4j.Logger;
6 | import org.slf4j.LoggerFactory;
7 |
8 | import java.io.FileNotFoundException;
9 | import java.util.concurrent.Callable;
10 |
11 | import static java.util.Objects.isNull;
12 |
13 | /**
14 | * @author Kanstantsin Shautsou
15 | */
16 | public class GHRepoDeleted implements Callable {
17 | private static final Logger LOG = LoggerFactory.getLogger(GHRepoDeleted.class);
18 |
19 | private GitHub gitHub;
20 | private String repoName;
21 |
22 | public GHRepoDeleted(final GitHub gitHub, final String repoName) {
23 | this.gitHub = gitHub;
24 | this.repoName = repoName;
25 | }
26 |
27 | @Override
28 | public Boolean call() throws Exception {
29 | GHRepository repository;
30 | try {
31 | repository = gitHub.getRepository(repoName);
32 | } catch (FileNotFoundException ignore) {
33 | LOG.debug("[WAIT] GitHub repository '{}' doesn't found", repoName);
34 | return true;
35 | }
36 |
37 | LOG.debug("[WAIT] GitHub repository '{}' {}", repoName, isNull(repository) ? "doesn't found" : "exists");
38 | return isNull(repository);
39 | }
40 |
41 | public static Callable ghRepoDeleted(final GitHub gitHub, final String repoName) {
42 | return new GHRepoDeleted(gitHub, repoName);
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/github-pullrequest-plugin/src/test/resources/org/jenkinsci/plugins/github/pullrequest/GitHubPRTriggerMockTest/badStatePR/jobs/test-job/org.jenkinsci.plugins.github.pullrequest.GitHubPRRepository.runtime.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | org/repo
4 | https://localhost/org/repo/
5 | git://localhost/org/repo.git
6 | git@localhost:org/repo.git
7 |
8 |
9 | 1
10 |
11 | 1
12 | 2016-04-18 06:53:41.0 UTC
13 | Update README.md
14 | 2016-04-18 06:53:41.0 UTC
15 | 65d0f7818009811e5d5eb703ebad38bbcc816b49
16 | KostyaSha-auto-patch-1
17 | true
18 | master
19 | KostyaSha-auto
20 | https://localhost/org/repo/pull/1
21 | 2016-04-18 06:53:41.0 UTC
22 | KostyaSha-auto
23 |
24 |
25 |
26 |
27 |
--------------------------------------------------------------------------------
/github-pullrequest-plugin/src/test/resources/com/github/kostyasha/github/integration/branch/GitHubBranchTriggerTest/buildButtonsPerms/jobs/project/config.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | false
4 |
5 |
6 | http://localhost/org/repo/
7 |
8 |
9 |
10 | false
11 | false
12 | false
13 | false
14 |
15 |
16 |
17 | CRON
18 | false
19 | false
20 | false
21 |
22 |
23 |
24 |
25 | false
26 |
27 |
28 | false
29 |
30 |
31 |
32 |
33 |
--------------------------------------------------------------------------------
/github-pullrequest-plugin/src/main/java/com/github/kostyasha/github/integration/branch/GitHubBranch.java:
--------------------------------------------------------------------------------
1 | package com.github.kostyasha.github.integration.branch;
2 |
3 | import hudson.Functions;
4 | import org.kohsuke.github.GHBranch;
5 | import org.kohsuke.github.GHRepository;
6 |
7 | /**
8 | * Store local information about branch.
9 | *
10 | * @author Kanstantsin Shautsou
11 | * @see GitHubBranchRepository
12 | */
13 | public class GitHubBranch {
14 |
15 | private String name;
16 | private String commitSha;
17 | private String htmlUrl;
18 |
19 | public GitHubBranch(GHBranch ghBranch) {
20 | this(ghBranch.getName(), ghBranch.getSHA1(), ghBranch.getOwner());
21 | }
22 |
23 | public GitHubBranch(String name, String commitSha, GHRepository ghRepository) {
24 | this.name = name;
25 | this.commitSha = commitSha;
26 | this.htmlUrl = ghRepository.getHtmlUrl().toString() + "/tree/" + name;
27 | }
28 |
29 | public String getName() {
30 | return name;
31 | }
32 |
33 | public void setName(String name) {
34 | this.name = name;
35 | }
36 |
37 | public String getCommitSha() {
38 | return commitSha;
39 | }
40 |
41 | public void setCommitSha(String sha1) {
42 | this.commitSha = sha1;
43 | }
44 |
45 | public String getHtmlUrl() {
46 | return htmlUrl;
47 | }
48 |
49 | public void setHtmlUrl(String htmlUrl) {
50 | this.htmlUrl = htmlUrl;
51 | }
52 |
53 | public static String getIconFileName() {
54 | return Functions.getResourcePath() + "/plugin/github-pullrequest/git-branch.svg";
55 | }
56 |
57 | }
58 |
--------------------------------------------------------------------------------
/github-pullrequest-plugin/src/test/resources/com/github/kostyasha/github/integration/branch/GitHubBranchTriggerTest/actualiseRepo/jobs/project/config.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | false
4 |
5 |
6 | https://github.com/KostyaSha-auto/test/
7 |
8 |
9 |
10 | false
11 | false
12 | false
13 | false
14 |
15 |
16 |
17 | CRON
18 | false
19 | false
20 | false
21 |
22 |
23 |
24 |
25 | false
26 |
27 |
28 | false
29 |
30 |
31 |
32 |
33 |
--------------------------------------------------------------------------------
/github-pullrequest-plugin/src/main/java/org/jenkinsci/plugins/github/pullrequest/trigger/check/LocalRepoUpdater.java:
--------------------------------------------------------------------------------
1 | package org.jenkinsci.plugins.github.pullrequest.trigger.check;
2 |
3 | import com.google.common.base.Function;
4 | import org.jenkinsci.plugins.github.pullrequest.GitHubPRPullRequest;
5 | import org.jenkinsci.plugins.github.pullrequest.GitHubPRRepository;
6 | import org.kohsuke.github.GHPullRequest;
7 | import org.slf4j.Logger;
8 | import org.slf4j.LoggerFactory;
9 |
10 | import static org.kohsuke.github.GHIssueState.CLOSED;
11 | import static org.kohsuke.github.GHIssueState.OPEN;
12 |
13 | /**
14 | * @author lanwen (Merkushev Kirill)
15 | */
16 | public class LocalRepoUpdater implements Function, java.util.function.Function {
17 | private static final Logger LOGGER = LoggerFactory.getLogger(LocalRepoUpdater.class);
18 | private final GitHubPRRepository localRepo;
19 |
20 | private LocalRepoUpdater(GitHubPRRepository localRepo) {
21 | this.localRepo = localRepo;
22 | }
23 |
24 | public static LocalRepoUpdater updateLocalRepo(GitHubPRRepository localRepo) {
25 | return new LocalRepoUpdater(localRepo);
26 | }
27 |
28 | @Override
29 | public GHPullRequest apply(GHPullRequest remotePR) {
30 | if (remotePR.getState() == OPEN) {
31 | localRepo.getPulls().put(remotePR.getNumber(), new GitHubPRPullRequest(remotePR));
32 | } else if (remotePR.getState() == CLOSED) {
33 | localRepo.getPulls().remove(remotePR.getNumber()); // don't store
34 | }
35 |
36 | return remotePR;
37 | }
38 | }
39 |
40 |
--------------------------------------------------------------------------------
/github-pullrequest-plugin/src/test/resources/org/jenkinsci/plugins/github/pullrequest/GitHubPRTriggerMockTest/actualiseRepo/jobs/project/org.jenkinsci.plugins.github.pullrequest.GitHubPRRepository.runtime.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | org/old-repo
4 | https://localhost/org/old-repo/
5 | git://localhost/org/old-repo.git
6 | git@localhost:org/old-repo.git
7 |
8 |
9 | 1
10 |
11 | 1
12 | 2016-04-18 06:53:41.0 UTC
13 | Update README.md
14 | 2016-04-18 06:53:41.0 UTC
15 | 65d0f7818009811e5d5eb703ebad38bbcc816b49
16 | KostyaSha-auto-patch-1
17 | true
18 | master
19 | KostyaSha-auto
20 | https://localhost/org/old-repo/pull/1
21 | 2016-04-18 06:53:41.0 UTC
22 | KostyaSha-auto
23 |
24 |
25 |
26 |
27 |
--------------------------------------------------------------------------------
/github-pullrequest-plugin/src/main/java/com/github/kostyasha/github/integration/tag/GitHubTag.java:
--------------------------------------------------------------------------------
1 | package com.github.kostyasha.github.integration.tag;
2 |
3 | import com.github.kostyasha.github.integration.branch.GitHubBranch;
4 | import hudson.Functions;
5 | import org.kohsuke.github.GHRepository;
6 | import org.kohsuke.github.GHTag;
7 |
8 | import java.io.IOException;
9 | import java.util.ArrayList;
10 | import java.util.List;
11 | import java.util.stream.Stream;
12 | import java.util.stream.StreamSupport;
13 |
14 | /**
15 | * Store local information about tag.
16 | *
17 | * @author Kanstantsin Shautsou
18 | * @see GitHubTagRepository
19 | */
20 | public class GitHubTag extends GitHubBranch {
21 |
22 | public GitHubTag(GHTag ghTag) {
23 | this(ghTag.getName(), ghTag.getCommit().getSHA1(), ghTag.getOwner());
24 | }
25 |
26 | public GitHubTag(String name, String commitSha, GHRepository ghRepository) {
27 | super(name, commitSha, ghRepository);
28 | }
29 |
30 | public static String getIconFileName() {
31 | return Functions.getResourcePath() + "/plugin/github-pullrequest/git-tag.svg";
32 | }
33 |
34 | public static GHTag findRemoteTag(GHRepository repo, String name) throws IOException {
35 | Stream tagStream = StreamSupport.stream(repo.listTags().spliterator(), false);
36 | return tagStream.filter(t -> t.getName().equals(name)).findFirst().orElse(null);
37 | }
38 |
39 | public static List getAllTags(GHRepository repo) throws IOException {
40 | List tags = new ArrayList<>();
41 | repo.listTags().forEach(tags::add);
42 | return tags;
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/github-pullrequest-plugin/src/test/resources/com/github/kostyasha/github/integration/branch/test/GHMockRule/user.json:
--------------------------------------------------------------------------------
1 | {
2 | "login": "login",
3 | "id": 2341,
4 | "avatar_url": "",
5 | "gravatar_id": "",
6 | "url": "https://api.github.com/users/login",
7 | "html_url": "https://github.com/login",
8 | "followers_url": "https://api.github.com/users/login/followers",
9 | "following_url": "https://api.github.com/users/login/following{/other_user}",
10 | "gists_url": "https://api.github.com/users/login/gists{/gist_id}",
11 | "starred_url": "https://api.github.com/users/login/starred{/owner}{/repo}",
12 | "subscriptions_url": "https://api.github.com/users/login/subscriptions",
13 | "organizations_url": "https://api.github.com/users/login/orgs",
14 | "repos_url": "https://api.github.com/users/login/repos",
15 | "events_url": "https://api.github.com/users/login/events{/privacy}",
16 | "received_events_url": "https://api.github.com/users/login/received_events",
17 | "type": "User",
18 | "site_admin": false,
19 | "name": "User",
20 | "company": "Company",
21 | "blog": "http://blog.blog",
22 | "location": "Location",
23 | "email": null,
24 | "hireable": null,
25 | "bio": null,
26 | "public_repos": 1,
27 | "public_gists": 1,
28 | "followers": 1,
29 | "following": 1,
30 | "created_at": "2012-07-12T16:12:59Z",
31 | "updated_at": "2015-10-05T08:55:34Z",
32 | "private_gists": 1,
33 | "total_private_repos": 0,
34 | "owned_private_repos": 0,
35 | "disk_usage": 10,
36 | "collaborators": 0,
37 | "plan": {
38 | "name": "free",
39 | "space": 976562499,
40 | "collaborators": 0,
41 | "private_repos": 0
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | ## rebel
2 | github-pullrequest-plugin/src/main/resources/rebel.xml
3 |
4 | ### Jenkins hpi:run
5 | work
6 |
7 | ### Maven.gitignore
8 | target/
9 | #pom.xml.tag
10 | #pom.xml.releaseBackup
11 | #pom.xml.versionsBackup
12 | #pom.xml.next
13 | #release.properties
14 |
15 | ### Global/JetBrains.gitignore
16 | # Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm
17 | *.iml
18 |
19 | ## Directory-based project format:
20 | .idea/*
21 | !.idea/codeStyleSettings.xml
22 | !.idea/encodings.xml
23 |
24 | ## File-based project format:
25 | *.ipr
26 | *.iws
27 |
28 | ## Plugin-specific files:
29 |
30 | # IntelliJ
31 | out/
32 |
33 | # mpeltonen/sbt-idea plugin
34 | .idea_modules/
35 |
36 | # JIRA plugin
37 | atlassian-ide-plugin.xml
38 |
39 | # Crashlytics plugin (for Android Studio and IntelliJ)
40 | com_crashlytics_export_strings.xml
41 | crashlytics.properties
42 | crashlytics-build.properties
43 |
44 | ### Global/Eclipse.gitignore
45 | *.pydevproject
46 | .metadata
47 | .gradle
48 | bin/
49 | tmp/
50 | *.tmp
51 | *.bak
52 | *.swp
53 | *~.nib
54 | local.properties
55 | .settings/
56 | .loadpath
57 |
58 | # Eclipse Core
59 | .project
60 |
61 | # External tool builders
62 | .externalToolBuilders/
63 |
64 | # Locally stored "Eclipse launch configurations"
65 | *.launch
66 |
67 | # CDT-specific
68 | .cproject
69 |
70 | # JDT-specific (Eclipse Java Development Tools)
71 | .classpath
72 |
73 | # PDT-specific
74 | .buildpath
75 |
76 | # sbteclipse plugin
77 | .target
78 |
79 | # TeXlipse plugin
80 | .texlipse
81 |
82 | ### Global/Vim.gitignore
83 | [._]*.s[a-w][a-z]
84 | [._]s[a-w][a-z]
85 | *.un~
86 | Session.vim
87 | .netrwhist
88 | *~
89 | some/
90 |
--------------------------------------------------------------------------------
/github-pullrequest-plugin/src/test/java/org/jenkinsci/plugins/github_integration/awaitility/GHFromServerConfigAppeared.java:
--------------------------------------------------------------------------------
1 | package org.jenkinsci.plugins.github_integration.awaitility;
2 |
3 | import org.jenkinsci.plugins.github.config.GitHubServerConfig;
4 | import org.kohsuke.github.GitHub;
5 | import org.slf4j.Logger;
6 | import org.slf4j.LoggerFactory;
7 |
8 | import java.util.concurrent.Callable;
9 |
10 | import static java.lang.System.currentTimeMillis;
11 | import static org.jenkinsci.plugins.github.config.GitHubServerConfig.loginToGithub;
12 | import static java.util.Objects.nonNull;
13 |
14 | /**
15 | * @author Kanstantsin Shautsou
16 | */
17 | public class GHFromServerConfigAppeared implements Callable {
18 | private static final Logger LOG = LoggerFactory.getLogger(GHFromServerConfigAppeared.class);
19 | private GitHubServerConfig gitHubServerConfig;
20 | final long timeBefore;
21 |
22 | public GHFromServerConfigAppeared(GitHubServerConfig gitHubServerConfig) {
23 | this.gitHubServerConfig = gitHubServerConfig;
24 | timeBefore = currentTimeMillis();
25 | }
26 |
27 | @Override
28 | public Boolean call() throws Exception {
29 | GitHub gitHub = loginToGithub().apply(gitHubServerConfig);
30 | if (nonNull(gitHub)) {
31 | LOG.debug("loginToGithub() delay {} ms.", currentTimeMillis() - timeBefore);
32 | return true;
33 | }
34 |
35 | throw new AssertionError("GitHub doesn't appear");
36 | }
37 |
38 | public static Callable ghAppeared(GitHubServerConfig gitHubServerConfig) {
39 | return new GHFromServerConfigAppeared(gitHubServerConfig);
40 | }
41 | }
42 |
43 |
--------------------------------------------------------------------------------
/github-pullrequest-plugin/src/test/java/org/jenkinsci/plugins/github_integration/its/FreestyleITest.java:
--------------------------------------------------------------------------------
1 | package org.jenkinsci.plugins.github_integration.its;
2 |
3 | import hudson.model.FreeStyleProject;
4 | import hudson.tasks.Shell;
5 | import org.jenkinsci.plugins.github.pullrequest.GitHubPRMessage;
6 | import org.jenkinsci.plugins.github.pullrequest.builders.GitHubPRStatusBuilder;
7 | import org.jenkinsci.plugins.github.pullrequest.publishers.impl.GitHubPRBuildStatusPublisher;
8 | import org.jenkinsci.plugins.github.pullrequest.publishers.impl.GitHubPRCommentPublisher;
9 | import org.junit.Ignore;
10 | import org.junit.Test;
11 |
12 | import static org.jenkinsci.plugins.github_integration.junit.GHRule.getPreconfiguredProperty;
13 | import static org.jenkinsci.plugins.github_integration.junit.GHRule.getPreconfiguredPRTrigger;
14 |
15 | /**
16 | * @author Kanstantsin Shautsou
17 | */
18 | @Ignore
19 | public class FreestyleITest extends AbstractPRTest {
20 |
21 | @Test
22 | public void freestyleTest() throws Exception {
23 | // create job
24 | FreeStyleProject job = jRule.createFreeStyleProject("freestyle-job");
25 |
26 | job.addProperty(getPreconfiguredProperty(ghRule.getGhRepo()));
27 |
28 | job.addTrigger(getPreconfiguredPRTrigger());
29 |
30 | job.getBuildersList().add(new GitHubPRStatusBuilder());
31 | job.getBuildersList().add(new Shell("sleep 10"));
32 |
33 | job.getPublishersList().add(new GitHubPRBuildStatusPublisher());
34 | job.getPublishersList().add(new GitHubPRCommentPublisher(new GitHubPRMessage("Comment"), null, null));
35 |
36 | job.save();
37 |
38 | super.basicTest(job);
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/github-pullrequest-plugin/src/test/java/org/jenkinsci/plugins/github_integration/awaitility/GHBranchAppeared.java:
--------------------------------------------------------------------------------
1 | package org.jenkinsci.plugins.github_integration.awaitility;
2 |
3 | import org.kohsuke.github.GHBranch;
4 | import org.kohsuke.github.GHRepository;
5 | import org.slf4j.Logger;
6 | import org.slf4j.LoggerFactory;
7 |
8 | import java.util.Map;
9 | import java.util.concurrent.Callable;
10 |
11 | import static java.lang.System.currentTimeMillis;
12 |
13 | /**
14 | * @author Kanstantsin Shautsou
15 | */
16 | public class GHBranchAppeared implements Callable {
17 | private static final Logger LOG = LoggerFactory.getLogger(GHPRAppeared.class);
18 |
19 | private final String branchName;
20 | private final GHRepository repository;
21 | private final long startTime;
22 |
23 | public GHBranchAppeared(final GHRepository repository, String branchName) {
24 | this.branchName = branchName;
25 | this.repository = repository;
26 | startTime = currentTimeMillis();
27 | }
28 |
29 | @Override
30 | public Boolean call() throws Exception {
31 | for (Map.Entry entry : repository.getBranches().entrySet()) {
32 | if (entry.getKey().equals(branchName)) {
33 | LOG.debug("[WAIT] appeared branch {}, delay {} ms", branchName, currentTimeMillis() - startTime);
34 | return true;
35 | }
36 | }
37 | LOG.debug("[WAIT] no Branch {}", branchName);
38 | return false;
39 | }
40 |
41 | public static GHBranchAppeared ghBranchAppeared(GHRepository repository, String branchName) {
42 | return new GHBranchAppeared(repository, branchName);
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/github-pullrequest-plugin/src/test/java/org/jenkinsci/plugins/github_integration/awaitility/GHPRAppeared.java:
--------------------------------------------------------------------------------
1 | package org.jenkinsci.plugins.github_integration.awaitility;
2 |
3 | import org.kohsuke.github.GHIssueState;
4 | import org.kohsuke.github.GHPullRequest;
5 | import org.kohsuke.github.GHRepository;
6 | import org.slf4j.Logger;
7 | import org.slf4j.LoggerFactory;
8 |
9 | import java.util.concurrent.Callable;
10 |
11 | import static java.lang.System.currentTimeMillis;
12 |
13 | /**
14 | * @author Kanstantsin Shautsou
15 | */
16 | public class GHPRAppeared implements Callable {
17 | private static final Logger LOG = LoggerFactory.getLogger(GHPRAppeared.class);
18 |
19 | private final GHPullRequest pullRequest;
20 | private final GHRepository repository;
21 | private final long startTime;
22 |
23 | public GHPRAppeared(final GHPullRequest pullRequest) {
24 | this.pullRequest = pullRequest;
25 | repository = pullRequest.getRepository();
26 | startTime = currentTimeMillis();
27 | }
28 |
29 | @Override
30 | public Boolean call() throws Exception {
31 | for (GHPullRequest pr : repository.listPullRequests(GHIssueState.OPEN)) {
32 | if (pr.getNumber() == pullRequest.getNumber()) {
33 | LOG.debug("[WAIT] appeared PR {}, delay {} ms", pullRequest.getNumber(), currentTimeMillis() - startTime);
34 | return true;
35 | }
36 | }
37 | LOG.debug("[WAIT] no PR {}", pullRequest.getNumber());
38 | return false;
39 | }
40 |
41 | public static GHPRAppeared ghPRAppeared(GHPullRequest pullRequest) {
42 | return new GHPRAppeared(pullRequest);
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/github-pullrequest-plugin/src/test/java/org/jenkinsci/plugins/github_integration/hamcrest/CommitStatusMatcher.java:
--------------------------------------------------------------------------------
1 | package org.jenkinsci.plugins.github_integration.hamcrest;
2 |
3 | //import org.hamcrest.Factory;
4 | import org.hamcrest.FeatureMatcher;
5 | import org.hamcrest.Matcher;
6 | import org.kohsuke.github.GHCommitState;
7 | import org.kohsuke.github.GHCommitStatus;
8 |
9 | import static org.hamcrest.core.Is.is;
10 |
11 | /**
12 | * @author Kanstantsin Shautsou
13 | */
14 | public class CommitStatusMatcher extends FeatureMatcher {
15 | private String context;
16 | private GHCommitState state;
17 | private String description;
18 |
19 | public CommitStatusMatcher(Matcher super Boolean> subMatcher,
20 | String context,
21 | GHCommitState state,
22 | String description) {
23 | super(subMatcher, "", "");
24 | this.context = context;
25 | this.state = state;
26 | this.description = description;
27 | }
28 |
29 | @Override
30 | protected Boolean featureValueOf(GHCommitStatus commitStatus) {
31 | return commitStatus.getState().equals(state) &&
32 | commitStatus.getContext().equals(context) &&
33 | commitStatus.getDescription().equals(description);
34 | }
35 |
36 | //@Factory
37 | public static CommitStatusMatcher commitStatus(String context,
38 | GHCommitState state,
39 | String description) {
40 | return new CommitStatusMatcher(is(true), context, state, description);
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/github-pullrequest-plugin/src/test/resources/org/jenkinsci/plugins/github/pullrequest/GitHubPRTriggerMockTest/badStatePR/jobs/test-job/config.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | false
6 |
7 |
8 | https://localhost/org/repo/
9 | display-name
10 |
11 |
12 |
13 | true
14 | false
15 | false
16 | false
17 |
18 |
19 |
20 | HEAVY_HOOKS
21 |
22 |
23 |
24 |
25 | false
26 | false
27 | false
28 |
29 |
30 | false
31 |
32 |
33 |
34 |
35 |
--------------------------------------------------------------------------------
/github-pullrequest-plugin/src/main/java/com/github/kostyasha/github/integration/multibranch/scm/AsIsGitSCMFactory.java:
--------------------------------------------------------------------------------
1 | package com.github.kostyasha.github.integration.multibranch.scm;
2 |
3 | import com.github.kostyasha.github.integration.multibranch.GitHubSCMSource;
4 | import hudson.Extension;
5 | import hudson.plugins.git.GitSCM;
6 | import jenkins.scm.api.SCMHead;
7 | import jenkins.scm.api.SCMRevision;
8 | import org.jenkinsci.Symbol;
9 | import org.kohsuke.stapler.DataBoundConstructor;
10 |
11 | import edu.umd.cs.findbugs.annotations.NonNull;
12 |
13 | /**
14 | * @author Kanstantsin Shautsou
15 | */
16 | public class AsIsGitSCMFactory extends GitHubSCMFactory {
17 |
18 | private GitSCM gitSCM;
19 |
20 | @DataBoundConstructor
21 | public AsIsGitSCMFactory(GitSCM gitSCM) {
22 | this.gitSCM = gitSCM;
23 | }
24 |
25 | public GitSCM getGitSCM() {
26 | return gitSCM;
27 | }
28 |
29 | @Override
30 | public GitSCM createScm(GitHubSCMSource scmSource, SCMHead scmHead, SCMRevision scmRevision) {
31 | return new GitSCM(
32 | gitSCM.getUserRemoteConfigs(),
33 | gitSCM.getBranches(),
34 | gitSCM.isDoGenerateSubmoduleConfigurations(),
35 | gitSCM.getSubmoduleCfg(),
36 | gitSCM.getBrowser(),
37 | gitSCM.getGitTool(),
38 | gitSCM.getExtensions()
39 | );
40 | }
41 |
42 | @Symbol("asIsGITScm")
43 | @Extension
44 | public static class DescriptorImpl extends GitHubSCMFactoryDescriptor {
45 | @NonNull
46 | @Override
47 | public String getDisplayName() {
48 | return "As Is Git SCM";
49 | }
50 | }
51 | }
52 |
--------------------------------------------------------------------------------
/github-pullrequest-plugin/src/main/java/org/jenkinsci/plugins/github/pullrequest/GitHubPRBuildListener.java:
--------------------------------------------------------------------------------
1 | package org.jenkinsci.plugins.github.pullrequest;
2 |
3 | import hudson.Extension;
4 | import hudson.model.Run;
5 | import hudson.model.TaskListener;
6 | import hudson.model.listeners.RunListener;
7 | import hudson.plugins.git.util.BuildData;
8 | import org.slf4j.Logger;
9 | import org.slf4j.LoggerFactory;
10 |
11 | import edu.umd.cs.findbugs.annotations.NonNull;
12 |
13 | import static java.util.Objects.isNull;
14 | import static java.util.Objects.nonNull;
15 | import static org.jenkinsci.plugins.github.pullrequest.utils.JobHelper.ghPRCauseFromRun;
16 | import static org.jenkinsci.plugins.github.pullrequest.utils.JobHelper.ghPRTriggerFromRun;
17 |
18 | /**
19 | * Sets Pending build status before build run and manipulates Git's BuildData attached to job Action.
20 | *
21 | * @author Kanstantsin Shautsou
22 | */
23 | @Extension
24 | public class GitHubPRBuildListener extends RunListener> {
25 | private static final Logger LOGGER = LoggerFactory.getLogger(GitHubPRBuildListener.class);
26 |
27 | @Override
28 | public void onCompleted(Run, ?> run, @NonNull TaskListener listener) {
29 | GitHubPRTrigger trigger = ghPRTriggerFromRun(run);
30 | if (isNull(trigger)) {
31 | return;
32 | }
33 |
34 | GitHubPRCause cause = ghPRCauseFromRun(run);
35 |
36 | if (nonNull(cause)) {
37 | //remove all BuildData, because it doesn't work right with pull requests now
38 | //TODO rework after git-client patching about BuildData usage
39 | run.getActions().removeAll(run.getActions(BuildData.class));
40 | }
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/github-pullrequest-plugin/src/test/resources/org/jenkinsci/plugins/github/pullrequest/GitHubPRTriggerTest/ensureOldValid/jobs/test-job/org.jenkinsci.plugins.github.pullrequest.GitHubPRRepository.runtime.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | KostyaSha-auto/test
4 | https://github.com/KostyaSha-auto/test/
5 | git://github.com/KostyaSha-auto/test.git
6 | git@github.com:KostyaSha-auto/test.git
7 |
8 |
9 | 1
10 |
11 | 1
12 | 2016-04-18 06:53:41.0 UTC
13 | Update README.md
14 | 2016-04-18 06:53:41.0 UTC
15 | 65d0f7818009811e5d5eb703ebad38bbcc816b49
16 | KostyaSha-auto-patch-1
17 | true
18 | master
19 | KostyaSha-auto
20 | https://github.com/KostyaSha-auto/test/pull/1
21 |
22 | 2016-04-18 06:53:41.0 UTC
23 | KostyaSha-auto
24 |
25 |
26 |
27 |
28 |
--------------------------------------------------------------------------------
/github-pullrequest-plugin/src/test/resources/org/jenkinsci/plugins/github/pullrequest/GitHubPRTriggerMockTest/actualiseRepo/jobs/project/config.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | false
6 |
7 |
8 | https://localhost/org/old-repo/
9 | display-name
10 |
11 |
12 |
13 | true
14 | false
15 | false
16 | false
17 |
18 |
19 |
20 | HEAVY_HOOKS
21 |
22 |
23 |
24 |
25 | false
26 | false
27 | false
28 |
29 |
30 | false
31 |
32 |
33 |
34 |
35 |
--------------------------------------------------------------------------------
/github-pullrequest-plugin/src/test/resources/org/jenkinsci/plugins/github/pullrequest/GitHubPRTriggerTest/buildButtonsPerms/jobs/project/org.jenkinsci.plugins.github.pullrequest.GitHubPRRepository.runtime.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | KostyaSha-auto/test
4 | https://github.com/KostyaSha-auto/test/
5 | git://github.com/KostyaSha-auto/test.git
6 | git@github.com:KostyaSha-auto/test.git
7 |
8 |
9 | 1
10 |
11 | 1
12 | 2016-04-18 06:53:41.0 UTC
13 | Update README.md
14 | 2016-04-18 06:53:41.0 UTC
15 | 65d0f7818009811e5d5eb703ebad38bbcc816b49
16 | KostyaSha-auto-patch-1
17 | true
18 | master
19 | KostyaSha-auto
20 | https://github.com/KostyaSha-auto/test/pull/1
21 |
22 | 2016-04-18 06:53:41.0 UTC
23 | KostyaSha-auto
24 |
25 |
26 |
27 |
28 |
--------------------------------------------------------------------------------
/github-pullrequest-plugin/src/main/java/com/github/kostyasha/github/integration/multibranch/hooks/GitHubPullRequestScmHeadEvent.java:
--------------------------------------------------------------------------------
1 | package com.github.kostyasha.github.integration.multibranch.hooks;
2 |
3 | import com.github.kostyasha.github.integration.multibranch.head.GitHubPRSCMHead;
4 | import hudson.scm.SCM;
5 | import jenkins.scm.api.SCMHead;
6 | import jenkins.scm.api.SCMRevision;
7 | import jenkins.scm.api.SCMSource;
8 | import org.jenkinsci.plugins.github.pullrequest.webhook.PullRequestInfo;
9 |
10 | import edu.umd.cs.findbugs.annotations.CheckForNull;
11 | import edu.umd.cs.findbugs.annotations.NonNull;
12 | import java.util.Collections;
13 | import java.util.Map;
14 |
15 | /**
16 | * @author Kanstantsin Shautsou
17 | */
18 | public class GitHubPullRequestScmHeadEvent extends GitHubScmHeadEvent {
19 | public GitHubPullRequestScmHeadEvent(@NonNull Type type, long timestamp, @NonNull PullRequestInfo payload,
20 | @CheckForNull String origin) {
21 | super(type, timestamp, payload, origin);
22 | }
23 |
24 | @NonNull
25 | @Override
26 | protected String getSourceRepo() {
27 | return getPayload().getRepo();
28 | }
29 |
30 | @NonNull
31 | @Override
32 | public Map heads(@NonNull SCMSource source) {
33 | if (!isMatch(source)) {
34 | return Collections.emptyMap();
35 | }
36 |
37 | return Collections.singletonMap(
38 | new GitHubPRSCMHead(getPayload().getNum(), getPayload().getTarget(), source.getId()), null
39 | );
40 | }
41 |
42 | @Override
43 | public boolean isMatch(@NonNull SCM scm) {
44 | return false;
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/github-pullrequest-plugin/src/main/java/org/jenkinsci/plugins/github/pullrequest/utils/StatusVerifier.java:
--------------------------------------------------------------------------------
1 | package org.jenkinsci.plugins.github.pullrequest.utils;
2 |
3 | import hudson.Extension;
4 | import hudson.model.AbstractDescribableImpl;
5 | import hudson.model.Descriptor;
6 | import hudson.model.Result;
7 | import hudson.model.Run;
8 | import hudson.util.ListBoxModel;
9 | import org.jenkinsci.Symbol;
10 | import org.kohsuke.stapler.DataBoundConstructor;
11 |
12 | /**
13 | * Checks build result and allows run for publishers only for builds with specified result.
14 | *
15 | * @author Alina Karpovich
16 | */
17 | public class StatusVerifier extends AbstractDescribableImpl {
18 |
19 | private Result buildStatus;
20 |
21 | @DataBoundConstructor
22 | public StatusVerifier(Result buildStatus) {
23 | this.buildStatus = buildStatus;
24 | }
25 |
26 | public boolean isRunAllowed(Run, ?> run) {
27 | return run.getResult().isBetterOrEqualTo(buildStatus);
28 | }
29 |
30 | public Result getBuildStatus() {
31 | return buildStatus;
32 | }
33 |
34 | @Symbol("allowRunOnStatus")
35 | @Extension
36 | public static class DescriptorImpl extends Descriptor {
37 | @Override
38 | public String getDisplayName() {
39 | return "Allow run only for specified status";
40 | }
41 |
42 | public ListBoxModel doFillBuildStatusItems() {
43 | ListBoxModel items = new ListBoxModel();
44 | items.add(Result.SUCCESS.toString());
45 | items.add(Result.UNSTABLE.toString());
46 | items.add(Result.FAILURE.toString());
47 | return items;
48 | }
49 | }
50 | }
51 |
--------------------------------------------------------------------------------
/github-pullrequest-plugin/src/test/resources/org/jenkinsci/plugins/github/pullrequest/GitHubPRTriggerTest/buildButtonsPerms/jobs/project/config.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | false
6 |
7 |
8 | https://localhost.localdomain/KostyaSha-auto/test/
9 | display-name
10 |
11 |
12 |
13 | true
14 | false
15 | false
16 | false
17 |
18 |
19 |
20 | CRON
21 |
22 |
23 |
24 |
25 | false
26 | false
27 | false
28 |
29 |
30 | false
31 |
32 |
33 |
34 |
35 |
--------------------------------------------------------------------------------
/github-pullrequest-plugin/src/main/java/org/jenkinsci/plugins/github/pullrequest/trigger/check/BranchRestrictionFilter.java:
--------------------------------------------------------------------------------
1 | package org.jenkinsci.plugins.github.pullrequest.trigger.check;
2 |
3 | import com.google.common.base.Predicate;
4 | import com.google.common.base.Predicates;
5 | import org.jenkinsci.plugins.github.pullrequest.restrictions.GitHubPRBranchRestriction;
6 | import org.jenkinsci.plugins.github.pullrequest.utils.LoggingTaskListenerWrapper;
7 | import org.kohsuke.github.GHPullRequest;
8 |
9 | import static java.util.Objects.isNull;
10 |
11 | /**
12 | * @author lanwen (Merkushev Kirill)
13 | */
14 | public class BranchRestrictionFilter implements Predicate {
15 | private final LoggingTaskListenerWrapper logger;
16 | private final GitHubPRBranchRestriction branchRestriction;
17 |
18 | private BranchRestrictionFilter(LoggingTaskListenerWrapper logger, GitHubPRBranchRestriction branchRestriction) {
19 | this.logger = logger;
20 | this.branchRestriction = branchRestriction;
21 | }
22 |
23 | public static Predicate withBranchRestriction(
24 | LoggingTaskListenerWrapper logger, GitHubPRBranchRestriction branchRestriction) {
25 |
26 | if (isNull(branchRestriction)) {
27 | return Predicates.alwaysTrue();
28 | }
29 |
30 | return new BranchRestrictionFilter(logger, branchRestriction);
31 | }
32 |
33 | @Override
34 | public boolean apply(GHPullRequest remotePR) {
35 | if (!branchRestriction.isBranchBuildAllowed(remotePR)) {
36 | logger.info("Skipping [#{} {}] because of branch restriction", remotePR.getNumber(), remotePR.getTitle());
37 | return false;
38 | }
39 |
40 | return true;
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/github-pullrequest-plugin/src/main/java/org/jenkinsci/plugins/github/pullrequest/utils/PublisherErrorHandler.java:
--------------------------------------------------------------------------------
1 | package org.jenkinsci.plugins.github.pullrequest.utils;
2 |
3 | import hudson.Extension;
4 | import hudson.model.AbstractDescribableImpl;
5 | import hudson.model.Descriptor;
6 | import hudson.model.Result;
7 | import hudson.model.Run;
8 | import hudson.util.ListBoxModel;
9 | import org.jenkinsci.Symbol;
10 | import org.kohsuke.stapler.DataBoundConstructor;
11 |
12 | import edu.umd.cs.findbugs.annotations.NonNull;
13 |
14 | /**
15 | * Allows to change build result to specified value if there was publisher error.
16 | *
17 | * @author Alina Karpovich
18 | */
19 | public class PublisherErrorHandler extends AbstractDescribableImpl {
20 |
21 | private Result buildStatus;
22 |
23 | @DataBoundConstructor
24 | public PublisherErrorHandler(Result buildStatus) {
25 | this.buildStatus = buildStatus;
26 | }
27 |
28 | public Result getBuildStatus() {
29 | return buildStatus;
30 | }
31 |
32 | public Result markBuildAfterError(Run, ?> run) {
33 | run.setResult(buildStatus);
34 | return buildStatus;
35 | }
36 |
37 | @Symbol("statusOnPublisherError")
38 | @Extension
39 | public static class DescriptorImpl extends Descriptor {
40 | @NonNull
41 | @Override
42 | public String getDisplayName() {
43 | return "Set build status if publisher failed";
44 | }
45 |
46 | public ListBoxModel doFillBuildStatusItems() {
47 | ListBoxModel items = new ListBoxModel();
48 | items.add(Result.UNSTABLE.toString());
49 | items.add(Result.FAILURE.toString());
50 | return items;
51 | }
52 | }
53 | }
54 |
--------------------------------------------------------------------------------
/github-pullrequest-plugin/src/main/java/com/github/kostyasha/github/integration/multibranch/GitHubParametersAction.java:
--------------------------------------------------------------------------------
1 | package com.github.kostyasha.github.integration.multibranch;
2 |
3 | import java.io.IOException;
4 | import java.util.List;
5 |
6 | import hudson.EnvVars;
7 | import hudson.Extension;
8 | import hudson.model.Action;
9 | import hudson.model.EnvironmentContributor;
10 | import hudson.model.InvisibleAction;
11 | import hudson.model.ParameterValue;
12 | import hudson.model.ParametersAction;
13 | import hudson.model.Run;
14 | import hudson.model.TaskListener;
15 | import hudson.model.Queue.Item;
16 | import hudson.model.Queue.Task;
17 | import hudson.model.queue.FoldableAction;
18 |
19 | /**
20 | * Simpler replacement for {@link ParametersAction} that does not stand in the way of 'folding' queue items
21 | * @author atanasenko
22 | *
23 | */
24 | public class GitHubParametersAction extends InvisibleAction implements FoldableAction {
25 |
26 | private List params;
27 |
28 | public GitHubParametersAction(List params) {
29 | this.params = params;
30 | }
31 |
32 | @Override
33 | public void foldIntoExisting(Item item, Task owner, List actions) {
34 | item.addOrReplaceAction(this);
35 | }
36 |
37 | @Extension
38 | public static class GitHubEnvContributor extends EnvironmentContributor {
39 | @Override
40 | public void buildEnvironmentFor(Run r, EnvVars envs, TaskListener listener) throws IOException, InterruptedException {
41 | GitHubParametersAction action = r.getAction(GitHubParametersAction.class);
42 | if (action == null) {
43 | return;
44 | }
45 | action.params.forEach(p -> p.buildEnvironment(r, envs));
46 | }
47 | }
48 |
49 | }
50 |
--------------------------------------------------------------------------------
/github-pullrequest-plugin/src/main/java/com/github/kostyasha/github/integration/tag/GitHubTagEnv.java:
--------------------------------------------------------------------------------
1 | package com.github.kostyasha.github.integration.tag;
2 |
3 | import com.github.kostyasha.github.integration.generic.GitHubEnv;
4 | import com.github.kostyasha.github.integration.generic.GitHubRepoEnv;
5 | import hudson.model.ParameterValue;
6 |
7 | import java.util.List;
8 | import java.util.function.Function;
9 | import java.util.function.Predicate;
10 |
11 | /**
12 | * @author Kanstantsin Shautsou
13 | */
14 | public enum GitHubTagEnv implements GitHubEnv {
15 | NAME(GitHubTagCause::getTagName),
16 | SHORT_DESC(GitHubTagCause::getShortDescription),
17 | TITLE(GitHubTagCause::getTitle),
18 | URL((Function) c -> c.getHtmlUrl().toString()),
19 | HEAD_SHA(GitHubTagCause::getCommitSha),
20 | FULL_REF(GitHubTagCause::getFullRef),
21 | CAUSE_SKIP(GitHubTagCause::isSkip);
22 |
23 | public static final String PREFIX = "GITHUB_TAG_";
24 |
25 | private Function fun;
26 |
27 | GitHubTagEnv(Function fun) {
28 | this.fun = c -> param(fun.apply(c));
29 | }
30 |
31 | GitHubTagEnv(Predicate fun) {
32 | this.fun = c -> param(fun.test(c));
33 | }
34 |
35 | @Override
36 | public void addParam(GitHubTagCause cause, List params) {
37 | params.add(fun.apply(cause));
38 | }
39 |
40 | @Override
41 | public String toString() {
42 | return PREFIX.concat(name());
43 | }
44 |
45 | public static void getParams(GitHubTagCause cause, List params) {
46 | GitHubEnv.getParams(GitHubTagEnv.class, cause, params);
47 | GitHubEnv.getParams(GitHubRepoEnv.class, cause, params);
48 | }
49 | }
50 |
--------------------------------------------------------------------------------
/github-pullrequest-plugin/src/main/java/org/jenkinsci/plugins/github/pullrequest/GitHubPRLabel.java:
--------------------------------------------------------------------------------
1 | package org.jenkinsci.plugins.github.pullrequest;
2 |
3 | import com.google.common.base.Joiner;
4 | import hudson.Extension;
5 | import hudson.model.Describable;
6 | import hudson.model.Descriptor;
7 | import jenkins.model.Jenkins;
8 | import org.jenkinsci.Symbol;
9 | import org.kohsuke.stapler.DataBoundConstructor;
10 |
11 | import edu.umd.cs.findbugs.annotations.NonNull;
12 | import java.util.Arrays;
13 | import java.util.Collections;
14 | import java.util.HashSet;
15 | import java.util.Set;
16 |
17 | import static java.util.Objects.nonNull;
18 |
19 | /**
20 | * Label object that contains user defined labels
21 | *
22 | * @author Alina Karpovich
23 | */
24 | public class GitHubPRLabel implements Describable {
25 | private Set labels;
26 |
27 | @DataBoundConstructor
28 | public GitHubPRLabel(String labels) {
29 | this(new HashSet<>(Arrays.asList(labels.split("\n"))));
30 | }
31 |
32 | public GitHubPRLabel(Set labels) {
33 | this.labels = labels;
34 | }
35 |
36 | // for UI binding
37 | public String getLabels() {
38 | return Joiner.on("\n").skipNulls().join(labels);
39 | }
40 |
41 | @NonNull
42 | public Set getLabelsSet() {
43 | return nonNull(labels) ? labels : Collections.emptySet();
44 | }
45 |
46 | public DescriptorImpl getDescriptor() {
47 | return (DescriptorImpl) Jenkins.getInstance().getDescriptor(GitHubPRLabel.class);
48 | }
49 |
50 | @Symbol("labels")
51 | @Extension
52 | public static class DescriptorImpl extends Descriptor {
53 | @NonNull
54 | @Override
55 | public String getDisplayName() {
56 | return "Labels";
57 | }
58 | }
59 | }
60 |
--------------------------------------------------------------------------------