Skip to content

Commit d7a4d79

Browse files
authored
WIP Multibranch (#241)
Multibranch
1 parent 4eff89d commit d7a4d79

200 files changed

Lines changed: 6503 additions & 865 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

github-pullrequest-plugin/.factorypath

Lines changed: 177 additions & 0 deletions
Large diffs are not rendered by default.

github-pullrequest-plugin/pom.xml

Lines changed: 100 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,10 @@
4343
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
4444
<maven-release-plugin.version>2.5.1</maven-release-plugin.version>
4545
<maven-findbugs-plugin.version>3.0.2</maven-findbugs-plugin.version>
46-
<powermock.version>1.6.0</powermock.version>
46+
<powermock.version>1.7.4</powermock.version>
4747
<logback.version>1.1.3</logback.version>
48-
<workflow.version>1.14</workflow.version>
49-
<matrix.version>1.6</matrix.version>
48+
<workflow.version>1.15</workflow.version>
49+
<matrix.version>1.7.1</matrix.version>
5050
<excluded.tests>**/its/*.java</excluded.tests>
5151
<java.level>8</java.level>
5252
</properties>
@@ -70,7 +70,7 @@
7070
<dependency>
7171
<groupId>com.coravy.hudson.plugins.github</groupId>
7272
<artifactId>github</artifactId>
73-
<version>1.22.1</version>
73+
<version>1.28.1</version>
7474
<exclusions>
7575
<exclusion>
7676
<groupId>org.slf4j</groupId>
@@ -90,7 +90,7 @@
9090
<dependency>
9191
<groupId>org.jenkins-ci.plugins</groupId>
9292
<artifactId>github-api</artifactId>
93-
<version>1.80</version>
93+
<version>1.86</version>
9494
</dependency>
9595

9696
<dependency>
@@ -106,6 +106,81 @@
106106
<version>${matrix.version}</version>
107107
</dependency>
108108

109+
<!-- multi pseudo-branch -->
110+
<dependency>
111+
<groupId>org.jenkins-ci.plugins.workflow</groupId>
112+
<artifactId>workflow-multibranch</artifactId>
113+
<version>2.16</version>
114+
</dependency>
115+
116+
<dependency>
117+
<groupId>org.jenkins-ci.plugins</groupId>
118+
<artifactId>scm-api</artifactId>
119+
<version>2.2.3</version>
120+
</dependency>
121+
<dependency>
122+
<groupId>org.jenkins-ci.plugins</groupId>
123+
<artifactId>branch-api</artifactId>
124+
<version>2.0.16</version>
125+
</dependency>
126+
<dependency>
127+
<groupId>org.jenkins-ci.plugins</groupId>
128+
<artifactId>cloudbees-folder</artifactId>
129+
<version>6.2.1</version>
130+
</dependency>
131+
<!--<dependency>-->
132+
<!--<groupId>com.infradna.tool</groupId>-->
133+
<!--<artifactId>bridge-method-annotation</artifactId>-->
134+
<!--<version>1.14</version>-->
135+
<!--</dependency>-->
136+
<dependency>
137+
<groupId>commons-codec</groupId>
138+
<artifactId>commons-codec</artifactId>
139+
<version>1.9</version>
140+
</dependency>
141+
<dependency>
142+
<groupId>org.jenkins-ci.plugins</groupId>
143+
<artifactId>mailer</artifactId>
144+
<version>1.18</version>
145+
</dependency>
146+
<dependency>
147+
<groupId>org.jenkins-ci.plugins.icon-shim</groupId>
148+
<artifactId>icon-shim</artifactId>
149+
<version>2.0.3</version>
150+
</dependency>
151+
<dependency>
152+
<groupId>org.jenkins-ci.plugins.icon-shim</groupId>
153+
<artifactId>icon-set</artifactId>
154+
<version>2.0.3</version>
155+
</dependency>
156+
<dependency>
157+
<groupId>org.jenkins-ci.ui</groupId>
158+
<artifactId>jquery-detached</artifactId>
159+
<version>1.2.1</version>
160+
</dependency>
161+
<dependency>
162+
<groupId>org.jenkins-ci.plugins</groupId>
163+
<artifactId>git</artifactId>
164+
<version>3.6.3</version>
165+
</dependency>
166+
<dependency>
167+
<groupId>org.jenkins-ci.plugins</groupId>
168+
<artifactId>git-client</artifactId>
169+
<version>2.6.0</version>
170+
</dependency>
171+
<dependency>
172+
<groupId>org.jenkins-ci.plugins</groupId>
173+
<artifactId>credentials</artifactId>
174+
<version>2.1.16</version>
175+
</dependency>
176+
<dependency>
177+
<groupId>org.jenkins-ci.plugins</groupId>
178+
<artifactId>ssh-credentials</artifactId>
179+
<version>1.13</version>
180+
</dependency>
181+
182+
<!-- -->
183+
109184
<!--for publishers-->
110185
<dependency>
111186
<groupId>org.jenkins-ci.plugins</groupId>
@@ -117,7 +192,7 @@
117192
<dependency>
118193
<groupId>org.jenkins-ci.plugins</groupId>
119194
<artifactId>token-macro</artifactId>
120-
<version>1.10</version>
195+
<version>1.12.1</version>
121196
<optional>true</optional>
122197
</dependency>
123198

@@ -130,10 +205,16 @@
130205
</dependency>
131206

132207
<!-- for pipeline/workflow step extension -->
208+
<dependency>
209+
<groupId>org.jenkins-ci.plugins.workflow</groupId>
210+
<artifactId>workflow-api</artifactId>
211+
<version>2.23.1</version>
212+
</dependency>
133213
<dependency>
134214
<groupId>org.jenkins-ci.plugins.workflow</groupId>
135215
<artifactId>workflow-step-api</artifactId>
136-
<version>${workflow.version}</version>
216+
<!--<version>${workflow.version}</version>-->
217+
<version>2.13</version>
137218
</dependency>
138219

139220
<!-- jucies -->
@@ -145,17 +226,22 @@
145226
</dependency>
146227

147228
<!-- workflow for tests -->
229+
<dependency>
230+
<groupId>org.jenkins-ci.plugins</groupId>
231+
<artifactId>script-security</artifactId>
232+
<version>1.34</version>
233+
</dependency>
148234
<dependency>
149235
<groupId>org.jenkins-ci.plugins.workflow</groupId>
150236
<artifactId>workflow-job</artifactId>
151-
<version>${workflow.version}</version>
237+
<version>2.10</version>
152238
<scope>test</scope>
153239
</dependency>
154240

155241
<dependency>
156242
<groupId>org.jenkins-ci.plugins.workflow</groupId>
157243
<artifactId>workflow-basic-steps</artifactId>
158-
<version>${workflow.version}</version>
244+
<version>2.6</version>
159245
<scope>test</scope>
160246
</dependency>
161247

@@ -170,7 +256,8 @@
170256
<groupId>org.jenkins-ci.plugins.workflow</groupId>
171257
<artifactId>workflow-cps</artifactId>
172258
<!-- see https://github.com/jenkinsci/workflow-cps-plugin/pull/7#issuecomment-216587074 -->
173-
<version>${workflow.version}-beta-1</version>
259+
<version>2.32</version>
260+
<!--<version>${workflow.version}</version>-->
174261
<scope>test</scope>
175262
</dependency>
176263

@@ -187,14 +274,14 @@
187274
<dependency>
188275
<groupId>junit</groupId>
189276
<artifactId>junit</artifactId>
190-
<version>4.11</version>
277+
<version>4.12</version>
191278
<scope>test</scope>
192279
</dependency>
193280

194281
<dependency>
195282
<groupId>org.mockito</groupId>
196283
<artifactId>mockito-core</artifactId>
197-
<version>1.10.5</version>
284+
<version>1.10.19</version>
198285
<scope>test</scope>
199286
</dependency>
200287

@@ -302,10 +389,7 @@
302389
<plugin>
303390
<groupId>org.apache.maven.plugins</groupId>
304391
<artifactId>maven-compiler-plugin</artifactId>
305-
<configuration>
306-
<source>1.${java.level}</source>
307-
<target>1.${java.level}</target>
308-
</configuration>
392+
<version>3.7.0</version>
309393
</plugin>
310394
<plugin>
311395
<artifactId>maven-surefire-plugin</artifactId>
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
package com.github.kostyasha.github.integration.branch;
2+
3+
import com.github.kostyasha.github.integration.generic.GitHubCause;
4+
5+
import javax.annotation.CheckForNull;
6+
7+
/**
8+
* @author Kanstantsin Shautsou
9+
*/
10+
public abstract class AbstractGitHubBranchCause<T extends AbstractGitHubBranchCause<T>> extends GitHubCause<T> {
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<T> 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+
}

github-pullrequest-plugin/src/main/java/com/github/kostyasha/github/integration/branch/GitHubBranch.java

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import hudson.Functions;
44
import org.kohsuke.github.GHBranch;
5+
import org.kohsuke.github.GHRepository;
56

67
/**
78
* Store local information about branch.
@@ -16,9 +17,13 @@ public class GitHubBranch {
1617
private String htmlUrl;
1718

1819
public GitHubBranch(GHBranch ghBranch) {
19-
name = ghBranch.getName();
20-
commitSha = ghBranch.getSHA1();
21-
htmlUrl = ghBranch.getOwner().getHtmlUrl().toString() + "/tree/" + name;
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;
2227
}
2328

2429
public String getName() {

github-pullrequest-plugin/src/main/java/com/github/kostyasha/github/integration/branch/GitHubBranchCause.java

Lines changed: 37 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,81 +1,88 @@
11
package com.github.kostyasha.github.integration.branch;
22

3-
import com.github.kostyasha.github.integration.generic.GitHubCause;
3+
import com.github.kostyasha.github.integration.branch.data.GitHubBranchEnv;
4+
import com.github.kostyasha.github.integration.multibranch.head.GitHubBranchSCMHead;
5+
import com.github.kostyasha.github.integration.multibranch.head.GitHubSCMHead;
6+
import hudson.model.ParameterValue;
47
import hudson.model.Run;
8+
import jenkins.scm.api.SCMSourceOwner;
59
import org.kohsuke.github.GHBranch;
610
import org.slf4j.Logger;
711
import org.slf4j.LoggerFactory;
812

9-
import javax.annotation.CheckForNull;
1013
import javax.annotation.Nonnull;
1114
import java.io.IOException;
15+
import java.util.List;
1216

1317
import static org.apache.commons.io.FileUtils.writeStringToFile;
1418

1519
/**
1620
* @author Kanstantsin Shautsou
1721
*/
18-
public class GitHubBranchCause extends GitHubCause<GitHubBranchCause> {
22+
public class GitHubBranchCause extends AbstractGitHubBranchCause<GitHubBranchCause> {
1923
private static final Logger LOG = LoggerFactory.getLogger(GitHubBranchCause.class);
2024

2125
private final String branchName;
2226

23-
/**
24-
* null for deleted branch.
25-
*/
26-
@CheckForNull
27-
private final String commitSha;
28-
29-
@CheckForNull
30-
private final String fullRef;
31-
32-
public GitHubBranchCause(@Nonnull GitHubBranch localBranch, @Nonnull GitHubBranchRepository localRepo,
33-
String reason, boolean skip) {
27+
public GitHubBranchCause(@Nonnull GitHubBranch localBranch, @Nonnull GitHubBranchRepository localRepo, String reason, boolean skip) {
28+
this(localBranch.getName(), localBranch.getCommitSha());
3429
withReason(reason);
3530
withSkip(skip);
3631
withLocalRepo(localRepo);
37-
this.branchName = localBranch.getName();
38-
this.commitSha = localBranch.getCommitSha();
39-
this.fullRef = "refs/heads/" + branchName;
4032
}
4133

42-
public GitHubBranchCause(@Nonnull GHBranch remoteBranch,
43-
@Nonnull GitHubBranchRepository localRepo,
44-
String reason, boolean skip) {
34+
public GitHubBranchCause(@Nonnull GHBranch remoteBranch, @Nonnull GitHubBranchRepository localRepo, String reason, boolean skip) {
35+
this(remoteBranch.getName(), remoteBranch.getSHA1());
4536
withReason(reason);
4637
withSkip(skip);
4738
withLocalRepo(localRepo);
48-
this.branchName = remoteBranch.getName();
49-
this.commitSha = remoteBranch.getSHA1();
50-
this.fullRef = "refs/heads/" + branchName;
39+
withRemoteData(remoteBranch);
40+
}
41+
42+
public GitHubBranchCause(@Nonnull String branchName, String commitSha) {
43+
super(commitSha, "refs/heads/" + branchName);
44+
this.branchName = branchName;
45+
}
46+
47+
/**
48+
* Copy constructor
49+
*/
50+
public GitHubBranchCause(GitHubBranchCause cause) {
51+
super(cause);
52+
this.branchName = cause.getBranchName();
5153
}
5254

5355
public String getBranchName() {
5456
return branchName;
5557
}
5658

57-
@CheckForNull
58-
public String getCommitSha() {
59-
return commitSha;
59+
@Override
60+
public void fillParameters(List<ParameterValue> params) {
61+
GitHubBranchEnv.getParams(this, params);
6062
}
6163

62-
@CheckForNull
63-
public String getFullRef() {
64-
return fullRef;
64+
@Override
65+
public GitHubSCMHead<GitHubBranchCause> createSCMHead(String sourceId) {
66+
return new GitHubBranchSCMHead(branchName, sourceId);
6567
}
6668

6769
@Nonnull
6870
@Override
6971
public String getShortDescription() {
7072
if (getHtmlUrl() != null) {
71-
return "GitHub Branch <a href=\"" + getHtmlUrl() + "\">" + branchName + "</a>, " + getReason();
73+
return "GitHub Branch <a href=\"" + getHtmlUrl() + "\">" + getBranchName() + "</a>, " + getReason();
7274
} else {
7375
return "Deleted branch";
7476
}
7577
}
7678

7779
@Override
7880
public void onAddedTo(@Nonnull Run run) {
81+
if (run.getParent().getParent() instanceof SCMSourceOwner) {
82+
// skip multibranch
83+
return;
84+
}
85+
7986
// move polling log from cause to action
8087
try {
8188
GitHubBranchPollingLogAction action = new GitHubBranchPollingLogAction(run);

0 commit comments

Comments
 (0)