Skip to content

Commit 7294541

Browse files
committed
Fixed #188
o Added methods to change displayName and description of a build.
1 parent 8c1ffb3 commit 7294541

File tree

3 files changed

+112
-0
lines changed

3 files changed

+112
-0
lines changed

ReleaseNotes.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,21 @@
1414

1515
### API Changes
1616

17+
* [Fixed issue 188][issue-188]
18+
19+
Added methods to update the description and the display name of a build.
20+
21+
```java
22+
public class BuildWithDetails .. {
23+
public void updateDisplayNameAndDescription(String displayName, String description, boolean crumbFlag);
24+
public void updateDisplayNameAndDescription(String displayName, String description);
25+
public void updateDisplayName(String displayName, boolean crumbFlag);
26+
public void updateDisplayName(String displayName);
27+
public void updateDescription(String description, boolean crumbFlag);
28+
public void updateDescription(String description);
29+
}
30+
```
31+
1732
* [Pull Request #206][pull-206] added runScript with `crumbFlag`.
1833

1934
Thanks Rainer W.
@@ -750,6 +765,7 @@ TestReport testReport = mavenJob.getLastSuccessfulBuild().getTestReport();
750765
[issue-179]: https://github.com/jenkinsci/java-client-api/issues/179
751766
[issue-182]: https://github.com/jenkinsci/java-client-api/issues/182
752767
[issue-186]: https://github.com/jenkinsci/java-client-api/issues/186
768+
[issue-188]: https://github.com/jenkinsci/java-client-api/issues/188
753769
[issue-197]: https://github.com/jenkinsci/java-client-api/issues/197
754770
[issue-198]: https://github.com/jenkinsci/java-client-api/issues/198
755771
[issue-200]: https://github.com/jenkinsci/java-client-api/issues/200

jenkins-client/src/main/java/com/offbytwo/jenkins/model/Build.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010

1111
import org.apache.http.client.HttpResponseException;
1212

13+
import com.google.common.collect.ImmutableMap;
14+
1315
public class Build extends BaseModel {
1416

1517
/**

jenkins-client/src/main/java/com/offbytwo/jenkins/model/BuildWithDetails.java

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
import com.google.common.base.Predicate;
1010
import com.google.common.base.Strings;
11+
import com.google.common.collect.ImmutableMap;
1112

1213
import java.io.IOException;
1314
import java.io.InputStream;
@@ -27,6 +28,7 @@ public class BuildWithDetails extends Build {
2728
private List actions; // TODO: Should be improved.
2829
private boolean building;
2930
private String description;
31+
private String displayName;
3032
private long duration;
3133
private long estimatedDuration;
3234
private String fullDisplayName;
@@ -43,9 +45,11 @@ public class BuildWithDetails extends Build {
4345
public BuildWithDetails() {
4446
// Default ctor is needed to jackson.
4547
}
48+
4649
public BuildWithDetails(BuildWithDetails details) {
4750
this.actions = details.actions;
4851
this.description = details.description;
52+
this.displayName = details.displayName;
4953
this.building = details.building;
5054
this.duration = details.duration;
5155
this.estimatedDuration = details.estimatedDuration;
@@ -98,6 +102,81 @@ public boolean apply(Map<String, Object> action) {
98102
return result;
99103
}
100104

105+
/**
106+
* Update <code>displayName</code> and the <code>description</code> of a build.
107+
* @param displayName The new displayName which should be set.
108+
* @param description The description which should be set.
109+
* @param crumbFlag <code>true</code> or <code>false</code>.
110+
* @throws IOException in case of errors.
111+
*/
112+
public void updateDisplayNameAndDescription(String displayName, String description, boolean crumbFlag)
113+
throws IOException {
114+
Objects.requireNonNull(displayName, "displayName is not allowed to be null.");
115+
Objects.requireNonNull(description, "description is not allowed to be null.");
116+
//TODO: Check what the "core:apply" means?
117+
ImmutableMap<String, String> params = ImmutableMap.of("displayName", displayName, "description", description,
118+
"core:apply", "", "Submit", "Save");
119+
client.post_form(this.getUrl() + "/configSubmit?", params, crumbFlag);
120+
}
121+
122+
/**
123+
* Update <code>displayName</code> and the <code>description</code> of a build.
124+
* @param displayName The new displayName which should be set.
125+
* @param description The description which should be set.
126+
* @throws IOException in case of errors.
127+
*/
128+
public void updateDisplayNameAndDescription(String displayName, String description) throws IOException {
129+
updateDisplayNameAndDescription(displayName, description, false);
130+
}
131+
132+
/**
133+
* Update <code>displayName</code> of a build.
134+
* @param displayName The new displayName which should be set.
135+
* @param crumbFlag <code>true</code> or <code>false</code>.
136+
* @throws IOException in case of errors.
137+
*/
138+
public void updateDisplayName(String displayName, boolean crumbFlag) throws IOException {
139+
Objects.requireNonNull(displayName, "displayName is not allowed to be null.");
140+
String description = getDescription() == null ? "" : getDescription();
141+
//TODO: Check what the "core:apply" means?
142+
ImmutableMap<String, String> params = ImmutableMap.of("displayName", displayName, "description",
143+
description, "core:apply", "", "Submit", "Save");
144+
client.post_form(this.getUrl() + "/configSubmit?", params, crumbFlag);
145+
}
146+
147+
/**
148+
* Update <code>displayName</code> of a build.
149+
* @param displayName The new displayName which should be set.
150+
* @throws IOException in case of errors.
151+
*/
152+
public void updateDisplayName(String displayName) throws IOException {
153+
updateDisplayName(displayName, false);
154+
}
155+
156+
/**
157+
* Update the <code>description</code> of a build.
158+
* @param description The description which should be set.
159+
* @param crumbFlag <code>true</code> or <code>false</code>.
160+
* @throws IOException in case of errors.
161+
*/
162+
public void updateDescription(String description, boolean crumbFlag) throws IOException {
163+
Objects.requireNonNull(description, "description is not allowed to be null.");
164+
String displayName = getDisplayName() == null ? "" : getDisplayName();
165+
//TODO: Check what the "core:apply" means?
166+
ImmutableMap<String, String> params = ImmutableMap.of("displayName", displayName, "description",
167+
description, "core:apply", "", "Submit", "Save");
168+
client.post_form(this.getUrl() + "/configSubmit?", params, crumbFlag);
169+
}
170+
171+
/**
172+
* Update the <code>description</code> of a build.
173+
* @param description The description which should be set.
174+
* @throws IOException in case of errors.
175+
*/
176+
public void updateDescription(String description) throws IOException {
177+
updateDescription(description, false);
178+
}
179+
101180
private BuildCause convertToBuildCause(Map<String, Object> cause) {
102181
BuildCause cause_object = new BuildCause();
103182

@@ -150,6 +229,10 @@ public String getFullDisplayName() {
150229
return fullDisplayName;
151230
}
152231

232+
public String getDisplayName() {
233+
return displayName;
234+
}
235+
153236
public String getId() {
154237
return id;
155238
}
@@ -202,6 +285,11 @@ public String getConsoleOutputText() throws IOException {
202285
return client.get(getUrl() + "/logText/progressiveText");
203286
}
204287

288+
/**
289+
* The console output with HTML.
290+
* @return The console output as HTML.
291+
* @throws IOException
292+
*/
205293
public String getConsoleOutputHtml() throws IOException {
206294
return client.get(getUrl() + "/logText/progressiveHtml");
207295
}
@@ -287,6 +375,11 @@ public boolean equals(Object obj) {
287375
return false;
288376
} else if (!description.equals(other.description))
289377
return false;
378+
if (displayName == null) {
379+
if (other.displayName != null)
380+
return false;
381+
} else if (!displayName.equals(other.displayName))
382+
return false;
290383
if (duration != other.duration)
291384
return false;
292385
if (estimatedDuration != other.estimatedDuration)
@@ -321,6 +414,7 @@ public int hashCode() {
321414
result = prime * result + ((consoleOutputText == null) ? 0 : consoleOutputText.hashCode());
322415
result = prime * result + ((culprits == null) ? 0 : culprits.hashCode());
323416
result = prime * result + ((description == null) ? 0 : description.hashCode());
417+
result = prime * result + ((displayName == null) ? 0 : displayName.hashCode());
324418
result = prime * result + (int) (duration ^ (duration >>> 32));
325419
result = prime * result + (int) (estimatedDuration ^ (estimatedDuration >>> 32));
326420
result = prime * result + ((fullDisplayName == null) ? 0 : fullDisplayName.hashCode());

0 commit comments

Comments
 (0)