Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
package org.kiwiproject.changelog.github
import com.fasterxml.jackson.databind.ObjectMapper
import com.fasterxml.jackson.module.kotlin.readValue
import com.google.common.annotations.VisibleForTesting
import org.kiwiproject.changelog.config.RepoConfig
import org.kiwiproject.changelog.extension.getInt
import org.kiwiproject.changelog.extension.getListOfMaps
import org.kiwiproject.changelog.extension.getMap
import org.kiwiproject.changelog.extension.getString
import java.time.ZonedDateTime
import java.util.concurrent.atomic.AtomicInteger
class GitHubSearchManager(
private val repoConfig: RepoConfig,
private val api: GitHubApi,
private val githubPagingHelper: GitHubPagingHelper,
private val mapper: ObjectMapper
) {
fun findIssuesByMilestone(milestoneTitle: String): List {
val allIssuesAndPulls = mutableListOf()
val totalCount = AtomicInteger()
// Implementation note:
// Here, we make separate requests for issues and pull requests
// to avoid getting a 422 Unprocessable Entity. See the Note
// in the "Search issues and pull requests" section of the
// "REST API endpoints for search" page in the documentation
// stating that requests made with a user access token must
// include "is:issue" or "is:pull-request" in the query (q).
//
// ref: https://docs.github.com/en/rest/search/search?apiVersion=2022-11-28#search-issues-and-pull-requests
accumulateByType("issue", milestoneTitle, allIssuesAndPulls, totalCount)
accumulateByType("pull-request", milestoneTitle, allIssuesAndPulls, totalCount)
checkExpectedNumberOfIssues(allIssuesAndPulls.size, totalCount.get())
return allIssuesAndPulls.sortedByDescending { it.createdAt }
}
private fun accumulateByType(
type: String,
milestoneTitle: String,
allIssues: MutableList,
totalCount: AtomicInteger
) {
val firstPageUrl = createSearchUrl(milestoneTitle, type)
githubPagingHelper.paginate(api, firstPageUrl) { page, response ->
val responseContent = mapper.readValue