diff --git a/src/main/java/org/thoughtslive/jenkins/plugins/jira/service/JiraService.java b/src/main/java/org/thoughtslive/jenkins/plugins/jira/service/JiraService.java index b33cb309..49a8754d 100644 --- a/src/main/java/org/thoughtslive/jenkins/plugins/jira/service/JiraService.java +++ b/src/main/java/org/thoughtslive/jenkins/plugins/jira/service/JiraService.java @@ -193,10 +193,15 @@ public ResponseData updateIssue(final String issueIdOrKey, final Object } } - public ResponseData assignIssue(final String issueIdorKey, final String userName) { + public ResponseData assignIssue(final String issueIdorKey, final String userName, + final String accountId) { try { Map input = Maps.newHashMap(); - input.put("name", userName); + if (userName != null) { + input.put("name", userName); + } else { + input.put("accountId", accountId); + } return parseResponse( jiraEndPoints .assignIssue(issueIdorKey, input) diff --git a/src/main/java/org/thoughtslive/jenkins/plugins/jira/steps/AssignIssueStep.java b/src/main/java/org/thoughtslive/jenkins/plugins/jira/steps/AssignIssueStep.java index 4fcaf33a..e046441f 100644 --- a/src/main/java/org/thoughtslive/jenkins/plugins/jira/steps/AssignIssueStep.java +++ b/src/main/java/org/thoughtslive/jenkins/plugins/jira/steps/AssignIssueStep.java @@ -76,10 +76,11 @@ protected ResponseData run() throws Exception { ResponseData response = verifyInput(); if (response == null) { - final String userName = Util.fixEmpty(step.getUserName()) == null ? Util.fixEmpty(step.getAccountId()) : Util.fixEmpty(step.getUserName()); + final String userName = Util.fixEmpty(step.getUserName()); + final String accountId = Util.fixEmpty(step.getAccountId()); logger.println("JIRA: Site - " + siteName + " - Assigning issue: " + step.getIdOrKey() - + " to: " + userName); - response = jiraService.assignIssue(step.getIdOrKey(), userName); + + " to username: " + userName + " / accountId: " + accountId); + response = jiraService.assignIssue(step.getIdOrKey(), userName, accountId); } return logResponse(response); diff --git a/src/test/java/org/thoughtslive/jenkins/plugins/jira/steps/AssignIssueStepTest.java b/src/test/java/org/thoughtslive/jenkins/plugins/jira/steps/AssignIssueStepTest.java index c4bfb1f9..6047d939 100644 --- a/src/test/java/org/thoughtslive/jenkins/plugins/jira/steps/AssignIssueStepTest.java +++ b/src/test/java/org/thoughtslive/jenkins/plugins/jira/steps/AssignIssueStepTest.java @@ -70,7 +70,7 @@ public void setup() throws IOException, InterruptedException { doNothing().when(printStreamMock).println(); final ResponseDataBuilder builder = ResponseData.builder(); - when(jiraServiceMock.assignIssue(any(), any())) + when(jiraServiceMock.assignIssue(any(), any(), any())) .thenReturn(builder.successful(true).code(200).message("Success").build()); when(contextMock.get(Run.class)).thenReturn(runMock); @@ -99,7 +99,7 @@ public void testWithEmptyUserNameOrAccountIdThrowsAbortException() throws Except stepExecution.run(); // Assert Test - verify(jiraServiceMock, times(1)).assignIssue("TEST-1", null); + verify(jiraServiceMock, times(1)).assignIssue("TEST-1", null, null); assertThat(step.isFailOnError()).isEqualTo(true); } @@ -112,7 +112,7 @@ public void testSuccessfulUnassignIssue() throws Exception { stepExecution.run(); // Assert Test - verify(jiraServiceMock, times(1)).assignIssue("TEST-1", null); + verify(jiraServiceMock, times(1)).assignIssue("TEST-1", null, null); assertThat(step.isFailOnError()).isEqualTo(true); } @@ -125,7 +125,7 @@ public void testSuccessfulAssignIssue() throws Exception { stepExecution.run(); // Assert Test - verify(jiraServiceMock, times(1)).assignIssue("TEST-1", "testUser"); + verify(jiraServiceMock, times(1)).assignIssue("TEST-1", "testUser", null); assertThat(step.isFailOnError()).isEqualTo(true); } @@ -138,7 +138,7 @@ public void testSuccessfulAssignIssueByAccountId() throws Exception { stepExecution.run(); // Assert Test - verify(jiraServiceMock, times(1)).assignIssue("TEST-1", "testUser"); + verify(jiraServiceMock, times(1)).assignIssue("TEST-1", null, "testUser"); assertThat(step.isFailOnError()).isEqualTo(true); } }