Skip to content

Setup an experimental SMACS repository to allow tooling scripts testing #19

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from
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 README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ This library provides a convenient interface for interacting with GitHub and Zen
# Build

```bash
./gradlew clean build
./gradlew build
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the clean task is unnecessary and will slow down build time

```

# Versioning
Expand Down
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
var currentVersion = "4.2.0"
var currentVersion = "5.0.0"

if (project.hasProperty("snapshot")) {
currentVersion = "${currentVersion}-SNAPSHOT"
Expand Down
5 changes: 5 additions & 0 deletions src/main/graphql/zenhub/CreateIssuePrConnection.graphql
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
mutation CreateIssuePrConnection($input: CreateIssuePrConnectionInput!) {
createIssuePrConnection(input: $input) {
clientMutationId
}
}
5 changes: 5 additions & 0 deletions src/main/graphql/zenhub/DeleteIssuePrConnection.graphql
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
mutation DeleteIssuePrConnection($input: DeleteIssuePrConnectionInput!) {
deleteIssuePrConnection(input: $input) {
clientMutationId
}
}
1 change: 1 addition & 0 deletions src/main/graphql/zenhub/fragments/IssueFragment.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PR id is needed to add / remove a connection to an issue

number
state
htmlUrl
Expand Down
15 changes: 0 additions & 15 deletions src/main/kotlin/zenhub/Pipeline.kt

This file was deleted.

31 changes: 20 additions & 11 deletions src/main/kotlin/zenhub/ZenHubClient.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -113,14 +109,14 @@ class ZenHubClient(
apolloClient.mutation(mutation).toFlow().single().data?.removeIssuesFromSprints
}

fun getIssuesByPipeline(pipeline: Pipeline): List<GetIssuesByPipelineQuery.Node> = runBlocking {
fun getIssuesByPipeline(pipelineId: String): List<GetIssuesByPipelineQuery.Node> = runBlocking {
val issues: ArrayList<GetIssuesByPipelineQuery.Node> = 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

Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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()
}
Expand Down
12 changes: 0 additions & 12 deletions src/test/kotlin/zenhub/ZenHubClientTest.kt
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package zenhub

import kotlin.test.assertEquals
import kotlin.test.assertNotNull
import kotlin.test.assertTrue
import org.junit.jupiter.api.Test

Expand All @@ -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)
}
}

Comment on lines -18 to -28
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this test isn't really usefull... it's not even a unit test (not fully mocked)

@Test
fun whenGetReleasesForValidRepoThenAtLeastOneRelease() {
val releases = zenHubClient.getReleases(DEFAULT_GITHUB_REPOSITORY_ID)
Expand Down