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

outgoing templated fields #144

Closed
wants to merge 1 commit into from
Closed
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
11 changes: 11 additions & 0 deletions sync-github/src/main/kotlin/gropius/sync/github/GithubSync.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +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.template.IMSTemplate
import gropius.model.template.IssueState
import gropius.model.user.User
Expand Down Expand Up @@ -80,6 +81,10 @@ final class GithubSync(
return imsProjectConfig.enableOutgoingComments
}

override suspend fun isOutgoingTemplatedFieldsEnabled(imsProject: IMSProject): Boolean {
return false
}

override suspend fun isOutgoingTitleChangedEnabled(imsProject: IMSProject): Boolean {
val imsProjectConfig = IMSProjectConfig(helper, imsProject)
return imsProjectConfig.enableOutgoingTitleChanges
Expand Down Expand Up @@ -209,6 +214,12 @@ 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
33 changes: 33 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 @@ -4,6 +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.template.IMSTemplate
import gropius.model.template.IssueState
import gropius.model.user.User
Expand Down Expand Up @@ -126,6 +127,11 @@ final class JiraSync(
return imsProjectConfig.enableOutgoingState
}

override suspend fun isOutgoingTemplatedFieldsEnabled(imsProject: IMSProject): Boolean {
val imsProjectConfig = IMSProjectConfig(helper, imsProject)
return imsProjectConfig.enableOutgoingTemplatedFields
}

override suspend fun fetchData(imsProjects: List<IMSProject>) {
for (imsProject in imsProjects) {
jiraDataService.issueTemplate(imsProject)
Expand Down Expand Up @@ -348,6 +354,33 @@ final class JiraSync(
)
}

override suspend fun syncTemplatedField(
imsProject: IMSProject, issueId: String, fieldChangedEvent: TemplatedFieldChangedEvent, users: List<User>
): TimelineItemConversionInformation? {
val response = jiraDataService.request(
imsProject, users, HttpMethod.Put, gropiusUserList(users), JsonObject(
mapOf(
"fields" to JsonObject(
mapOf(
fieldChangedEvent.fieldName to JsonPrimitive(fieldChangedEvent.newValue)
)
)
)
)
) {
appendPathSegments("issue")
appendPathSegments(issueId)
parameters.append("returnIssue", "true")
parameters.append("expand", "names,schema,editmeta,changelog")

}
val changelogEntry = response.second.body<IssueBean>().changelog.histories.lastOrNull()
return JiraTimelineItemConversionInformation(
imsProject.rawId!!,
if (changelogEntry?.items?.singleOrNull()?.field == fieldChangedEvent.fieldName) changelogEntry.id else ""
)
}

override suspend fun syncStateChange(
imsProject: IMSProject, issueId: String, newState: IssueState, users: List<User>
): TimelineItemConversionInformation? {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ data class IMSProjectConfig(
val enableOutgoingAssignments: Boolean,
val enableOutgoingTitleChanges: Boolean,
val enableOutgoingState: Boolean,
val enableOutgoingTemplatedFields: Boolean,
val defaultType: String?,
val defaultTemplate: String?
) {
Expand All @@ -40,6 +41,7 @@ data class IMSProjectConfig(
enableOutgoingAssignments = helper.parseBoolean(imsProject.templatedFields["enable-outgoing-assignments"]),
enableOutgoingTitleChanges = helper.parseBoolean(imsProject.templatedFields["enable-outgoing-title-changes"]),
enableOutgoingState = helper.parseBoolean(imsProject.templatedFields["enable-outgoing-state"]),
enableOutgoingTemplatedFields = helper.parseBoolean(imsProject.templatedFields["enable-outgoing-templated-fields"]),
defaultType = helper.parseString(imsProject.templatedFields["default-type"]),
defaultTemplate = helper.parseString(imsProject.templatedFields["default-template"])
)
Expand Down Expand Up @@ -85,6 +87,9 @@ data class IMSProjectConfig(
}.toString(), "enable-outgoing-state" to obj {
"nullable" to true
"type" to "boolean"
}.toString(), "enable-outgoing-templated-fields" to obj {
"nullable" to true
"type" to "boolean"
}.toString()) + IMSConfigManager.COMMON_TEMPLATE_FIELDS
}
}
53 changes: 53 additions & 0 deletions sync/src/main/kotlin/gropius/sync/AbstractSync.kt
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,18 @@ abstract class AbstractSync(
imsProject: IMSProject, issueId: String, newState: IssueState, users: List<User>
): TimelineItemConversionInformation?

/**
* Incorporate a templated field change
* @param imsProject IMS project to sync
* @param issueId GitHub ID of the issue
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why is there a GitHub id in the AbstractSync?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

* @param fieldChangedEvent Event describing the field change
* @param users List of users involved in this timeline item, sorted with most relevant first
* @return Conversion information
*/
abstract suspend fun syncTemplatedField(
imsProject: IMSProject, issueId: String, fieldChangedEvent: TemplatedFieldChangedEvent, users: List<User>
): TimelineItemConversionInformation?

/**
* Incorporate an added label
* @param imsProject IMS project to sync
Expand Down Expand Up @@ -196,6 +208,13 @@ abstract class AbstractSync(
*/
abstract suspend fun isOutgoingLabelsEnabled(imsProject: IMSProject): Boolean

/**
* Check if Outgoing Sync of TemplatedFields is Enabled
* @param imsProject IMS project to check for
* @return true if and only if outgoing sync of templatedFields is enabled
*/
abstract suspend fun isOutgoingTemplatedFieldsEnabled(imsProject: IMSProject): Boolean

/**
* Check if Outgoing Sync of Comments is Enabled
* @param imsProject IMS project to check for
Expand Down Expand Up @@ -660,6 +679,9 @@ abstract class AbstractSync(
if (isOutgoingAssignmentsEnabled(imsProject)) {
syncOutgoingAssignments(timeline, imsProject, issueInfo)
}
if (isOutgoingTemplatedFieldsEnabled(imsProject)) {
syncOutgoingTemplatedFields(timeline, imsProject, issueInfo)
}
if (isOutgoingStatesEnabled(imsProject)) {
syncOutgoingStateChanges(timeline, imsProject, issueInfo)
}
Expand Down Expand Up @@ -844,6 +866,37 @@ abstract class AbstractSync(
}
}

/**
* Sync Outgoing TemplatedFields Changes
* @param timeline Timeline of the issue
* @param imsProject IMS project to sync
* @param issueInfo Issue to sync
*/
private suspend fun syncOutgoingTemplatedFields(
timeline: List<TimelineItem>, imsProject: IMSProject, issueInfo: IssueConversionInformation
) {
val virtualIDs = mapOf<TimelineItem, String>()//For future features
val relevantTimeline = timeline.mapNotNull { it as? TemplatedFieldChangedEvent }
if (relevantTimeline.isEmpty()) return
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

brackets pls

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

val finalBlock = findFinalBlock(relevantTimeline) { it.fieldName to it.newValue }
if (finalBlock.none {
collectedSyncInfo.timelineItemConversionInformationService.findByImsProjectAndGropiusId(
imsProject.rawId!!, it.rawId!!
) != null
}) {
val conversionInformation = syncTemplatedField(imsProject,
issueInfo.githubId,
finalBlock.first(),
finalBlock.map { it.createdBy().value })
if (conversionInformation != null) {
conversionInformation.gropiusId = finalBlock.map { it.rawId ?: virtualIDs[it]!! }.first()
collectedSyncInfo.timelineItemConversionInformationService.save(
conversionInformation
).awaitSingle()
}
}
}

/**
* Sync Outgoing State Changes
* @param timeline Timeline of the issue
Expand Down