Skip to content
Open
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
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
kotlin.code.style=official
ziro.cli.version=v6.2.2
ziro.cli.version=v6.5.0
5 changes: 5 additions & 0 deletions src/main/graphql/github/fragments/PullRequest.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@ fragment PullRequestFragment on PullRequest {
repository {
name
}
reviews(last: 1) {
nodes {
state
}
}
state
title
url
Expand Down
7 changes: 7 additions & 0 deletions src/main/graphql/github/mutations/MergePullRequest.graphql
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
mutation MergePullRequest($input: MergePullRequestInput!) {
mergePullRequest(input: $input) {
pullRequest {
...PullRequestFragment
}
}
}
18 changes: 18 additions & 0 deletions src/main/graphql/github/queries/GetChecks.graphql
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
query GetChecks($owner: String!, $repo: String!, $gitReference: String!) {
repository(owner: $owner, name: $repo) {
object(expression: $gitReference) {
... on Commit {
checkSuites(first: 5) {
nodes {
checkRuns(first: 10) {
nodes {
name
conclusion
}
}
}
}
}
}
}
}
4 changes: 3 additions & 1 deletion src/main/graphql/github/queries/GetStatuses.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@ query GetStatuses($owner: String!, $repo: String!, $gitReference: String!) {
creator {
login
}
context
description
state
targetUrl
}
}
}
}
}
}
}
45 changes: 45 additions & 0 deletions src/main/kotlin/github/GitHubClient.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import com.apollographql.apollo3.api.Optional
import com.ziro.engineering.github.graphql.sdk.*
import com.ziro.engineering.github.graphql.sdk.fragment.PullRequestFragment
import com.ziro.engineering.github.graphql.sdk.type.CreatePullRequestInput
import com.ziro.engineering.github.graphql.sdk.type.MergePullRequestInput
import com.ziro.engineering.github.graphql.sdk.type.PullRequestMergeMethod
import com.ziro.engineering.github.graphql.sdk.type.PullRequestUpdateState
import com.ziro.engineering.github.graphql.sdk.type.UpdatePullRequestInput
import java.net.URI
Expand Down Expand Up @@ -96,6 +98,28 @@ class GitHubClient : AutoCloseable {
?.contexts ?: emptyList()
}

fun getChecks(
repoOwner: String = DEFAULT_REPOSITORY_OWNER,
repoName: String = DEFAULT_REPOSITORY_NAME,
gitReference: String
): List<GetChecksQuery.Node1> = runBlocking {
val query = GetChecksQuery(repoOwner, repoName, gitReference)

apolloClient
.query(query)
.toFlow()
.single()
.data
?.repository
?.`object`
?.onCommit
?.checkSuites
?.nodes
?.flatMap { checkSuite -> checkSuite?.checkRuns?.nodes.orEmpty() }
?.filterNotNull()
.orEmpty()
}

fun createPullRequest(
repoId: String,
baseBranch: String,
Expand Down Expand Up @@ -195,6 +219,27 @@ class GitHubClient : AutoCloseable {
pullRequestFragment
}

fun mergePullRequest(
id: String,
commitTitle: String?,
expectedHeadOid: String?,
mergeMethod: PullRequestMergeMethod
) = runBlocking {
val input =
MergePullRequestInput(
commitHeadline = Optional.presentIfNotNull(commitTitle),
expectedHeadOid = Optional.presentIfNotNull(expectedHeadOid),
mergeMethod = Optional.present(mergeMethod),
pullRequestId = id)

val mutation = MergePullRequestMutation(input)
val response = apolloClient.mutation(mutation).execute()

if (response.hasErrors()) {
throw RuntimeException(response.errors?.joinToString(separator = "\n") { it.message })
}
}

override fun close() {
apolloClient.closeQuietly()
}
Expand Down