Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set an issue to Unassigned #85

Merged
merged 3 commits into from
Feb 10, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions hugo/content/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ lastmodifierdisplayname = "Naresh Rayapati"
+++

* #### **1.4.5** (Unreleased)
* Use 'null' as assignee to set an issue to unassigned.

* #### **1.4.4**
* [JENKINS-53044](https://issues.jenkins-ci.org/browse/JENKINS-53044) Add step to retrieve jira server info.
Expand Down
7 changes: 6 additions & 1 deletion hugo/content/steps/issue/jira_assign_issue.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ description = "More about jiraAssignIssue step."
tags = ["steps", "issue"]
weight = 4
date = "2017-11-12"
lastmodifierdisplayname = "Naresh Rayapati"
lastmodifierdisplayname = "Benedikt Hr"
+++

### jiraAssignIssue
Expand Down Expand Up @@ -60,3 +60,8 @@ It supports all the fields that any jira instance supports including custom fiel
```groovy
jiraAssignIssue site: 'LOCAL', idOrKey: 'TEST-1', userName: 'Jenkins'
```
* A null name will remove the assignee.

```groovy
jiraAssignIssue site: 'LOCAL', idOrKey: 'TEST-1', userName: null
```
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import okhttp3.OkHttpClient;
import okhttp3.RequestBody;
import okhttp3.ResponseBody;
import com.google.common.collect.Maps;
import org.thoughtslive.jenkins.plugins.jira.Site;
import org.thoughtslive.jenkins.plugins.jira.api.ResponseData;
import org.thoughtslive.jenkins.plugins.jira.login.SigningInterceptor;
Expand Down Expand Up @@ -153,9 +154,11 @@ public ResponseData<Object> updateIssue(final String issueIdOrKey, final Object

public ResponseData<Void> assignIssue(final String issueIdorKey, final String userName) {
try {
Map input = Maps.newHashMap();
input.put("name", userName);
return parseResponse(
jiraEndPoints
.assignIssue(issueIdorKey, ImmutableMap.builder().put("name", userName).build())
.assignIssue(issueIdorKey, input)
.execute());
} catch (Exception e) {
return buildErrorResponse(e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,14 +87,13 @@ protected <T> ResponseData<T> verifyInput() throws Exception {

if (response == null) {
final String idOrKey = Util.fixEmpty(step.getIdOrKey());
final String userName = Util.fixEmpty(step.getUserName());

if (idOrKey == null) {
errorMessage = "idOrKey is empty or null.";
}

if (userName == null) {
errorMessage = "userName is empty or null.";
if (step.getUserName() != null && step.getUserName().isEmpty()) {
errorMessage = "userName is empty.";
}

if (errorMessage != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,10 +101,24 @@ public void testWithEmptyCommentThrowsAbortException() throws Exception {
// Execute and assert Test.
assertThatExceptionOfType(AbortException.class).isThrownBy(() -> {
stepExecution.run();
}).withMessage("userName is empty or null.").withStackTraceContaining("AbortException")
}).withMessage("userName is empty.").withStackTraceContaining("AbortException")
.withNoCause();
}

@Test
public void testSuccessfulUnassignIssue() throws Exception {
final AssignIssueStep step = new AssignIssueStep("TEST-1", null);
stepExecution = new AssignIssueStep.Execution(step, contextMock);
;

// Execute Test.
stepExecution.run();

// Assert Test
verify(jiraServiceMock, times(1)).assignIssue("TEST-1", null);
assertThat(step.isFailOnError()).isEqualTo(true);
}

@Test
public void testSuccessfulAssignIssue() throws Exception {
final AssignIssueStep step = new AssignIssueStep("TEST-1", "testUser");
Expand Down