Skip to content

Commit

Permalink
hi
Browse files Browse the repository at this point in the history
  • Loading branch information
subhajitxyz committed Oct 31, 2024
1 parent 6b8576e commit f3bb778
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 65 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,8 @@ interface GitHubService {
* @return the list of [GitHubIssue]s read from the remote repository (as a [Call])
*/
@Headers("Accept: application/vnd.github+json", "X-GitHub-Api-Version: 2022-11-28")
// @GET("repos/{repo_owner}/{repo_name}/issues?direction=asc")
// add by subha
@GET("repos/{repo_owner}/{repo_name}/issues?direction=asc&pulls=false")
// @GET("repos/{repo_owner}/{repo_name}/issues?state=open&direction=asc")
fun fetchOpenIssues(
@Path("repo_owner") repoOwner: String,
@Path("repo_name") repoName: String,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,37 +84,6 @@ class TodoOpenCheckTest {
assertThat(outContent.toString().trim()).isEqualTo(TODO_CHECK_PASSED_OUTPUT_INDICATOR)
}

// subha
@Test
fun testOpenIssuesOnly_withPullRequests_checkShouldFail() {
// Setup with open issues and some pull requests
setUpGitHubService(
openIssueNumbers = listOf(11004, 11003, 11002, 11001), pullRequestNumbers = listOf(21001)
)

val tempFile1 = tempFolder.newFile("testfiles/TempFile1.kt")
val tempFile2 = tempFolder.newFile("testfiles/TempFile2.kt")
val testContent1 =
"""
// TODO(#11002): test summary 1.
# TODO(#11004): test summary 2.
test Todo
test TODO
""".trimIndent()
val testContent2 =
"""
// TODO(#21001): test summary 3.
todo
<!-- TODO(#11003): test summary 4-->
""".trimIndent()
tempFile1.writeText(testContent1)
tempFile2.writeText(testContent2)

runScript()

assertThat(outContent.toString().trim()).isEqualTo(TODO_SYNTAX_CHECK_FAILED_OUTPUT_INDICATOR)
}

@Test
fun testTodoCheck_onlyPoorlyFormattedTodosPresent_checkShouldFail() {
setUpGitHubService(issueNumbers = emptyList())
Expand Down Expand Up @@ -808,42 +777,14 @@ class TodoOpenCheckTest {
assertThat(outContent.toString().trim()).isEqualTo(failureMessage)
}

// subha
private fun setUpGitHubService(
openIssueNumbers: List<Int>,
pullRequestNumbers: List<Int> = emptyList()
) {
// Create JSON objects for open issues
val openIssuesJson = openIssueNumbers.joinToString(separator = ",") { "{\"number\":$it}" }

// Create JSON objects for pull requests (using the `pull_request` field to indicate it's a PR)
val pullRequestsJson = pullRequestNumbers.joinToString(separator = ",") {
"{\"number\":$it, \"pull_request\":{}}" // Include an empty pull_request object
}

// Combine them to simulate a typical GitHub response where issues & PRs might mix
val combinedJson = if (pullRequestsJson.isNotEmpty()) {
"[$openIssuesJson, $pullRequestsJson]"
} else {
"[$openIssuesJson]" // Only include open issues if PRs are empty
}
private fun setUpGitHubService(issueNumbers: List<Int>) {
val issueJsons = issueNumbers.joinToString(separator = ",") { "{\"number\":$it}" }
val mockWebServer = MockWebServer()

mockWebServer.enqueue(MockResponse().setBody(combinedJson))
mockWebServer.enqueue(MockResponse().setBody("[]")) // Simulate end of pagination.

// Set the mock server URL for the GitHub client to use
mockWebServer.enqueue(MockResponse().setBody("[$issueJsons]"))
mockWebServer.enqueue(MockResponse().setBody("[]")) // No more issues.
GitHubClient.remoteApiUrl = mockWebServer.url("/").toString()
}

// private fun setUpGitHubService(issueNumbers: List<Int>) {
// val issueJsons = issueNumbers.joinToString(separator = ",") { "{\"number\":$it}" }
// val mockWebServer = MockWebServer()
// mockWebServer.enqueue(MockResponse().setBody("[$issueJsons]"))
// mockWebServer.enqueue(MockResponse().setBody("[]")) // No more issues.
// GitHubClient.remoteApiUrl = mockWebServer.url("/").toString()
// }

private fun setUpSupportForGhAuth(authToken: String) {
fakeCommandExecutor.registerHandler("gh") { _, args, outputStream, _ ->
when (args) {
Expand Down

0 comments on commit f3bb778

Please sign in to comment.