From 4ff8746c45d2aa98a75e50597b7001508f845331 Mon Sep 17 00:00:00 2001 From: Justin Sadakhom Date: Thu, 29 Jan 2026 16:21:42 -0500 Subject: [PATCH 1/7] Add description to git status query --- gradle.properties | 2 +- src/main/graphql/github/queries/GetStatuses.graphql | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/gradle.properties b/gradle.properties index 6dda49b..c455ffe 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,2 +1,2 @@ kotlin.code.style=official -ziro.cli.version=v6.2.2 +ziro.cli.version=v6.5.0 diff --git a/src/main/graphql/github/queries/GetStatuses.graphql b/src/main/graphql/github/queries/GetStatuses.graphql index 7759cd8..19038d8 100644 --- a/src/main/graphql/github/queries/GetStatuses.graphql +++ b/src/main/graphql/github/queries/GetStatuses.graphql @@ -7,6 +7,7 @@ query GetStatuses($owner: String!, $repo: String!, $gitReference: String!) { creator { login } + description state targetUrl } @@ -14,4 +15,4 @@ query GetStatuses($owner: String!, $repo: String!, $gitReference: String!) { } } } -} \ No newline at end of file +} From 572883b20e018f7225c25dacb1404de854df18e7 Mon Sep 17 00:00:00 2001 From: Justin Sadakhom Date: Tue, 10 Feb 2026 11:25:01 -0500 Subject: [PATCH 2/7] Add new required queries --- .../github/fragments/PullRequest.graphql | 5 ++ .../github/mutations/MergePullRequest.graphql | 7 +++ .../graphql/github/queries/GetChecks.graphql | 18 +++++++ .../github/queries/GetStatuses.graphql | 1 + src/main/kotlin/github/GitHubClient.kt | 49 +++++++++++++++++++ 5 files changed, 80 insertions(+) create mode 100644 src/main/graphql/github/mutations/MergePullRequest.graphql create mode 100644 src/main/graphql/github/queries/GetChecks.graphql diff --git a/src/main/graphql/github/fragments/PullRequest.graphql b/src/main/graphql/github/fragments/PullRequest.graphql index da9c5fe..63bfc5d 100644 --- a/src/main/graphql/github/fragments/PullRequest.graphql +++ b/src/main/graphql/github/fragments/PullRequest.graphql @@ -12,6 +12,11 @@ fragment PullRequestFragment on PullRequest { repository { name } + reviews(last: 1) { + nodes { + state + } + } state title url diff --git a/src/main/graphql/github/mutations/MergePullRequest.graphql b/src/main/graphql/github/mutations/MergePullRequest.graphql new file mode 100644 index 0000000..dccfeb5 --- /dev/null +++ b/src/main/graphql/github/mutations/MergePullRequest.graphql @@ -0,0 +1,7 @@ +mutation MergePullRequest($input: MergePullRequestInput!) { + mergePullRequest(input: $input) { + pullRequest { + ...PullRequestFragment + } + } +} diff --git a/src/main/graphql/github/queries/GetChecks.graphql b/src/main/graphql/github/queries/GetChecks.graphql new file mode 100644 index 0000000..5a91eb6 --- /dev/null +++ b/src/main/graphql/github/queries/GetChecks.graphql @@ -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, filterBy: {checkName: "SonarQubeCloud"}) { + nodes { + checkRuns(first: 3, filterBy: {checkName: "SonarCloud Code Analysis"}) { + nodes { + name + conclusion + } + } + } + } + } + } + } +} diff --git a/src/main/graphql/github/queries/GetStatuses.graphql b/src/main/graphql/github/queries/GetStatuses.graphql index 19038d8..94c82da 100644 --- a/src/main/graphql/github/queries/GetStatuses.graphql +++ b/src/main/graphql/github/queries/GetStatuses.graphql @@ -7,6 +7,7 @@ query GetStatuses($owner: String!, $repo: String!, $gitReference: String!) { creator { login } + context description state targetUrl diff --git a/src/main/kotlin/github/GitHubClient.kt b/src/main/kotlin/github/GitHubClient.kt index be69739..056a84e 100644 --- a/src/main/kotlin/github/GitHubClient.kt +++ b/src/main/kotlin/github/GitHubClient.kt @@ -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 @@ -96,6 +98,30 @@ class GitHubClient : AutoCloseable { ?.contexts ?: emptyList() } + fun getChecks( + repoOwner: String = DEFAULT_REPOSITORY_OWNER, + repoName: String = DEFAULT_REPOSITORY_NAME, + gitReference: String + ): List = runBlocking { + val query = GetChecksQuery(repoOwner, repoName, gitReference) + + apolloClient + .query(query) + .toFlow() + .single() + .data + ?.repository + ?.`object` + ?.onCommit + ?.checkSuites + ?.nodes + ?.first() + ?.checkRuns + ?.nodes + ?.filterNotNull() + .orEmpty() + } + fun createPullRequest( repoId: String, baseBranch: String, @@ -195,6 +221,29 @@ 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 } + ?: "Unknown GraphQL error") + } + } + override fun close() { apolloClient.closeQuietly() } From b6a7bdd878b589d456fb7c35f9e91af47321852f Mon Sep 17 00:00:00 2001 From: Justin Sadakhom Date: Wed, 11 Feb 2026 11:28:52 -0500 Subject: [PATCH 3/7] Add new mutation --- .../mutations/AddPullRequestReview.graphql | 5 +++++ src/main/kotlin/github/GitHubClient.kt | 19 ++++++++++++++++--- 2 files changed, 21 insertions(+), 3 deletions(-) create mode 100644 src/main/graphql/github/mutations/AddPullRequestReview.graphql diff --git a/src/main/graphql/github/mutations/AddPullRequestReview.graphql b/src/main/graphql/github/mutations/AddPullRequestReview.graphql new file mode 100644 index 0000000..a6c116d --- /dev/null +++ b/src/main/graphql/github/mutations/AddPullRequestReview.graphql @@ -0,0 +1,5 @@ +mutation AddPullRequestReview($input: AddPullRequestReviewInput!) { + addPullRequestReview(input: $input) { + clientMutationId + } +} diff --git a/src/main/kotlin/github/GitHubClient.kt b/src/main/kotlin/github/GitHubClient.kt index 056a84e..c927ea2 100644 --- a/src/main/kotlin/github/GitHubClient.kt +++ b/src/main/kotlin/github/GitHubClient.kt @@ -4,9 +4,11 @@ import com.apollographql.apollo3.ApolloClient 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.AddPullRequestReviewInput 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.PullRequestReviewEvent import com.ziro.engineering.github.graphql.sdk.type.PullRequestUpdateState import com.ziro.engineering.github.graphql.sdk.type.UpdatePullRequestInput import java.net.URI @@ -238,9 +240,20 @@ class GitHubClient : AutoCloseable { val response = apolloClient.mutation(mutation).execute() if (response.hasErrors()) { - throw RuntimeException( - response.errors?.joinToString(separator = "\n") { it.message } - ?: "Unknown GraphQL error") + throw RuntimeException(response.errors?.joinToString(separator = "\n") { it.message }) + } + } + + fun addPullRequestReview(pullRequestId: String, event: PullRequestReviewEvent?) = runBlocking { + val input = + AddPullRequestReviewInput( + pullRequestId = pullRequestId, event = Optional.presentIfNotNull(event)) + + val mutation = AddPullRequestReviewMutation(input) + val response = apolloClient.mutation(mutation).execute() + + if (response.hasErrors()) { + throw RuntimeException(response.errors?.joinToString(separator = "\n") { it.message }) } } From d26a9b8e8b91a8948bea197e4d7a3f15844d3b5b Mon Sep 17 00:00:00 2001 From: Justin Sadakhom Date: Wed, 11 Feb 2026 14:08:08 -0500 Subject: [PATCH 4/7] Undo addition of new mutation --- .../github/mutations/AddPullRequestReview.graphql | 5 ----- src/main/kotlin/github/GitHubClient.kt | 15 --------------- 2 files changed, 20 deletions(-) delete mode 100644 src/main/graphql/github/mutations/AddPullRequestReview.graphql diff --git a/src/main/graphql/github/mutations/AddPullRequestReview.graphql b/src/main/graphql/github/mutations/AddPullRequestReview.graphql deleted file mode 100644 index a6c116d..0000000 --- a/src/main/graphql/github/mutations/AddPullRequestReview.graphql +++ /dev/null @@ -1,5 +0,0 @@ -mutation AddPullRequestReview($input: AddPullRequestReviewInput!) { - addPullRequestReview(input: $input) { - clientMutationId - } -} diff --git a/src/main/kotlin/github/GitHubClient.kt b/src/main/kotlin/github/GitHubClient.kt index c927ea2..081283d 100644 --- a/src/main/kotlin/github/GitHubClient.kt +++ b/src/main/kotlin/github/GitHubClient.kt @@ -4,11 +4,9 @@ import com.apollographql.apollo3.ApolloClient 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.AddPullRequestReviewInput 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.PullRequestReviewEvent import com.ziro.engineering.github.graphql.sdk.type.PullRequestUpdateState import com.ziro.engineering.github.graphql.sdk.type.UpdatePullRequestInput import java.net.URI @@ -244,19 +242,6 @@ class GitHubClient : AutoCloseable { } } - fun addPullRequestReview(pullRequestId: String, event: PullRequestReviewEvent?) = runBlocking { - val input = - AddPullRequestReviewInput( - pullRequestId = pullRequestId, event = Optional.presentIfNotNull(event)) - - val mutation = AddPullRequestReviewMutation(input) - val response = apolloClient.mutation(mutation).execute() - - if (response.hasErrors()) { - throw RuntimeException(response.errors?.joinToString(separator = "\n") { it.message }) - } - } - override fun close() { apolloClient.closeQuietly() } From d4e77db3f64f83352e362b502447a8997dd7f5b2 Mon Sep 17 00:00:00 2001 From: Justin Sadakhom Date: Wed, 11 Feb 2026 14:15:10 -0500 Subject: [PATCH 5/7] Remove hardcoding in GetChecks query --- src/main/graphql/github/queries/GetChecks.graphql | 6 +++--- src/main/kotlin/github/GitHubClient.kt | 6 ++++-- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/main/graphql/github/queries/GetChecks.graphql b/src/main/graphql/github/queries/GetChecks.graphql index 5a91eb6..c1a33f0 100644 --- a/src/main/graphql/github/queries/GetChecks.graphql +++ b/src/main/graphql/github/queries/GetChecks.graphql @@ -1,10 +1,10 @@ -query GetChecks($owner: String!, $repo: String!, $gitReference: String!) { +query GetChecks($owner: String!, $repo: String!, $gitReference: String!, $checkSuiteName: String!, $checkRunName: String!) { repository(owner: $owner, name: $repo) { object(expression: $gitReference) { ... on Commit { - checkSuites(first: 5, filterBy: {checkName: "SonarQubeCloud"}) { + checkSuites(first: 5, filterBy: {checkName: $checkSuiteName}) { nodes { - checkRuns(first: 3, filterBy: {checkName: "SonarCloud Code Analysis"}) { + checkRuns(first: 3, filterBy: {checkName: $checkRunName}) { nodes { name conclusion diff --git a/src/main/kotlin/github/GitHubClient.kt b/src/main/kotlin/github/GitHubClient.kt index 081283d..7c46924 100644 --- a/src/main/kotlin/github/GitHubClient.kt +++ b/src/main/kotlin/github/GitHubClient.kt @@ -101,9 +101,11 @@ class GitHubClient : AutoCloseable { fun getChecks( repoOwner: String = DEFAULT_REPOSITORY_OWNER, repoName: String = DEFAULT_REPOSITORY_NAME, - gitReference: String + gitReference: String, + checkSuiteName: String, + checkRunName: String ): List = runBlocking { - val query = GetChecksQuery(repoOwner, repoName, gitReference) + val query = GetChecksQuery(repoOwner, repoName, gitReference, checkSuiteName, checkRunName) apolloClient .query(query) From dad075d101280a62056a4232997a01516c37f823 Mon Sep 17 00:00:00 2001 From: Justin Sadakhom Date: Wed, 11 Feb 2026 14:18:31 -0500 Subject: [PATCH 6/7] Fix query again --- src/main/graphql/github/queries/GetChecks.graphql | 6 +++--- src/main/kotlin/github/GitHubClient.kt | 6 ++---- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/src/main/graphql/github/queries/GetChecks.graphql b/src/main/graphql/github/queries/GetChecks.graphql index c1a33f0..02bb9ec 100644 --- a/src/main/graphql/github/queries/GetChecks.graphql +++ b/src/main/graphql/github/queries/GetChecks.graphql @@ -1,10 +1,10 @@ -query GetChecks($owner: String!, $repo: String!, $gitReference: String!, $checkSuiteName: String!, $checkRunName: String!) { +query GetChecks($owner: String!, $repo: String!, $gitReference: String!) { repository(owner: $owner, name: $repo) { object(expression: $gitReference) { ... on Commit { - checkSuites(first: 5, filterBy: {checkName: $checkSuiteName}) { + checkSuites(first: 5) { nodes { - checkRuns(first: 3, filterBy: {checkName: $checkRunName}) { + checkRuns(first: 10) { nodes { name conclusion diff --git a/src/main/kotlin/github/GitHubClient.kt b/src/main/kotlin/github/GitHubClient.kt index 7c46924..081283d 100644 --- a/src/main/kotlin/github/GitHubClient.kt +++ b/src/main/kotlin/github/GitHubClient.kt @@ -101,11 +101,9 @@ class GitHubClient : AutoCloseable { fun getChecks( repoOwner: String = DEFAULT_REPOSITORY_OWNER, repoName: String = DEFAULT_REPOSITORY_NAME, - gitReference: String, - checkSuiteName: String, - checkRunName: String + gitReference: String ): List = runBlocking { - val query = GetChecksQuery(repoOwner, repoName, gitReference, checkSuiteName, checkRunName) + val query = GetChecksQuery(repoOwner, repoName, gitReference) apolloClient .query(query) From adb78eca7ea99780b90666d922586cf3b8df19e0 Mon Sep 17 00:00:00 2001 From: Justin Sadakhom Date: Wed, 11 Feb 2026 14:27:30 -0500 Subject: [PATCH 7/7] Fix filtering --- src/main/kotlin/github/GitHubClient.kt | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/main/kotlin/github/GitHubClient.kt b/src/main/kotlin/github/GitHubClient.kt index 081283d..157a813 100644 --- a/src/main/kotlin/github/GitHubClient.kt +++ b/src/main/kotlin/github/GitHubClient.kt @@ -115,9 +115,7 @@ class GitHubClient : AutoCloseable { ?.onCommit ?.checkSuites ?.nodes - ?.first() - ?.checkRuns - ?.nodes + ?.flatMap { checkSuite -> checkSuite?.checkRuns?.nodes.orEmpty() } ?.filterNotNull() .orEmpty() }