Skip to content

Commit

Permalink
octopus-vcs-facade-17 Simplified GiteaService.getCommit(vcsPath, toId)
Browse files Browse the repository at this point in the history
  • Loading branch information
aryabokon committed Sep 22, 2023
1 parent cdf320c commit 420a818
Showing 1 changed file with 2 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import org.octopusden.octopus.infrastructure.gitea.client.createPullRequestWithD
import org.octopusden.octopus.infrastructure.gitea.client.dto.GiteaCommit
import org.octopusden.octopus.infrastructure.gitea.client.dto.GiteaPullRequest
import org.octopusden.octopus.infrastructure.gitea.client.dto.GiteaTag
import org.octopusden.octopus.infrastructure.gitea.client.getBranches
import org.octopusden.octopus.infrastructure.gitea.client.getCommits
import org.octopusden.octopus.infrastructure.gitea.client.getTags
import org.octopusden.octopus.vcsfacade.client.common.dto.Commit
Expand Down Expand Up @@ -53,7 +52,7 @@ class GiteaService(giteaProperties: VCSConfig.GiteaProperties) : VCSClient(gitea
override fun getCommits(vcsPath: String, fromId: String?, fromDate: Date?, toId: String): Collection<Commit> {
validateParams(fromId, fromDate)
val (organization, repository) = vcsPath.toOrganizationAndRepository()
val toCommit = execute("") { getCommit(vcsPath, toId) }
val toCommit = getCommit(vcsPath, toId)

val giteaCommits = execute("getCommits($vcsPath, $fromId, $fromDate, $toCommit)") {
client.getCommits(organization, repository, null, toCommit.id)
Expand All @@ -75,13 +74,8 @@ class GiteaService(giteaProperties: VCSConfig.GiteaProperties) : VCSClient(gitea

override fun getCommit(vcsPath: String, commitId: String): Commit {
val (organization, repository) = vcsPath.toOrganizationAndRepository()

return execute("getCommit($vcsPath, $commitId)") {
client.getCommit(
organization,
repository,
getBranchLatestCommit(organization, repository, commitId) ?: commitId
).toCommit(vcsPath)
client.getCommit(organization, repository, commitId).toCommit(vcsPath)
}
}

Expand All @@ -106,12 +100,6 @@ class GiteaService(giteaProperties: VCSConfig.GiteaProperties) : VCSClient(gitea
it[0] to it[1]
}

private fun getBranchLatestCommit(organization: String, repository: String, branchName: String): String? {
val shortBranchName = branchName.replace("^refs/heads/".toRegex(), "")
return client.getBranches(organization, repository)
.firstOrNull { b -> b.name == shortBranchName }?.commit?.id
}

private fun GiteaCommit.toCommit(vcsPath: String) =
Commit(sha, commit.message, commit.author.date, commit.author.name, parents.map { it.sha }, vcsPath)

Expand Down

0 comments on commit 420a818

Please sign in to comment.