Skip to content
This repository has been archived by the owner on Jun 3, 2024. It is now read-only.

Get all reviews in the PR with octokit.paginate #78

Merged
merged 1 commit into from
Apr 8, 2022
Merged
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
1 change: 1 addition & 0 deletions src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export const commitStateFailure: CommitState = "failure"

export const maxGithubApiFilesPerPage = 100
export const maxGithubApiTeamMembersPerPage = 100
export const maxGithubApiReviewsPerPage = 100

export const rulesConfigurations: RulesConfigurations = {
basic: {
Expand Down
16 changes: 10 additions & 6 deletions src/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
commitStateSuccess,
configFilePath,
maxGithubApiFilesPerPage,
maxGithubApiReviewsPerPage,
maxGithubApiTeamMembersPerPage,
} from "./constants"
import { LoggerInterface } from "./logger"
Expand Down Expand Up @@ -407,12 +408,15 @@ export const runChecks = async function (
}

if (matchedRules.length !== 0) {
const reviewsResponse = await octokit.rest.pulls.listReviews({
owner: pr.base.repo.owner.login,
repo: pr.base.repo.name,
pull_number: pr.number,
})
const { data: reviews } = reviewsResponse
const reviews = await octokit.paginate(
"GET /repos/{owner}/{repo}/pulls/{pull_number}/reviews",
{
owner: pr.base.repo.owner.login,
repo: pr.base.repo.name,
pull_number: pr.number,
per_page: maxGithubApiReviewsPerPage,
},
)

const latestReviews: Map<
number,
Expand Down
8 changes: 6 additions & 2 deletions test/constants.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
import { configFilePath, maxGithubApiFilesPerPage } from "src/constants"
import {
configFilePath,
maxGithubApiFilesPerPage,
maxGithubApiReviewsPerPage,
} from "src/constants"
import { AndDistinctRule, AndRule, BasicRule, OrRule, PR } from "src/types"

export const org = "org"
Expand All @@ -25,7 +29,7 @@ export const condition = "condition"
export const githubApi = "https://api.github.com"
export const githubWebsite = "https://github.com"
export const prApiPath = `/repos/${org}/${repo}/pulls/${prNumber}`
export const reviewsApiPath = `${prApiPath}/reviews`
export const reviewsApiPath = `${prApiPath}/reviews?per_page=${maxGithubApiReviewsPerPage}`
export const changedFilesApiPath = `${prApiPath}/files?per_page=${maxGithubApiFilesPerPage}`
export const requestedReviewersApiPath = `${prApiPath}/requested_reviewers`
export const configFileContentsApiPath = `/repos/${org}/${repo}/contents/${encodeURIComponent(
Expand Down