From 5d986b227265a63d4c9e20ef8655b3d46d9b285b Mon Sep 17 00:00:00 2001 From: Christian Kurz Date: Wed, 23 Oct 2024 11:14:57 +0200 Subject: [PATCH] sync timeline items of dead users --- .../kotlin/gropius/sync/github/IssuePile.kt | 191 ++++++++---------- 1 file changed, 83 insertions(+), 108 deletions(-) diff --git a/sync-github/src/main/kotlin/gropius/sync/github/IssuePile.kt b/sync-github/src/main/kotlin/gropius/sync/github/IssuePile.kt index ce5f6655..9bb3a0a0 100644 --- a/sync-github/src/main/kotlin/gropius/sync/github/IssuePile.kt +++ b/sync-github/src/main/kotlin/gropius/sync/github/IssuePile.kt @@ -402,21 +402,17 @@ class RenamedTitleEventTimelineItem( val convInfo = timelineItemConversionInformation ?: TODOTimelineItemConversionInformation(imsProject.rawId!!, githubId); val githubService = service as GithubDataService - if ((createdBy != null)) { - val gropiusId = convInfo.gropiusId - val event = if (gropiusId != null) githubService.neoOperations.findById( - gropiusId - ) else TitleChangedEvent(createdAt, createdAt, oldTitle, newTitle) - if (event == null) { - return listOf() to convInfo; - } - event.createdBy().value = githubService.mapUser(imsProject, createdBy) - event.lastModifiedBy().value = githubService.mapUser(imsProject, createdBy) - return listOf(event) to convInfo; + val gropiusId = convInfo.gropiusId + val event = if (gropiusId != null) githubService.neoOperations.findById( + gropiusId + ) else TitleChangedEvent(createdAt, createdAt, oldTitle, newTitle) + if (event == null) { + return listOf() to convInfo; } - return listOf() to convInfo; + event.createdBy().value = githubService.mapUser(imsProject, createdBy) + event.lastModifiedBy().value = githubService.mapUser(imsProject, createdBy) + return listOf(event) to convInfo; } - } /** @@ -445,20 +441,17 @@ class UnlabeledEventTimelineItem( val convInfo = timelineItemConversionInformation ?: TODOTimelineItemConversionInformation(imsProject.rawId!!, githubId); val githubService = service as GithubDataService - if ((createdBy != null)) { - val gropiusId = convInfo.gropiusId - val event = if (gropiusId != null) githubService.neoOperations.findById( - gropiusId - ) else RemovedLabelEvent(createdAt, createdAt) - if (event == null) { - return listOf() to convInfo; - } - event.createdBy().value = githubService.mapUser(imsProject, createdBy) - event.lastModifiedBy().value = githubService.mapUser(imsProject, createdBy) - event.removedLabel().value = githubService.mapLabel(imsProject, label) - return listOf(event) to convInfo; + val gropiusId = convInfo.gropiusId + val event = if (gropiusId != null) githubService.neoOperations.findById( + gropiusId + ) else RemovedLabelEvent(createdAt, createdAt) + if (event == null) { + return listOf() to convInfo; } - return listOf() to convInfo; + event.createdBy().value = githubService.mapUser(imsProject, createdBy) + event.lastModifiedBy().value = githubService.mapUser(imsProject, createdBy) + event.removedLabel().value = githubService.mapLabel(imsProject, label) + return listOf(event) to convInfo; } } @@ -482,20 +475,17 @@ class LabeledEventTimelineItem( val convInfo = timelineItemConversionInformation ?: TODOTimelineItemConversionInformation(imsProject.rawId!!, githubId); val githubService = service as GithubDataService - if ((createdBy != null)) { - val gropiusId = convInfo.gropiusId - val event = if (gropiusId != null) githubService.neoOperations.findById( - gropiusId - ) else AddedLabelEvent(createdAt, createdAt) - if (event == null) { - return listOf() to convInfo; - } - event.createdBy().value = githubService.mapUser(imsProject, createdBy) - event.lastModifiedBy().value = githubService.mapUser(imsProject, createdBy) - event.addedLabel().value = githubService.mapLabel(imsProject, label) - return listOf(event) to convInfo; + val gropiusId = convInfo.gropiusId + val event = if (gropiusId != null) githubService.neoOperations.findById( + gropiusId + ) else AddedLabelEvent(createdAt, createdAt) + if (event == null) { + return listOf() to convInfo; } - return listOf() to convInfo; + event.createdBy().value = githubService.mapUser(imsProject, createdBy) + event.lastModifiedBy().value = githubService.mapUser(imsProject, createdBy) + event.addedLabel().value = githubService.mapLabel(imsProject, label) + return listOf(event) to convInfo; } /** @@ -534,22 +524,19 @@ class UnassignedTimelineItem( val convInfo = timelineItemConversionInformation ?: TODOTimelineItemConversionInformation(imsProject.rawId!!, githubId); val githubService = service as GithubDataService - if ((createdBy != null)) { - val gropiusId = convInfo.gropiusId - val event = if (gropiusId != null) githubService.neoOperations.findById( - gropiusId - ) else RemovedAssignmentEvent(createdAt, createdAt) - val opposite = issue.timelineItems().filterIsInstance().sortedBy { it.createdAt } - .lastOrNull { it.user().value.username == user } // TODO: Catch multiple - if ((event == null) || (opposite == null)) { - return listOf() to convInfo; - } - event.createdBy().value = githubService.mapUser(imsProject, createdBy) - event.lastModifiedBy().value = githubService.mapUser(imsProject, createdBy) - event.removedAssignment().value = opposite - return listOf(event) to convInfo; + val gropiusId = convInfo.gropiusId + val event = if (gropiusId != null) githubService.neoOperations.findById( + gropiusId + ) else RemovedAssignmentEvent(createdAt, createdAt) + val opposite = issue.timelineItems().filterIsInstance().sortedBy { it.createdAt } + .lastOrNull { it.user().value.username == user } // TODO: Catch multiple + if ((event == null) || (opposite == null)) { + return listOf() to convInfo; } - return listOf() to convInfo; + event.createdBy().value = githubService.mapUser(imsProject, createdBy) + event.lastModifiedBy().value = githubService.mapUser(imsProject, createdBy) + event.removedAssignment().value = opposite + return listOf(event) to convInfo; } } @@ -582,20 +569,17 @@ class AssignedTimelineItem( val convInfo = timelineItemConversionInformation ?: TODOTimelineItemConversionInformation(imsProject.rawId!!, githubId); val githubService = service as GithubDataService - if ((createdBy != null)) { - val gropiusId = convInfo.gropiusId - val event = if (gropiusId != null) githubService.neoOperations.findById( - gropiusId - ) else Assignment(createdAt, createdAt) - if (event == null) { - return listOf() to convInfo; - } - event.createdBy().value = githubService.mapUser(imsProject, createdBy) - event.lastModifiedBy().value = githubService.mapUser(imsProject, createdBy) - event.user().value = githubService.mapUser(imsProject, user) - return listOf(event) to convInfo; + val gropiusId = convInfo.gropiusId + val event = if (gropiusId != null) githubService.neoOperations.findById( + gropiusId + ) else Assignment(createdAt, createdAt) + if (event == null) { + return listOf() to convInfo; } - return listOf() to convInfo; + event.createdBy().value = githubService.mapUser(imsProject, createdBy) + event.lastModifiedBy().value = githubService.mapUser(imsProject, createdBy) + event.user().value = githubService.mapUser(imsProject, user) + return listOf(event) to convInfo; } } @@ -623,21 +607,18 @@ class ReopenedEventTimelineItem(githubId: String, createdAt: OffsetDateTime, val val convInfo = timelineItemConversionInformation ?: TODOTimelineItemConversionInformation(imsProject.rawId!!, githubId); val githubService = service as GithubDataService - if ((createdBy != null)) { - val gropiusId = convInfo.gropiusId - val event = if (gropiusId != null) githubService.neoOperations.findById( - gropiusId - ) else StateChangedEvent(createdAt, createdAt) - if (event == null) { - return listOf() to convInfo; - } - event.createdBy().value = githubService.mapUser(imsProject, createdBy) - event.lastModifiedBy().value = githubService.mapUser(imsProject, createdBy) - event.newState().value = githubService.issueState(imsProject, true) - event.oldState().value = githubService.issueState(imsProject, false) - return listOf(event) to convInfo; + val gropiusId = convInfo.gropiusId + val event = if (gropiusId != null) githubService.neoOperations.findById( + gropiusId + ) else StateChangedEvent(createdAt, createdAt) + if (event == null) { + return listOf() to convInfo; } - return listOf() to convInfo; + event.createdBy().value = githubService.mapUser(imsProject, createdBy) + event.lastModifiedBy().value = githubService.mapUser(imsProject, createdBy) + event.newState().value = githubService.issueState(imsProject, true) + event.oldState().value = githubService.issueState(imsProject, false) + return listOf(event) to convInfo; } } @@ -665,21 +646,18 @@ class ClosedEventTimelineItem(githubId: String, createdAt: OffsetDateTime, val c val convInfo = timelineItemConversionInformation ?: TODOTimelineItemConversionInformation(imsProject.rawId!!, githubId); val githubService = service as GithubDataService - if ((createdBy != null)) { - val gropiusId = convInfo.gropiusId - val event = if (gropiusId != null) githubService.neoOperations.findById( - gropiusId - ) else StateChangedEvent(createdAt, createdAt) - if (event == null) { - return listOf() to convInfo; - } - event.createdBy().value = githubService.mapUser(imsProject, createdBy) - event.lastModifiedBy().value = githubService.mapUser(imsProject, createdBy) - event.newState().value = githubService.issueState(imsProject, false) - event.oldState().value = githubService.issueState(imsProject, true) - return listOf(event) to convInfo; + val gropiusId = convInfo.gropiusId + val event = if (gropiusId != null) githubService.neoOperations.findById( + gropiusId + ) else StateChangedEvent(createdAt, createdAt) + if (event == null) { + return listOf() to convInfo; } - return listOf() to convInfo; + event.createdBy().value = githubService.mapUser(imsProject, createdBy) + event.lastModifiedBy().value = githubService.mapUser(imsProject, createdBy) + event.newState().value = githubService.issueState(imsProject, false) + event.oldState().value = githubService.issueState(imsProject, true) + return listOf(event) to convInfo; } } @@ -717,20 +695,17 @@ class IssueCommentTimelineItem( val convInfo = timelineItemConversionInformation ?: TODOTimelineItemConversionInformation(imsProject.rawId!!, githubId); val githubService = service as GithubDataService - if ((createdBy != null)) { - val gropiusId = convInfo.gropiusId - val event = if (gropiusId != null) githubService.neoOperations.findById( - gropiusId - ) else IssueComment(createdAt, createdAt, body, createdAt, false) - if (event == null) { - return listOf() to convInfo; - } - event.createdBy().value = githubService.mapUser(imsProject, createdBy) - event.lastModifiedBy().value = githubService.mapUser(imsProject, createdBy) - event.bodyLastEditedBy().value = githubService.mapUser(imsProject, createdBy) - return listOf(event) to convInfo; + val gropiusId = convInfo.gropiusId + val event = if (gropiusId != null) githubService.neoOperations.findById( + gropiusId + ) else IssueComment(createdAt, createdAt, body, createdAt, false) + if (event == null) { + return listOf() to convInfo; } - return listOf() to convInfo; + event.createdBy().value = githubService.mapUser(imsProject, createdBy) + event.lastModifiedBy().value = githubService.mapUser(imsProject, createdBy) + event.bodyLastEditedBy().value = githubService.mapUser(imsProject, createdBy) + return listOf(event) to convInfo; } }