Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 06472d0

Browse filesBrowse files
Merge pull request #1 from lucidsoftware/jnowjack-duplicate-build-data-issue
Grab current build data if there are multiple
2 parents 851f0fe + a06f196 commit 06472d0
Copy full SHA for 06472d0

File tree

Expand file treeCollapse file tree

3 files changed

+23
-12
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

3 files changed

+23
-12
lines changed
Open diff view settings
Collapse file

‎pom.xml‎

Copy file name to clipboardExpand all lines: pom.xml
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
<groupId>com.coravy.hudson.plugins.github</groupId>
1313
<artifactId>github</artifactId>
14-
<version>1.43.0</version>
14+
<version>99.43.0</version>
1515
<packaging>hpi</packaging>
1616

1717
<name>GitHub plugin</name>
@@ -39,7 +39,7 @@
3939
<connection>scm:git:https://github.com/${gitHubRepo}.git</connection>
4040
<developerConnection>scm:git:git@github.com:${gitHubRepo}.git</developerConnection>
4141
<url>https://github.com/${gitHubRepo}</url>
42-
<tag>v1.43.0</tag>
42+
<tag>v99.43.0</tag>
4343
</scm>
4444
<issueManagement>
4545
<system>JIRA</system>
Collapse file

‎src/main/java/org/jenkinsci/plugins/github/util/BuildDataHelper.java‎

Copy file name to clipboardExpand all lines: src/main/java/org/jenkinsci/plugins/github/util/BuildDataHelper.java
+13-2Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ private BuildDataHelper() {
3535
* @return the build data related to the project, null if not found
3636
*/
3737
public static BuildData calculateBuildData(
38-
String parentName, String parentFullName, List<BuildData> buildDataList
38+
int buildNumber, String parentName, String parentFullName, List<BuildData> buildDataList
3939
) {
4040

4141
if (buildDataList == null) {
@@ -46,6 +46,8 @@ public static BuildData calculateBuildData(
4646
return buildDataList.get(0);
4747
}
4848

49+
// This relies upon very specific folder naming schemes and should be replaced with a more generic solution
50+
// See https://issues.jenkins-ci.org/browse/JENKINS-60534
4951
String projectName = parentFullName.replace(parentName, "");
5052

5153
if (projectName.endsWith("/")) {
@@ -62,6 +64,15 @@ public static BuildData calculateBuildData(
6264
}
6365
}
6466

67+
// Sometimes the previous build data is attached along with the current one, and we just want the current one
68+
for (BuildData buildData : buildDataList) {
69+
for (Build build : buildData.buildsByBranchName.values()) {
70+
if (build.getBuildNumber() == buildNumber) {
71+
return buildData;
72+
}
73+
}
74+
}
75+
6576
return null;
6677
}
6778

@@ -80,7 +91,7 @@ public static ObjectId getCommitSHA1(@NonNull Run<?, ?> build) throws IOExceptio
8091
Job<?, ?> parent = build.getParent();
8192

8293
BuildData buildData = calculateBuildData(
83-
parent.getName(), parent.getFullName(), buildDataList
94+
build.number, parent.getName(), parent.getFullName(), buildDataList
8495
);
8596

8697
if (buildData == null) {
Collapse file

‎src/test/java/org/jenkinsci/plugins/github/util/BuildDataHelperTest.java‎

Copy file name to clipboardExpand all lines: src/test/java/org/jenkinsci/plugins/github/util/BuildDataHelperTest.java
+8-8Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public void shouldCalculateDataBuildFromProject() throws Exception {
4141
buildDataList.add(projectBuildData);
4242

4343
BuildData buildData = BuildDataHelper.calculateBuildData(
44-
"master", "project/master", buildDataList);
44+
1, "master", "project/master", buildDataList);
4545

4646
assertThat("should fetch project build data", buildData, is(projectBuildData));
4747
}
@@ -66,7 +66,7 @@ public void shouldCalculateDataBuildFromProjectWithTwoBuildDatas() throws Except
6666
Collections.addAll(buildDataList, sharedLibBuildData, realProjectBuildData);
6767

6868
BuildData buildData = BuildDataHelper.calculateBuildData(
69-
"master", "project/master", buildDataList);
69+
1, "master", "project/master", buildDataList);
7070

7171
assertThat("should not fetch shared library build data", buildData, not(sharedLibBuildData));
7272
assertThat("should fetch project build data", buildData, is(realProjectBuildData));
@@ -76,7 +76,7 @@ public void shouldCalculateDataBuildFromProjectWithTwoBuildDatas() throws Except
7676
@Issue("JENKINS-53149")
7777
public void shouldCalculateDataBuildFromProjectWithEmptyBuildDatas() throws Exception {
7878
BuildData buildData = BuildDataHelper.calculateBuildData(
79-
"master", "project/master", Collections.EMPTY_LIST);
79+
1, "master", "project/master", Collections.EMPTY_LIST);
8080

8181
assertThat("should be null", buildData, nullValue());
8282
}
@@ -85,7 +85,7 @@ public void shouldCalculateDataBuildFromProjectWithEmptyBuildDatas() throws Exce
8585
@Issue("JENKINS-53149")
8686
public void shouldCalculateDataBuildFromProjectWithNullBuildDatas() throws Exception {
8787
BuildData buildData = BuildDataHelper.calculateBuildData(
88-
"master", "project/master", null);
88+
1, "master", "project/master", null);
8989

9090
assertThat("should be null", buildData, nullValue());
9191
}
@@ -110,7 +110,7 @@ public void shouldCalculateDataBuildFromProject() throws Exception {
110110
buildDataList.add(projectBuildData);
111111

112112
BuildData buildData = BuildDataHelper.calculateBuildData(
113-
"master", ORGANIZATION_NAME + "/project/master", buildDataList);
113+
1, "master", ORGANIZATION_NAME + "/project/master", buildDataList);
114114

115115
assertThat("should fetch project build data", buildData, is(projectBuildData));
116116
}
@@ -135,7 +135,7 @@ public void shouldCalculateDataBuildFromProjectWithTwoBuildDatas() throws Except
135135
Collections.addAll(buildDataList, sharedLibBuildData, realProjectBuildData);
136136

137137
BuildData buildData = BuildDataHelper.calculateBuildData(
138-
"master", ORGANIZATION_NAME + "/project/master", buildDataList);
138+
1, "master", ORGANIZATION_NAME + "/project/master", buildDataList);
139139

140140
assertThat("should not fetch shared library build data", buildData, not(sharedLibBuildData));
141141
assertThat("should fetch project build data", buildData, is(realProjectBuildData));
@@ -145,7 +145,7 @@ public void shouldCalculateDataBuildFromProjectWithTwoBuildDatas() throws Except
145145
@Issue("JENKINS-53149")
146146
public void shouldCalculateDataBuildFromProjectWithEmptyBuildDatas() throws Exception {
147147
BuildData buildData = BuildDataHelper.calculateBuildData(
148-
"master", ORGANIZATION_NAME + "/project/master", Collections.EMPTY_LIST);
148+
1, "master", ORGANIZATION_NAME + "/project/master", Collections.EMPTY_LIST);
149149

150150
assertThat("should be null", buildData, nullValue());
151151
}
@@ -154,7 +154,7 @@ public void shouldCalculateDataBuildFromProjectWithEmptyBuildDatas() throws Exce
154154
@Issue("JENKINS-53149")
155155
public void shouldCalculateDataBuildFromProjectWithNullBuildDatas() throws Exception {
156156
BuildData buildData = BuildDataHelper.calculateBuildData(
157-
"master", ORGANIZATION_NAME + "/project/master", null);
157+
1, "master", ORGANIZATION_NAME + "/project/master", null);
158158

159159
assertThat("should be null", buildData, nullValue());
160160
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.