-
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 more automation events
- Loading branch information
1 parent
c1add9d
commit 165ec42
Showing
16 changed files
with
251 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
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
54 changes: 54 additions & 0 deletions
54
...fra/replicate/jira/service/jira/handler/action/JiraAbstractVersionActionEventHandler.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,54 @@ | ||
package org.hibernate.infra.replicate.jira.service.jira.handler.action; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
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.JiraVersion; | ||
import org.hibernate.infra.replicate.jira.service.reporting.ReportingConfig; | ||
|
||
abstract class JiraAbstractVersionActionEventHandler extends JiraActionEventHandler { | ||
|
||
public JiraAbstractVersionActionEventHandler(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(); | ||
|
||
List<JiraVersion> versionList = versionList(issue); | ||
|
||
List<JiraVersion> versions; | ||
if (versionList != null) { | ||
versions = new ArrayList<>(versionList.size()); | ||
for (JiraVersion ver : versionList) { | ||
JiraVersion version = new JiraVersion(); | ||
version.name = ver.name; | ||
versions.add(version); | ||
} | ||
} else { | ||
versions = List.of(); | ||
} | ||
|
||
setVersionList(updated, versions); | ||
|
||
context.sourceJiraClient().update(toSourceKey(event.key), updated); | ||
} | ||
|
||
protected abstract void setVersionList(JiraIssue issue, List<JiraVersion> versions); | ||
|
||
protected abstract List<JiraVersion> versionList(JiraIssue issue); | ||
|
||
@Override | ||
public String toString() { | ||
return this.getClass().getSimpleName() + "[" + "event=" + event + ", project=" + context.projectName() + ']'; | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
...nfra/replicate/jira/service/jira/handler/action/JiraAffectsVersionActionEventHandler.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.handler.action; | ||
|
||
import java.util.List; | ||
|
||
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.jira.model.rest.JiraVersion; | ||
import org.hibernate.infra.replicate.jira.service.reporting.ReportingConfig; | ||
|
||
public class JiraAffectsVersionActionEventHandler extends JiraAbstractVersionActionEventHandler { | ||
|
||
public JiraAffectsVersionActionEventHandler(ReportingConfig reportingConfig, HandlerProjectContext context, | ||
JiraActionEvent event) { | ||
super(reportingConfig, context, event); | ||
} | ||
|
||
protected void setVersionList(JiraIssue issue, List<JiraVersion> versions) { | ||
issue.fields.versions = versions; | ||
} | ||
|
||
protected List<JiraVersion> versionList(JiraIssue issue) { | ||
return issue.fields.versions; | ||
} | ||
|
||
} |
26 changes: 26 additions & 0 deletions
26
...te/infra/replicate/jira/service/jira/handler/action/JiraFixVersionActionEventHandler.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.handler.action; | ||
|
||
import java.util.List; | ||
|
||
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.jira.model.rest.JiraVersion; | ||
import org.hibernate.infra.replicate.jira.service.reporting.ReportingConfig; | ||
|
||
public class JiraFixVersionActionEventHandler extends JiraAbstractVersionActionEventHandler { | ||
|
||
public JiraFixVersionActionEventHandler(ReportingConfig reportingConfig, HandlerProjectContext context, | ||
JiraActionEvent event) { | ||
super(reportingConfig, context, event); | ||
} | ||
|
||
protected void setVersionList(JiraIssue issue, List<JiraVersion> versions) { | ||
issue.fields.fixVersions = versions; | ||
} | ||
|
||
protected List<JiraVersion> versionList(JiraIssue issue) { | ||
return issue.fields.fixVersions; | ||
} | ||
|
||
} |
58 changes: 58 additions & 0 deletions
58
...te/infra/replicate/jira/service/jira/handler/action/JiraTransitionActionEventHandler.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,58 @@ | ||
package org.hibernate.infra.replicate.jira.service.jira.handler.action; | ||
|
||
import java.util.Locale; | ||
import java.util.Optional; | ||
import java.util.Set; | ||
import java.util.function.Supplier; | ||
|
||
import org.hibernate.infra.replicate.jira.service.jira.HandlerProjectContext; | ||
import org.hibernate.infra.replicate.jira.service.jira.handler.JiraStaticFieldMappingCache; | ||
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.jira.model.rest.JiraTransition; | ||
import org.hibernate.infra.replicate.jira.service.jira.model.rest.JiraTransitions; | ||
import org.hibernate.infra.replicate.jira.service.reporting.ReportingConfig; | ||
|
||
public class JiraTransitionActionEventHandler extends JiraActionEventHandler { | ||
|
||
public JiraTransitionActionEventHandler(ReportingConfig reportingConfig, HandlerProjectContext context, | ||
JiraActionEvent event) { | ||
super(reportingConfig, context, event); | ||
} | ||
|
||
@Override | ||
protected void doRun() { | ||
String sourceKey = toSourceKey(event.key); | ||
JiraIssue issue = context.destinationJiraClient().getIssue(event.key); | ||
JiraIssue sourceIssue = context.sourceJiraClient().getIssue(sourceKey); | ||
|
||
String statusDownstream = issue.fields.status.name.toLowerCase(Locale.ROOT); | ||
String statusCurrent = sourceIssue.fields.status.name.toLowerCase(Locale.ROOT); | ||
|
||
if (context.projectGroup().statuses().ignoreTransitionCondition().getOrDefault(statusCurrent, Set.of()) | ||
.contains(statusDownstream)) { | ||
return; | ||
} | ||
|
||
String statusNew = context.upstreamStatus(statusDownstream); | ||
|
||
prepareTransition(statusNew, sourceIssue) | ||
.ifPresent(jiraTransition -> context.sourceJiraClient().transition(sourceKey, jiraTransition)); | ||
} | ||
|
||
protected Optional<JiraTransition> prepareTransition(String upstreamStatus, JiraIssue issue) { | ||
return statusToTransition(issue.fields.status.name, upstreamStatus, () -> JiraTransitions | ||
.findRequiredTransitionId(context.sourceJiraClient(), failureCollector, upstreamStatus, issue)) | ||
.map(JiraTransition::new); | ||
} | ||
|
||
protected Optional<String> statusToTransition(String from, String to, Supplier<Optional<String>> transitionFinder) { | ||
return Optional.ofNullable(JiraStaticFieldMappingCache.statusUpstream(context.projectGroupName(), | ||
"%s->%s".formatted(from, to), tk -> transitionFinder.get().orElse(null))); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "JiraAssigneeActionEventHandler[" + "event=" + event + ", project=" + context.projectName() + ']'; | ||
} | ||
} |
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
Oops, something went wrong.