Skip to content

Commit

Permalink
Remove previousSha from GitHub PR events (#281)
Browse files Browse the repository at this point in the history
* Remove previousSha from GitHUb PR events

* Fix tests
  • Loading branch information
rbro112 authored Oct 17, 2024
1 parent 4bc121b commit b268f1a
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ class NoVcsEmergePluginTest : EmergePluginTest() {

assertEquals("github_head_sha", configuration.vcsOptions!!.sha)
assertEquals("github_base_sha", configuration.vcsOptions!!.baseSha)
assertEquals("github_previous_sha", configuration.vcsOptions!!.previousSha)
assertEquals(null, configuration.vcsOptions!!.previousSha)
assertEquals("123", configuration.vcsOptions!!.prNumber)
}

Expand Down Expand Up @@ -131,27 +131,4 @@ class NoVcsEmergePluginTest : EmergePluginTest() {
// BaseSha not set by default
assertNull(configuration.vcsOptions!!.baseSha)
}

@Test
fun `Assert previousSha and baseSha are the same on first commit to PR`() {
val runner = EmergeGradleRunner.create("no-vcs-params")
val configurationJson = File(runner.tempProjectDir, "emerge_config.json")

runner
.withArguments("saveExtensionConfig", "--outputPath", configurationJson.path)
.withDebugTasks()
.withGitHubPREventNoBefore()
.assert { result, _ ->
result.assertSuccessfulTask(":saveExtensionConfig")
}
.build()

val configuration = Json.decodeFromStream<EmergePluginExtensionData>(
configurationJson.inputStream()
)

assertEquals("github_head_sha", configuration.vcsOptions!!.sha)
assertEquals("github_base_sha", configuration.vcsOptions!!.baseSha)
assertEquals("github_base_sha", configuration.vcsOptions!!.previousSha)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,8 @@ internal class GitHub(private val execOperations: ExecOperations) {
fun previousSha(): String? {
return when {
isPush() -> getPushEventData().before
// In the case of the first commit on a PR, the before sha is not available.
// We want previousSha to be the last commit on main, so we'll fallback to baseSha
isPullRequest() -> getPullRequestEventData().before ?: baseSha()
// In the case of branches, `before` can't be relied on from GitHub event data, so we'll skip
// previousSha for now on `pull_request` events
else -> null
}
}
Expand Down Expand Up @@ -112,7 +111,6 @@ internal class GitHub(private val execOperations: ExecOperations) {
@SerialName("pull_request")
val pr: GitHubPullRequest,
val number: Int,
val before: String? = null,
)

@Serializable
Expand Down

0 comments on commit b268f1a

Please sign in to comment.