Skip to content

Commit 5968565

Browse files
committed
Fixed #211
o Added methods to update/clear the description of a job.
1 parent 1b0c1e8 commit 5968565

File tree

2 files changed

+78
-2
lines changed

2 files changed

+78
-2
lines changed

ReleaseNotes.md

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

1515
### API Changes
1616

17+
* [Fixed issue 211][issue-211]
18+
19+
Added methods to update/clear the description of a job.
20+
21+
```java
22+
public class JobWithDetails .. {
23+
public void updateDescription(String description);
24+
public void updateDescription(String description, boolean crumbFlag);
25+
public void clearDescription();
26+
public void clearDescription(boolean crumbFlag);
27+
```
28+
1729
* [Fixed issue 188][issue-188]
1830

1931
Added methods to update the description and the display name of a build.
@@ -773,6 +785,7 @@ TestReport testReport = mavenJob.getLastSuccessfulBuild().getTestReport();
773785
[issue-202]: https://github.com/jenkinsci/java-client-api/issues/202
774786
[issue-203]: https://github.com/jenkinsci/java-client-api/issues/203
775787
[issue-207]: https://github.com/jenkinsci/java-client-api/issues/207
788+
[issue-211]: https://github.com/jenkinsci/java-client-api/issues/211
776789
[pull-123]: https://github.com/jenkinsci/java-client-api/pull/123
777790
[pull-149]: https://github.com/jenkinsci/java-client-api/pull/149
778791
[pull-158]: https://github.com/jenkinsci/java-client-api/pull/158

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

Lines changed: 65 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,15 @@
1111
import java.io.IOException;
1212
import java.util.Collections;
1313
import java.util.List;
14+
import java.util.Objects;
1415

1516
import org.apache.http.HttpStatus;
1617
import org.apache.http.client.HttpResponseException;
1718

1819
import com.google.common.base.Function;
1920
import com.google.common.base.Optional;
2021
import com.google.common.base.Predicate;
22+
import com.google.common.collect.ImmutableMap;
2123
import com.google.common.collect.Iterables;
2224
import com.offbytwo.jenkins.client.util.EncodingUtils;
2325
import com.offbytwo.jenkins.helper.Range;
@@ -339,9 +341,10 @@ public QueueItem getQueueItem() {
339341
/**
340342
* Get a build by the given buildNumber.
341343
*
342-
* @param buildNumber The number to select the build by.
344+
* @param buildNumber
345+
* The number to select the build by.
343346
* @return The {@link Build} selected by the given buildnumber
344-
*
347+
*
345348
*/
346349
public Build getBuildByNumber(final int buildNumber) {
347350

@@ -366,6 +369,66 @@ public Job apply(Job job) {
366369
}
367370
}
368371

372+
/**
373+
* Empty description to be used for {@link #updateDescription(String)}
374+
* or {@link #updateDescription(String, boolean)}.
375+
*/
376+
public static final String EMPTY_DESCRIPTION = "";
377+
378+
/**
379+
* Update the <code>description</code> of a Job.
380+
*
381+
* @param description
382+
* The description which should be set.
383+
* If you like to set an empty description
384+
* you should use {@link #EMPTY_DESCRIPTION}.
385+
* @throws IOException
386+
* in case of errors.
387+
*/
388+
public void updateDescription(String description) throws IOException {
389+
updateDescription(description, false);
390+
}
391+
392+
/**
393+
* Update the <code>description</code> of a Job.
394+
*
395+
* @param description
396+
* The description which should be set.
397+
* If you like to set an empty description
398+
* you should use {@link #EMPTY_DESCRIPTION}.
399+
* @param crumbFlag
400+
* <code>true</code> or <code>false</code>.
401+
* @throws IOException
402+
* in case of errors.
403+
*/
404+
public void updateDescription(String description, boolean crumbFlag) throws IOException {
405+
Objects.requireNonNull(description, "description is not allowed to be null.");
406+
ImmutableMap<String, String> params = ImmutableMap.of("description", description);
407+
client.post_form(this.getUrl() + "/submitDescription?", params, crumbFlag);
408+
}
409+
410+
/**
411+
* clear the description of a job.
412+
*
413+
* @throws IOException
414+
* in case of errors.
415+
*/
416+
public void clearDescription() throws IOException {
417+
updateDescription(EMPTY_DESCRIPTION);
418+
}
419+
420+
/**
421+
* clear the description of a job.
422+
*
423+
* @param crumbFlag
424+
* <code>true</code> or <code>false</code>.
425+
* @throws IOException
426+
* in case of errors.
427+
*/
428+
public void clearDescription(boolean crumbFlag) throws IOException {
429+
updateDescription(EMPTY_DESCRIPTION, crumbFlag);
430+
}
431+
369432
@Override
370433
public int hashCode() {
371434
final int prime = 31;

0 commit comments

Comments
 (0)