Skip to content

Commit

Permalink
up schema version on riscs on version 3.2 (#141)
Browse files Browse the repository at this point in the history
  • Loading branch information
joakimsjo authored Jul 4, 2024
1 parent 244bade commit 3dfe694
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/main/kotlin/no/risc/risc/RiScService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ class RiScService(
}
fetchRisc(owner, repository, id.id, accessTokens.githubAccessToken.value)
.responseToRiScResult(id.id, id.status, accessTokens.gcpAccessToken, id.pullRequestUrl)
.let { migrateToNewMinor(it) }
} catch (e: Exception) {
RiScContentResultDTO(
riScId = id.id,
Expand All @@ -162,6 +163,17 @@ class RiScService(
logger.info("Fetching ${msId.value.count()} RiScs took ${msRiSc.duration}")
msRiSc.value}

// Update RiSc scenarios from schemaVersion 3.2 to 3.3. This is necessary because 3.3 is backwards compatible,
// and modifications can only be made when the schemaVersion is 3.3.
private fun migrateToNewMinor(obj: RiScContentResultDTO): RiScContentResultDTO {
if (obj.riScContent == null) {
return obj
}

val migratedSchemaVersion = obj.riScContent.replace("\"schemaVersion\": \"3.2\"","\"schemaVersion\": \"3.3\"")
return obj.copy(riScContent = migratedSchemaVersion)
}

private fun GithubContentResponse.responseToRiScResult(
riScId: String,
riScStatus: RiScStatus,
Expand Down

0 comments on commit 3dfe694

Please sign in to comment.