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

Sync logic assignment removes #130

Merged
merged 2 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
17 changes: 14 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 @@ -138,11 +139,21 @@ class JiraDataService(
* @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 {
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 isOpen whether the issue state is open or closed
* @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
59 changes: 52 additions & 7 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 @@ -198,7 +202,8 @@ class JiraTimelineItem(val id: String, val created: String, val author: JsonObje
timelineItemConversionInformation: TimelineItemConversionInformation?,
imsProject: IMSProject,
service: JiraDataService,
jiraService: JiraDataService
jiraService: JiraDataService,
issue: Issue
): Pair<List<TimelineItem>, TimelineItemConversionInformation> {
val convInfo =
timelineItemConversionInformation ?: JiraTimelineItemConversionInformation(imsProject.rawId!!, id);
Expand All @@ -209,19 +214,59 @@ 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)
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
* @return the pair of timeline items and conversion information
*/
private suspend fun gropiusNamedState(
timelineItemConversionInformation: TimelineItemConversionInformation?,
imsProject: IMSProject,
service: JiraDataService,
jiraService: JiraDataService,
issue: Issue
): 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(
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;
}

/**
* Convert a single title change to a Gropius TitleChangedEvent
* @param timelineItemConversionInformation the timeline item conversion information
Expand Down Expand Up @@ -394,7 +439,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