Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix overzealous label state mapper #131

Merged
merged 4 commits into from
Sep 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions sync-github/src/main/kotlin/gropius/sync/github/IssuePile.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package gropius.sync.github

import com.fasterxml.jackson.databind.JsonNode
import gropius.model.architecture.IMSProject
import gropius.model.architecture.Project
import gropius.model.issue.Issue
import gropius.model.issue.timeline.*
import gropius.sync.*
Expand All @@ -13,7 +12,6 @@ import gropius.sync.github.generated.fragment.AssignedEventTimelineItemData.Assi
import gropius.sync.github.generated.fragment.TimelineItemData.Companion.asNode
import gropius.sync.github.generated.fragment.UnassignedEventTimelineItemData.Assignee.Companion.userData
import jakarta.transaction.Transactional
import kotlinx.coroutines.reactive.awaitFirst
import kotlinx.coroutines.reactor.awaitSingle
import org.bson.types.ObjectId
import org.springframework.data.annotation.Id
Expand Down Expand Up @@ -536,18 +534,19 @@ class UnassignedTimelineItem(
val convInfo =
timelineItemConversionInformation ?: TODOTimelineItemConversionInformation(imsProject.rawId!!, githubId);
val githubService = service as GithubDataService
// TODO
if ((createdBy != null)) {
val gropiusId = convInfo.gropiusId
val event = if (gropiusId != null) githubService.neoOperations.findById<RemovedAssignmentEvent>(
gropiusId
) else RemovedAssignmentEvent(createdAt, createdAt)
if (event == null) {
val opposite = issue.timelineItems().filterIsInstance<Assignment>().sortedBy { it.createdAt }
.lastOrNull { it.user().value.username == user }
if ((event == null) || (opposite == null)) {
return listOf<TimelineItem>() to convInfo;
}
event.createdBy().value = githubService.mapUser(imsProject, createdBy)
event.lastModifiedBy().value = githubService.mapUser(imsProject, createdBy)
event.removedAssignment().value = TODO()
event.removedAssignment().value = opposite
return listOf<TimelineItem>(event) to convInfo;
}
return listOf<TimelineItem>() to convInfo;
Expand Down
21 changes: 18 additions & 3 deletions sync-jira/src/main/kotlin/gropius/sync/jira/JiraDataService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package gropius.sync.jira
import com.fasterxml.jackson.databind.JsonNode
import com.fasterxml.jackson.databind.ObjectMapper
import gropius.model.architecture.IMSProject
import gropius.model.issue.Issue
import gropius.model.issue.Label
import gropius.model.template.*
import gropius.model.user.GropiusUser
Expand Down Expand Up @@ -135,14 +136,28 @@ class JiraDataService(

/**
* Get the default issue state
* @param imsProject the ims project to work on
* @param issue the issue to work on (sometimes not yet saved or complete)
* @param isOpen whether the issue state is open or closed
* @return the default issue state
*/
suspend fun issueState(imsProject: IMSProject, isOpen: Boolean): IssueState {
suspend fun issueState(imsProject: IMSProject, issue: Issue?, isOpen: Boolean): IssueState {
nk-coding marked this conversation as resolved.
Show resolved Hide resolved
nk-coding marked this conversation as resolved.
Show resolved Hide resolved
nk-coding marked this conversation as resolved.
Show resolved Hide resolved
val newIssueState = IssueState(if (isOpen) "open" else "closed", "", isOpen)
newIssueState.partOf() += issueTemplate(imsProject)
return neoOperations.findAll(IssueState::class.java).filter { it.isOpen == isOpen }.awaitFirstOrNull()
?: neoOperations.save(newIssueState).awaitSingle()
return (issue?.template?.invoke()?.value ?: issueTemplate(imsProject)).issueStates()
.firstOrNull { it.isOpen == isOpen } ?: neoOperations.save(newIssueState).awaitSingle()
}

/**
* Get the named issue state
* @param imsProject the ims project to work on
* @param issue the issue to work on (sometimes not yet saved or complete)
* @param isOpen whether the issue state is open or closed
nk-coding marked this conversation as resolved.
Show resolved Hide resolved
* @return the default issue state
*/
suspend fun issueState(imsProject: IMSProject, issue: Issue?, name: String): IssueState? {
return (issue?.template?.invoke()?.value ?: issueTemplate(imsProject)).issueStates()
.firstOrNull { it.name == name }
}

/**
Expand Down
4 changes: 2 additions & 2 deletions sync-jira/src/main/kotlin/gropius/sync/jira/JiraSync.kt
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,8 @@ final class JiraSync(
for (imsProject in imsProjects) {
jiraDataService.issueTemplate(imsProject)
jiraDataService.issueType(imsProject)
jiraDataService.issueState(imsProject, true)
jiraDataService.issueState(imsProject, false)
jiraDataService.issueState(imsProject, null, true)
jiraDataService.issueState(imsProject, null, false)
}

for (imsProject in imsProjects) {
Expand Down
75 changes: 56 additions & 19 deletions sync-jira/src/main/kotlin/gropius/sync/jira/model/IssueData.kt
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,11 @@ class JiraTimelineItem(val id: String, val created: String, val author: JsonObje
return gropiusSummary(timelineItemConversionInformation, imsProject, service, jiraService)
} else if (fieldId == "resolution") {
return gropiusState(
timelineItemConversionInformation, imsProject, service, jiraService
timelineItemConversionInformation, imsProject, service, jiraService, issue
)
} else if (fieldId == "state") {
return gropiusNamedState(
timelineItemConversionInformation, imsProject, service, jiraService, issue
)
} else if (fieldId == "labels") {
return gropiusLabels(
Expand Down Expand Up @@ -122,9 +126,7 @@ class JiraTimelineItem(val id: String, val created: String, val author: JsonObje
)
templateEvent.createdBy().value = jiraService.mapUser(imsProject, author)
templateEvent.lastModifiedBy().value = jiraService.mapUser(imsProject, author)
return listOf<TimelineItem>(
templateEvent
) to convInfo;
return listOf<TimelineItem>(templateEvent) to convInfo;
}

/**
Expand Down Expand Up @@ -179,9 +181,7 @@ class JiraTimelineItem(val id: String, val created: String, val author: JsonObje
removedLabelEvent.createdBy().value = jiraService.mapUser(imsProject, author)
removedLabelEvent.lastModifiedBy().value = jiraService.mapUser(imsProject, author)
removedLabelEvent.removedLabel().value = jiraService.mapLabel(imsProject, removedLabel)
return listOf<TimelineItem>(
removedLabelEvent
) to convInfo;
return listOf<TimelineItem>(removedLabelEvent) to convInfo;
}
return listOf<TimelineItem>() to convInfo;
}
Expand All @@ -192,13 +192,15 @@ class JiraTimelineItem(val id: String, val created: String, val author: JsonObje
* @param imsProject the ims project
* @param service the service
* @param jiraService the jira service
* @param issue the issue to work on (sometimes not yet saved or complete)
* @return the pair of timeline items and conversion information
*/
private suspend fun gropiusState(
timelineItemConversionInformation: TimelineItemConversionInformation?,
imsProject: IMSProject,
service: JiraDataService,
jiraService: JiraDataService
jiraService: JiraDataService,
issue: Issue
nk-coding marked this conversation as resolved.
Show resolved Hide resolved
): Pair<List<TimelineItem>, TimelineItemConversionInformation> {
val convInfo =
timelineItemConversionInformation ?: JiraTimelineItemConversionInformation(imsProject.rawId!!, id);
Expand All @@ -209,17 +211,54 @@ class JiraTimelineItem(val id: String, val created: String, val author: JsonObje
) else null) ?: StateChangedEvent(
OffsetDateTime.parse(
created, IssueData.formatter
), OffsetDateTime.parse(
).minusNanos(1), OffsetDateTime.parse(
created, IssueData.formatter
)
).minusNanos(1)
)
titleChangedEvent.createdBy().value = jiraService.mapUser(imsProject, author)
titleChangedEvent.lastModifiedBy().value = jiraService.mapUser(imsProject, author)
titleChangedEvent.oldState().value = jiraService.issueState(imsProject, data.fromString == null)
titleChangedEvent.newState().value = jiraService.issueState(imsProject, data.toString == null)
return listOf<TimelineItem>(
titleChangedEvent
) to convInfo;
titleChangedEvent.oldState().value = jiraService.issueState(imsProject, issue, data.fromString == null)
titleChangedEvent.newState().value = jiraService.issueState(imsProject, issue, data.toString == null)
return listOf<TimelineItem>(titleChangedEvent) to convInfo;
}

/**
* Convert a single state change to a Gropius StateChangedEvent
* @param timelineItemConversionInformation the timeline item conversion information
* @param imsProject the ims project
* @param service the service
* @param jiraService the jira service
* @param issue the issue to work on (sometimes not yet saved or complete)
* @return the pair of timeline items and conversion information
*/
private suspend fun gropiusNamedState(
timelineItemConversionInformation: TimelineItemConversionInformation?,
imsProject: IMSProject,
service: JiraDataService,
jiraService: JiraDataService,
issue: Issue
nk-coding marked this conversation as resolved.
Show resolved Hide resolved
): Pair<List<TimelineItem>, TimelineItemConversionInformation> {
val newState = jiraService.issueState(imsProject, issue, data.toString!!)
?: return listOf<TimelineItem>() to JiraTimelineItemConversionInformation(imsProject.rawId!!, id)
val convInfo =
timelineItemConversionInformation ?: JiraTimelineItemConversionInformation(imsProject.rawId!!, id);
val timelineId = timelineItemConversionInformation?.gropiusId
val stateChangedEvent: StateChangedEvent =
(if (timelineId != null) service.neoOperations.findById<StateChangedEvent>(
timelineId
) else null) ?: StateChangedEvent(
nk-coding marked this conversation as resolved.
Show resolved Hide resolved
OffsetDateTime.parse(
created, IssueData.formatter
), OffsetDateTime.parse(
created, IssueData.formatter
)
)
stateChangedEvent.createdBy().value = jiraService.mapUser(imsProject, author)
stateChangedEvent.lastModifiedBy().value = jiraService.mapUser(imsProject, author)
stateChangedEvent.oldState().value =
jiraService.issueState(imsProject, issue, data.fromString!!) ?: issue.state().value
stateChangedEvent.newState().value = newState
return listOf<TimelineItem>(stateChangedEvent) to convInfo;
}

/**
Expand Down Expand Up @@ -251,9 +290,7 @@ class JiraTimelineItem(val id: String, val created: String, val author: JsonObje
)
titleChangedEvent.createdBy().value = jiraService.mapUser(imsProject, author)
titleChangedEvent.lastModifiedBy().value = jiraService.mapUser(imsProject, author)
return listOf<TimelineItem>(
titleChangedEvent
) to convInfo;
return listOf<TimelineItem>(titleChangedEvent) to convInfo;
}
}

Expand Down Expand Up @@ -394,7 +431,7 @@ data class IssueData(
issue.createdBy().value = jiraService.mapUser(imsProject, fields["creator"]!!)
issue.lastModifiedBy().value = jiraService.mapUser(imsProject, fields["creator"]!!)
issue.body().value.issue().value = issue
issue.state().value = jiraService.issueState(imsProject, true)
issue.state().value = jiraService.issueState(imsProject, null, true)
issue.template().value = jiraService.issueTemplate(imsProject)
issue.trackables() += jiraService.neoOperations.findAll(Project::class.java).awaitFirst()
issue.type().value = jiraService.issueType(imsProject)
Expand Down
24 changes: 14 additions & 10 deletions sync/src/main/kotlin/gropius/sync/AbstractSync.kt
Original file line number Diff line number Diff line change
Expand Up @@ -423,16 +423,20 @@ abstract class AbstractSync(
mappedStates: List<IssueState>
) {
val labelStateMap = this.labelStateMap(imsProject)
timelineItems.remove(timelineItem)
val newStateChange = StateChangedEvent(
timelineItem.createdAt, timelineItem.lastModifiedAt
)
newStateChange.oldState().value = lastState
newStateChange.newState().value = mappedStates.firstOrNull() ?: lastState//TODO("Restore State out of nothing")
newStateChange.createdBy().value = timelineItem.createdBy().value
newStateChange.lastModifiedBy().value = timelineItem.lastModifiedBy().value
timelineItems.add(newStateChange)
issue.timelineItems().add(newStateChange)
val mappedState = lookupState(labelStateMap[timelineItem.removedLabel().value?.name])
if ((mappedState != null) && !mappedStates.contains(mappedState)) {
timelineItems.remove(timelineItem)
val newStateChange = StateChangedEvent(
timelineItem.createdAt, timelineItem.lastModifiedAt
)
newStateChange.oldState().value = lastState
newStateChange.newState().value =
mappedStates.firstOrNull() ?: lastState//TODO("Restore State out of nothing")
nk-coding marked this conversation as resolved.
Show resolved Hide resolved
newStateChange.createdBy().value = timelineItem.createdBy().value
newStateChange.lastModifiedBy().value = timelineItem.lastModifiedBy().value
timelineItems.add(newStateChange)
issue.timelineItems().add(newStateChange)
}
}

/**
Expand Down