Skip to content

Commit

Permalink
fallback comments
Browse files Browse the repository at this point in the history
  • Loading branch information
chriku committed Oct 10, 2024
1 parent dffa657 commit f853997
Show file tree
Hide file tree
Showing 4 changed files with 85 additions and 21 deletions.
23 changes: 16 additions & 7 deletions sync-github/src/main/kotlin/gropius/sync/github/GithubSync.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import gropius.model.architecture.IMSProject
import gropius.model.issue.Issue
import gropius.model.issue.Label
import gropius.model.issue.timeline.IssueComment
import gropius.model.issue.timeline.TemplatedFieldChangedEvent
import gropius.model.issue.timeline.TimelineItem
import gropius.model.template.IMSTemplate
import gropius.model.template.IssueState
import gropius.model.user.User
Expand Down Expand Up @@ -177,6 +177,21 @@ final class GithubSync(
return null
}

override suspend fun syncFallbackComment(
imsProject: IMSProject, issueId: String, comment: String, original: TimelineItem?, users: List<User>
): TimelineItemConversionInformation? {
val response = githubDataService.mutation(
imsProject, users, MutateCreateCommentMutation(issueId, comment), gropiusUserList(users)
).second
val item = response.data?.addComment?.commentEdge?.node?.asIssueTimelineItems()
if (item != null) {
return TODOTimelineItemConversionInformation(imsProject.rawId!!, item.id)
}
logger.error("${response.data} ${response.errors}")
//TODO("ERROR HANDLING")
return null
}

override suspend fun syncAddedLabel(
imsProject: IMSProject, issueId: String, label: Label, users: List<User>
): TimelineItemConversionInformation? {
Expand Down Expand Up @@ -214,12 +229,6 @@ final class GithubSync(
return null
}

override suspend fun syncTemplatedField(
imsProject: IMSProject, issueId: String, fieldChangedEvent: TemplatedFieldChangedEvent, users: List<User>
): TimelineItemConversionInformation? {
TODO("Remove this, as soon as the fallback is done in AbstractSync")
}

override suspend fun syncStateChange(
imsProject: IMSProject, issueId: String, newState: IssueState, users: List<User>
): TimelineItemConversionInformation? {
Expand Down
19 changes: 19 additions & 0 deletions sync-jira/src/main/kotlin/gropius/sync/jira/JiraSync.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import gropius.model.issue.Issue
import gropius.model.issue.Label
import gropius.model.issue.timeline.IssueComment
import gropius.model.issue.timeline.TemplatedFieldChangedEvent
import gropius.model.issue.timeline.TimelineItem
import gropius.model.template.IMSTemplate
import gropius.model.template.IssueState
import gropius.model.user.User
Expand Down Expand Up @@ -328,6 +329,24 @@ final class JiraSync(
return JiraTimelineItemConversionInformation(imsProject.rawId!!, iid)
}

override suspend fun syncFallbackComment(
imsProject: IMSProject, issueId: String, comment: String, original: TimelineItem?, users: List<User>
): TimelineItemConversionInformation? {
val response = jiraDataService.request(
imsProject,
users,
HttpMethod.Post,
gropiusUserList(users),
JsonObject(mapOf("body" to JsonPrimitive(comment)))
) {
appendPathSegments("issue")
appendPathSegments(issueId)
appendPathSegments("comment")
}.second.body<JsonObject>()
val iid = response["id"]!!.jsonPrimitive.content
return JiraTimelineItemConversionInformation(imsProject.rawId!!, iid)
}

override suspend fun syncTitleChange(
imsProject: IMSProject, issueId: String, newTitle: String, users: List<User>
): TimelineItemConversionInformation? {
Expand Down
58 changes: 45 additions & 13 deletions sync/src/main/kotlin/gropius/sync/AbstractSync.kt
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,22 @@ abstract class AbstractSync(
* @param users List of users involved in this timeline item, sorted with most relevant first
* @return Conversion information
*/
abstract suspend fun syncComment(
open suspend fun syncComment(
imsProject: IMSProject, issueId: String, issueComment: IssueComment, users: List<User>
): TimelineItemConversionInformation? {
return syncFallbackComment(imsProject, issueId, issueComment.body, issueComment, users)
}

/**
* Incorporate a fallback comment
* @param imsProject IMS project to sync
* @param issueId GitHub ID of the issue
* @param issueComment Comment to sync
* @param users List of users involved in this timeline item, sorted with most relevant first
* @return Conversion information
*/
abstract suspend fun syncFallbackComment(
imsProject: IMSProject, issueId: String, comment: String, original: TimelineItem?, users: List<User>
): TimelineItemConversionInformation?

/**
Expand All @@ -134,9 +148,11 @@ abstract class AbstractSync(
* @param users List of users involved in this timeline item, sorted with most relevant first
* @return Conversion information
*/
abstract suspend fun syncTitleChange(
open suspend fun syncTitleChange(
imsProject: IMSProject, issueId: String, newTitle: String, users: List<User>
): TimelineItemConversionInformation?
): TimelineItemConversionInformation? {
return syncFallbackComment(imsProject, issueId, "Gropius Title changed to $newTitle", null, users)
}

/**
* Incorporate a state change
Expand All @@ -158,9 +174,17 @@ abstract class AbstractSync(
* @param users List of users involved in this timeline item, sorted with most relevant first
* @return Conversion information
*/
abstract suspend fun syncTemplatedField(
open suspend fun syncTemplatedField(
imsProject: IMSProject, issueId: String, fieldChangedEvent: TemplatedFieldChangedEvent, users: List<User>
): TimelineItemConversionInformation?
): TimelineItemConversionInformation? {
return syncFallbackComment(
imsProject,
issueId,
"Gropius Field ${fieldChangedEvent.fieldName} changed to ${fieldChangedEvent.newValue}",
fieldChangedEvent,
users
)
}

/**
* Incorporate an added label
Expand All @@ -170,9 +194,11 @@ abstract class AbstractSync(
* @param users List of users involved in this timeline item, sorted with most relevant first
* @return Conversion information
*/
abstract suspend fun syncAddedLabel(
open suspend fun syncAddedLabel(
imsProject: IMSProject, issueId: String, label: Label, users: List<User>
): TimelineItemConversionInformation?
): TimelineItemConversionInformation? {
return syncFallbackComment(imsProject, issueId, "Gropius Label ${label.name} added", null, users)
}

/**
* Incorporate a removed label
Expand All @@ -182,9 +208,11 @@ abstract class AbstractSync(
* @param users List of users involved in this timeline item, sorted with most relevant first
* @return Conversion information
*/
abstract suspend fun syncRemovedLabel(
open suspend fun syncRemovedLabel(
imsProject: IMSProject, issueId: String, label: Label, users: List<User>
): TimelineItemConversionInformation?
): TimelineItemConversionInformation? {
return syncFallbackComment(imsProject, issueId, "Gropius Label ${label.name} removed", null, users)
}

/**
* Create an issue on the IMS
Expand Down Expand Up @@ -779,7 +807,8 @@ abstract class AbstractSync(
imsProject, finalBlock, relevantTimeline, true, virtualIDs
)
) {
val conversionInformation = syncRemovedLabel(imsProject,
val conversionInformation = syncRemovedLabel(
imsProject,
issueInfo.githubId,
label!!,
finalBlock.map { it.lastModifiedBy().value })
Expand All @@ -794,7 +823,8 @@ abstract class AbstractSync(
imsProject, finalBlock, relevantTimeline, false, virtualIDs
)
) {
val conversionInformation = syncAddedLabel(imsProject,
val conversionInformation = syncAddedLabel(
imsProject,
issueInfo.githubId,
label!!,
finalBlock.map { it.lastModifiedBy().value })
Expand Down Expand Up @@ -853,7 +883,8 @@ abstract class AbstractSync(
imsProject.rawId!!, it.rawId!!
) != null
}) {
val conversionInformation = syncTitleChange(imsProject,
val conversionInformation = syncTitleChange(
imsProject,
issueInfo.githubId,
finalBlock.first().newTitle,
finalBlock.map { it.createdBy().value })
Expand Down Expand Up @@ -884,7 +915,8 @@ abstract class AbstractSync(
imsProject.rawId!!, it.rawId!!
) != null
}) {
val conversionInformation = syncTemplatedField(imsProject,
val conversionInformation = syncTemplatedField(
imsProject,
issueInfo.githubId,
finalBlock.first(),
finalBlock.map { it.createdBy().value })
Expand Down
6 changes: 5 additions & 1 deletion sync/src/main/kotlin/gropius/sync/TokenManager.kt
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import io.ktor.client.request.*
import io.ktor.client.statement.*
import io.ktor.http.*
import io.ktor.serialization.kotlinx.json.*
import kotlinx.coroutines.delay
import kotlinx.serialization.Serializable
import kotlinx.serialization.json.Json
import org.slf4j.LoggerFactory
Expand Down Expand Up @@ -235,7 +236,10 @@ abstract class TokenManager<ResponseType : BaseResponseType>(
): Pair<IMSUser, T> {
val users = user.map { getPossibleUsersForUser(imsProject.ims().value, it) }.flatten().distinct()
logger.info("Expanding ${user.map { "${it::class.simpleName}:${it.rawId}(${it.username})" }} to ${users.map { "${it::class.simpleName}:${it.rawId}(${it.username})" }}")
return executeUntilWorking(imsProject, users, executor, owner)
return executeUntilWorking(imsProject, users, {
delay(1100)
executor(it)
}, owner)
}

/**
Expand Down

0 comments on commit f853997

Please sign in to comment.