diff --git a/README.md b/README.md index a3e2ac5..ee6ab0c 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,7 @@ This library provides a convenient interface for interacting with GitHub and Zen # Build ```bash -./gradlew clean build +./gradlew build ``` # Versioning diff --git a/build.gradle.kts b/build.gradle.kts index 634e801..a8103bc 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -1,4 +1,4 @@ -var currentVersion = "4.2.0" +var currentVersion = "5.0.0" if (project.hasProperty("snapshot")) { currentVersion = "${currentVersion}-SNAPSHOT" diff --git a/src/main/graphql/zenhub/CreateIssuePrConnection.graphql b/src/main/graphql/zenhub/CreateIssuePrConnection.graphql new file mode 100644 index 0000000..2f8c896 --- /dev/null +++ b/src/main/graphql/zenhub/CreateIssuePrConnection.graphql @@ -0,0 +1,5 @@ +mutation CreateIssuePrConnection($input: CreateIssuePrConnectionInput!) { + createIssuePrConnection(input: $input) { + clientMutationId + } +} diff --git a/src/main/graphql/zenhub/DeleteIssuePrConnection.graphql b/src/main/graphql/zenhub/DeleteIssuePrConnection.graphql new file mode 100644 index 0000000..b05759b --- /dev/null +++ b/src/main/graphql/zenhub/DeleteIssuePrConnection.graphql @@ -0,0 +1,5 @@ +mutation DeleteIssuePrConnection($input: DeleteIssuePrConnectionInput!) { + deleteIssuePrConnection(input: $input) { + clientMutationId + } +} diff --git a/src/main/graphql/zenhub/fragments/IssueFragment.graphql b/src/main/graphql/zenhub/fragments/IssueFragment.graphql index 091cacf..0951104 100644 --- a/src/main/graphql/zenhub/fragments/IssueFragment.graphql +++ b/src/main/graphql/zenhub/fragments/IssueFragment.graphql @@ -38,6 +38,7 @@ fragment IssueFragment on Issue { # No need to get all pages as issues don't realistically have >100 connectedPrs(first: 5) { nodes { + id number state htmlUrl diff --git a/src/main/kotlin/zenhub/Pipeline.kt b/src/main/kotlin/zenhub/Pipeline.kt deleted file mode 100644 index bc54973..0000000 --- a/src/main/kotlin/zenhub/Pipeline.kt +++ /dev/null @@ -1,15 +0,0 @@ -package zenhub - -enum class Pipeline(val id: String) { - IDEA_BOX("Z2lkOi8vcmFwdG9yL1BpcGVsaW5lLzEwMTEzNjc"), - NEW_REQUEST("Z2lkOi8vcmFwdG9yL1BpcGVsaW5lLzEwMTEyODY"), - EPICS("Z2lkOi8vcmFwdG9yL1BpcGVsaW5lLzEwMTE0NTM"), - WORKSHOP_BACKLOG("Z2lkOi8vcmFwdG9yL1BpcGVsaW5lLzEwMTE1MzE"), - WORKSHOP_IN_PROGRESS("Z2lkOi8vcmFwdG9yL1BpcGVsaW5lLzEwMTE2MDg"), - ESTIMATE_READY("Z2lkOi8vcmFwdG9yL1BpcGVsaW5lLzEwMTE2OTI"), - DEV_BACKLOG("Z2lkOi8vcmFwdG9yL1BpcGVsaW5lLzEwMTE3NzI"), - DEV_IN_PROGRESS("Z2lkOi8vcmFwdG9yL1BpcGVsaW5lLzEwMTE4NDc"), - REVIEW("Z2lkOi8vcmFwdG9yL1BpcGVsaW5lLzIyOTUyNzk"), - MERGE_READY("Z2lkOi8vcmFwdG9yL1BpcGVsaW5lLzEwMTIwODA"), - UAT_READY("Z2lkOi8vcmFwdG9yL1BpcGVsaW5lLzEwMTIxNzI") -} diff --git a/src/main/kotlin/zenhub/ZenHubClient.kt b/src/main/kotlin/zenhub/ZenHubClient.kt index a20530f..76d8b68 100644 --- a/src/main/kotlin/zenhub/ZenHubClient.kt +++ b/src/main/kotlin/zenhub/ZenHubClient.kt @@ -20,11 +20,7 @@ private const val ZENHUB_GRAPHQL_URL = "https://api.zenhub.com/public/graphql" private const val DEFAULT_PAGE_SIZE = 100 -class ZenHubClient( - private val githubRepositoryId: Int = DEFAULT_GITHUB_REPOSITORY_ID, - private val gitRepositoryId: String = DEFAULT_GIT_REPOSITORY_ID, - private val zenhubWorkspaceId: String = DEFAULT_WORKSPACE_ID -) : AutoCloseable { +class ZenHubClient(private val zenhubWorkspaceId: String = DEFAULT_WORKSPACE_ID) : AutoCloseable { private val apolloClient: ApolloClient = ApolloClient.Builder() @@ -113,14 +109,14 @@ class ZenHubClient( apolloClient.mutation(mutation).toFlow().single().data?.removeIssuesFromSprints } - fun getIssuesByPipeline(pipeline: Pipeline): List = runBlocking { + fun getIssuesByPipeline(pipelineId: String): List = runBlocking { val issues: ArrayList = ArrayList() var hasNextPage: Boolean var endCursor: String? = null do { val issuesQuery = - GetIssuesByPipelineQuery(pipeline.id, Optional.presentIfNotNull(endCursor)) + GetIssuesByPipelineQuery(pipelineId, Optional.presentIfNotNull(endCursor)) val issuesInPage = apolloClient.query(issuesQuery).toFlow().single().data?.searchIssuesByPipeline @@ -233,17 +229,18 @@ class ZenHubClient( } /** Cannot move an issue to closed because closed is not a pipeline. */ - fun moveIssueToPipeline(issueId: String, pipeline: Pipeline): MoveIssueMutation.MoveIssue? = + fun moveIssueToPipeline(issueId: String, pipelineId: String): MoveIssueMutation.MoveIssue? = runBlocking { - val input = MoveIssueInput(Optional.absent(), pipeline.id, issueId, Optional.present(0)) + val input = MoveIssueInput(Optional.absent(), pipelineId, issueId, Optional.present(0)) val mutation = MoveIssueMutation(input, DEFAULT_WORKSPACE_ID) apolloClient.mutation(mutation).toFlow().single().data?.moveIssue } - fun setEstimate(issueId: String, value: Double?): SetEstimateMutation.SetEstimate? = + fun setEstimate(issueId: String, value: Integer?): SetEstimateMutation.SetEstimate? = runBlocking { val input = - SetEstimateInput(Optional.absent(), Optional.presentIfNotNull(value), issueId) + SetEstimateInput( + Optional.absent(), Optional.presentIfNotNull(value?.toDouble()), issueId) val mutation = SetEstimateMutation(input) apolloClient.mutation(mutation).toFlow().single().data?.setEstimate } @@ -490,6 +487,18 @@ class ZenHubClient( issues } + fun createIssuePrConnection(issueId: String, pullRequestID: String) = runBlocking { + val input = CreateIssuePrConnectionInput(Optional.absent(), issueId, pullRequestID) + val mutation = CreateIssuePrConnectionMutation(input) + apolloClient.mutation(mutation).execute() + } + + fun deleteIssuePrConnection(issueId: String, pullRequestID: String) = runBlocking { + val input = DeleteIssuePrConnectionInput(Optional.absent(), issueId, pullRequestID) + val mutation = DeleteIssuePrConnectionMutation(input) + apolloClient.mutation(mutation).execute() + } + override fun close() { apolloClient.closeQuietly() } diff --git a/src/test/kotlin/zenhub/ZenHubClientTest.kt b/src/test/kotlin/zenhub/ZenHubClientTest.kt index 8a8aa3d..c5b0425 100644 --- a/src/test/kotlin/zenhub/ZenHubClientTest.kt +++ b/src/test/kotlin/zenhub/ZenHubClientTest.kt @@ -1,7 +1,6 @@ package zenhub import kotlin.test.assertEquals -import kotlin.test.assertNotNull import kotlin.test.assertTrue import org.junit.jupiter.api.Test @@ -15,17 +14,6 @@ class ZenHubClientTest { assertEquals(18004, issue?.issueFragment?.number) } - @Test - fun whenGetIssuesByPipelineThenAtLeastZeroIssues() { - val issues = zenHubClient.getIssuesByPipeline(Pipeline.MERGE_READY) - - if (issues.isNotEmpty()) { - assertTrue(issues[0].issueFragment.number > 0) - } else { - assertNotNull(issues) - } - } - @Test fun whenGetReleasesForValidRepoThenAtLeastOneRelease() { val releases = zenHubClient.getReleases(DEFAULT_GITHUB_REPOSITORY_ID)