Skip to content

Commit

Permalink
Use a dedicated assign api for changing the upstream assignee
Browse files Browse the repository at this point in the history
since updating it through edit doesn't work consistently
  • Loading branch information
marko-bekhta committed Dec 4, 2024
1 parent 1b1f0f3 commit 80e8295
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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 {

Expand Down Expand Up @@ -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")
Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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("""
Expand Down

0 comments on commit 80e8295

Please sign in to comment.