-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(cli): Attempt at patching the existing event with a new file rea…
…der to support trunk based flows (#63) * Attempt at patching the existing event with a new file reader * Remove labels * Remove unused import * linting
- Loading branch information
Showing
4 changed files
with
70 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
src/commonMain/kotlin/com/monta/slack/notifier/model/GithubTrunkBasedPushContext.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package com.monta.slack.notifier.model | ||
|
||
import kotlinx.serialization.SerialName | ||
import kotlinx.serialization.Serializable | ||
|
||
@Serializable | ||
data class GithubTrunkBasedPushContext( | ||
@SerialName("run_id") | ||
val runId: String? = null, // 4. Fourth var, Name of run (should be ) | ||
) { | ||
// In this class we grab variables from a trunk based event flow | ||
// Where each thing we need to populate the slack message are listed | ||
@Serializable | ||
data class PullRequestHead( | ||
@SerialName("ref") val ref: String, | ||
) | ||
|
||
@Serializable | ||
data class PullRequest( | ||
@SerialName("head") val head: PullRequestHead, | ||
@SerialName("title") val title: String, | ||
@SerialName("user") val user: PullRequestUser, | ||
) | ||
|
||
@Serializable | ||
data class PullRequestUser( | ||
@SerialName("login") val login: String, | ||
) | ||
|
||
@Serializable | ||
data class Repository( | ||
@SerialName("full_name") val fullName: String, | ||
) | ||
|
||
@Serializable | ||
data class Event( | ||
@SerialName("after") val sha: String, | ||
@SerialName("pull_request") val pullRequest: PullRequest, | ||
@SerialName("repository") val repository: Repository, | ||
) | ||
} |
20 changes: 20 additions & 0 deletions
20
src/commonMain/kotlin/com/monta/slack/notifier/util/TrunkUtils.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package com.monta.slack.notifier.util | ||
|
||
import com.monta.slack.notifier.model.GithubPushContext | ||
import com.monta.slack.notifier.model.GithubTrunkBasedPushContext | ||
|
||
/** | ||
* Populates the existing event type with information needed to generate | ||
* an entire Slack notification. This is super hacky but an easy solution | ||
* without deintegrating GithubPushContext from the rest of the code. | ||
*/ | ||
fun populateEventFromTrunkBasedEvent(eventJson: String, event: GithubPushContext.Event): GithubPushContext.Event { | ||
val trunkBasedEvent = JsonUtil.instance.decodeFromString<GithubTrunkBasedPushContext.Event>(eventJson) | ||
event.headCommit = GithubPushContext.Commit( | ||
committer = GithubPushContext.Committer(name = trunkBasedEvent.pullRequest.user.login), | ||
id = trunkBasedEvent.sha, | ||
url = "https://github.com/${trunkBasedEvent.repository.fullName}/compare/${trunkBasedEvent.pullRequest.head.ref}", | ||
message = trunkBasedEvent.pullRequest.title | ||
) | ||
return event | ||
} |