-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add handling of downstream automation events
- Loading branch information
1 parent
faed79c
commit 478ba6d
Showing
14 changed files
with
386 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
...rg/hibernate/infra/replicate/jira/service/jira/handler/action/JiraActionEventHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package org.hibernate.infra.replicate.jira.service.jira.handler.action; | ||
|
||
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.JiraIssue; | ||
import org.hibernate.infra.replicate.jira.service.reporting.FailureCollector; | ||
import org.hibernate.infra.replicate.jira.service.reporting.ReportingConfig; | ||
|
||
import io.quarkus.logging.Log; | ||
|
||
public abstract class JiraActionEventHandler implements Runnable { | ||
|
||
protected final JiraActionEvent event; | ||
protected final FailureCollector failureCollector; | ||
protected final HandlerProjectContext context; | ||
|
||
protected JiraActionEventHandler(ReportingConfig reportingConfig, HandlerProjectContext context, | ||
JiraActionEvent event) { | ||
this.event = event; | ||
this.failureCollector = FailureCollector.collector(reportingConfig); | ||
this.context = context; | ||
} | ||
|
||
@Override | ||
public final void run() { | ||
try { | ||
context.startProcessingDownstreamEvent(); | ||
doRun(); | ||
} catch (RuntimeException e) { | ||
failureCollector.critical("Failed to handled the event: %s".formatted(this), e); | ||
} catch (InterruptedException e) { | ||
failureCollector.critical("Interrupted while waiting in the queue", e); | ||
Thread.currentThread().interrupt(); | ||
} finally { | ||
failureCollector.close(); | ||
Log.infof("Finished processing %s. Pending events in %s to process: %s", this.toString(), | ||
context.projectGroupName(), context.pendingDownstreamEventsInCurrentContext()); | ||
} | ||
} | ||
|
||
protected String toSourceKey(String key) { | ||
return "%s-%d".formatted(context.project().originalProjectKey(), JiraIssue.keyToLong(key)); | ||
} | ||
|
||
protected abstract void doRun(); | ||
|
||
public abstract String toString(); | ||
|
||
} |
41 changes: 41 additions & 0 deletions
41
...nate/infra/replicate/jira/service/jira/handler/action/JiraAssigneeActionEventHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package org.hibernate.infra.replicate.jira.service.jira.handler.action; | ||
|
||
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; | ||
|
||
public class JiraAssigneeActionEventHandler extends JiraActionEventHandler { | ||
|
||
public JiraAssigneeActionEventHandler(ReportingConfig reportingConfig, HandlerProjectContext context, | ||
JiraActionEvent event) { | ||
super(reportingConfig, context, event); | ||
} | ||
|
||
@Override | ||
protected void doRun() { | ||
JiraIssue issue = context.destinationJiraClient().getIssue(event.key); | ||
|
||
JiraIssue updated = new JiraIssue(); | ||
updated.fields = JiraFields.empty(); | ||
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); | ||
|
||
} | ||
} else { | ||
updated.fields.assignee = new JiraUser("-1"); | ||
} | ||
context.sourceJiraClient().update(toSourceKey(event.key), updated); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "JiraAssigneeActionEventHandler[" + "event=" + event + ", project=" + context.projectName() + ']'; | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
...in/java/org/hibernate/infra/replicate/jira/service/jira/model/action/JiraActionEvent.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package org.hibernate.infra.replicate.jira.service.jira.model.action; | ||
|
||
import java.util.Optional; | ||
|
||
import org.hibernate.infra.replicate.jira.service.jira.model.JiraBaseObject; | ||
import org.hibernate.infra.replicate.jira.service.jira.model.hook.JiraActionEventType; | ||
|
||
public class JiraActionEvent extends JiraBaseObject { | ||
public String id; | ||
public String key; | ||
public String event; | ||
public String assignee; | ||
public String status; | ||
|
||
public String triggeredByUser; | ||
|
||
public Optional<JiraActionEventType> eventType() { | ||
return JiraActionEventType.of(event); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "JiraActionEvent{" + "id='" + id + '\'' + ", key='" + key + '\'' + ", event='" + event + '\'' | ||
+ ", assignee='" + assignee + '\'' + ", status='" + status + '\'' + '}'; | ||
} | ||
} |
Oops, something went wrong.