From e3637e12c331db9137ba5c676825ed837ee8408c Mon Sep 17 00:00:00 2001 From: marko-bekhta Date: Wed, 4 Dec 2024 22:23:10 +0100 Subject: [PATCH] Use a dedicated assign api for changing the upstream assignee since updating it through edit doesn't work consistently --- .../jira/service/jira/client/JiraRestClient.java | 13 +++++++++---- .../service/jira/client/JiraRestClientBuilder.java | 5 +++++ .../action/JiraAssigneeActionEventHandler.java | 13 ++++++------- .../replicate/jira/mock/SampleJiraRestClient.java | 5 +++++ 4 files changed, 25 insertions(+), 11 deletions(-) diff --git a/src/main/java/org/hibernate/infra/replicate/jira/service/jira/client/JiraRestClient.java b/src/main/java/org/hibernate/infra/replicate/jira/service/jira/client/JiraRestClient.java index 080b648..4189bf4 100644 --- a/src/main/java/org/hibernate/infra/replicate/jira/service/jira/client/JiraRestClient.java +++ b/src/main/java/org/hibernate/infra/replicate/jira/service/jira/client/JiraRestClient.java @@ -22,7 +22,6 @@ import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.databind.ObjectMapper; import io.quarkus.rest.client.reactive.ClientExceptionMapper; -import io.quarkus.rest.client.reactive.ClientQueryParam; import io.quarkus.rest.client.reactive.jackson.ClientObjectMapper; import jakarta.ws.rs.Consumes; import jakarta.ws.rs.DELETE; @@ -41,8 +40,10 @@ * version (included), e.g.: */ // so that we do not spam with all notifications ... -// since `notifyUsers=false` does not apply to all requests and we've disabled notifications downstream -// this query param is not sent anymore to allow automation updating upstream issues to work with a non-admin user. +// since `notifyUsers=false` does not apply to all requests and we've disabled +// notifications downstream +// this query param is not sent anymore to allow automation updating upstream +// issues to work with a non-admin user. // @ClientQueryParam(name = "notifyUsers", value = "false") public interface JiraRestClient { @@ -150,7 +151,7 @@ JiraIssues find(@QueryParam("jql") String query, @QueryParam("startAt") int star @GET @Path("/issue/{issueKey}/transitions") - JiraTransitions availableTransitions(String issueKey); + JiraTransitions availableTransitions(@PathParam("issueKey") String issueKey); @PUT @Path("/issue/{issueKey}/archive") @@ -172,6 +173,10 @@ JiraIssues find(@QueryParam("jql") String query, @QueryParam("startAt") int star @Path("/version/{id}") JiraVersion update(@PathParam("id") String id, JiraVersion version); + @PUT + @Path("/issue/{issueKey}/assignee") + void assign(@PathParam("issueKey") String id, JiraUser assignee); + @ClientObjectMapper static ObjectMapper objectMapper(ObjectMapper defaultObjectMapper) { return defaultObjectMapper.copy().setDefaultPropertyInclusion(JsonInclude.Include.NON_EMPTY); diff --git a/src/main/java/org/hibernate/infra/replicate/jira/service/jira/client/JiraRestClientBuilder.java b/src/main/java/org/hibernate/infra/replicate/jira/service/jira/client/JiraRestClientBuilder.java index ad07d98..06ae3c6 100644 --- a/src/main/java/org/hibernate/infra/replicate/jira/service/jira/client/JiraRestClientBuilder.java +++ b/src/main/java/org/hibernate/infra/replicate/jira/service/jira/client/JiraRestClientBuilder.java @@ -281,6 +281,11 @@ public JiraVersion update(String id, JiraVersion version) { return withRetry(() -> delegate.update(id, version)); } + @Override + public void assign(String id, JiraUser assignee) { + withRetry(() -> delegate.assign(id, assignee)); + } + private static final int RETRIES = 5; private static final Duration WAIT_BETWEEN_RETRIES = Duration.of(2, ChronoUnit.SECONDS); diff --git a/src/main/java/org/hibernate/infra/replicate/jira/service/jira/handler/action/JiraAssigneeActionEventHandler.java b/src/main/java/org/hibernate/infra/replicate/jira/service/jira/handler/action/JiraAssigneeActionEventHandler.java index ee64b6c..e52345d 100644 --- a/src/main/java/org/hibernate/infra/replicate/jira/service/jira/handler/action/JiraAssigneeActionEventHandler.java +++ b/src/main/java/org/hibernate/infra/replicate/jira/service/jira/handler/action/JiraAssigneeActionEventHandler.java @@ -2,7 +2,6 @@ import org.hibernate.infra.replicate.jira.service.jira.HandlerProjectContext; import org.hibernate.infra.replicate.jira.service.jira.model.action.JiraActionEvent; -import org.hibernate.infra.replicate.jira.service.jira.model.rest.JiraFields; import org.hibernate.infra.replicate.jira.service.jira.model.rest.JiraIssue; import org.hibernate.infra.replicate.jira.service.jira.model.rest.JiraUser; import org.hibernate.infra.replicate.jira.service.reporting.ReportingConfig; @@ -18,20 +17,20 @@ public JiraAssigneeActionEventHandler(ReportingConfig reportingConfig, HandlerPr protected void doRun() { JiraIssue issue = context.destinationJiraClient().getIssue(event.key); - JiraIssue updated = new JiraIssue(); - updated.fields = JiraFields.empty(); + JiraUser user = null; if (issue.fields.assignee != null) { String accountId = context.upstreamUser( issue.fields.assignee.mappedIdentifier(context.projectGroup().users().mappedPropertyName())); if (accountId != null) { - updated.fields.assignee = new JiraUser(accountId); - + user = new JiraUser(accountId); } } else { - updated.fields.assignee = new JiraUser("-1"); + user = new JiraUser("-1"); + } + if (user != null) { + context.sourceJiraClient().assign(toSourceKey(event.key), user); } - context.sourceJiraClient().update(toSourceKey(event.key), updated); } @Override diff --git a/src/test/java/org/hibernate/infra/replicate/jira/mock/SampleJiraRestClient.java b/src/test/java/org/hibernate/infra/replicate/jira/mock/SampleJiraRestClient.java index 8792aff..428f449 100644 --- a/src/test/java/org/hibernate/infra/replicate/jira/mock/SampleJiraRestClient.java +++ b/src/test/java/org/hibernate/infra/replicate/jira/mock/SampleJiraRestClient.java @@ -229,6 +229,11 @@ public JiraVersion update(String id, JiraVersion version) { return version; } + @Override + public void assign(String id, JiraUser assignee) { + // ok + } + private JiraIssueLink sampleIssueLink(Long id) { try { return objectMapper.readValue("""