Skip to content
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

Retrieve all PR reviews when checking approvals #190

Merged
merged 2 commits into from
May 12, 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
4 changes: 2 additions & 2 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -468,7 +468,7 @@ async function fetchApprovalReviewCount(context, pullRequest) {
}

logger.debug("Getting reviews for", number, "...");
let { data: reviews } = await octokit.pulls.listReviews({
const reviews = await octokit.paginate(octokit.pulls.listReviews, {
owner: pullRequest.base.repo.owner.login,
repo: pullRequest.base.repo.name,
pull_number: number
Expand Down Expand Up @@ -22095,7 +22095,7 @@ module.exports = JSON.parse('[[[0,44],"disallowed_STD3_valid"],[[45,46],"valid"]
/***/ ((module) => {

"use strict";
module.exports = JSON.parse('{"name":"automerge-action","version":"0.15.1","description":"GitHub action to automatically merge pull requests","main":"lib/api.js","author":"Pascal","license":"MIT","private":true,"bin":{"automerge-action":"./bin/automerge.js"},"scripts":{"test":"jest","it":"node it/it.js","lint":"prettier -l lib/** test/** && eslint .","compile":"ncc build bin/automerge.js --license LICENSE -o dist","prepublish":"yarn lint && yarn test && yarn compile"},"dependencies":{"@actions/core":"^1.6.0","@octokit/rest":"^18.12.0","argparse":"^2.0.1","fs-extra":"^10.0.1","object-resolve-path":"^1.1.1","tmp":"^0.2.1"},"devDependencies":{"@vercel/ncc":"^0.33.3","dotenv":"^16.0.0","eslint":"^8.11.0","eslint-plugin-jest":"^26.1.3","jest":"^27.5.1","prettier":"^2.6.0"},"prettier":{"trailingComma":"none","arrowParens":"avoid"}}');
module.exports = JSON.parse('{"name":"automerge-action","version":"0.15.2","description":"GitHub action to automatically merge pull requests","main":"lib/api.js","author":"Pascal","license":"MIT","private":true,"bin":{"automerge-action":"./bin/automerge.js"},"scripts":{"test":"jest","it":"node it/it.js","lint":"prettier -l lib/** test/** && eslint .","compile":"ncc build bin/automerge.js --license LICENSE -o dist","prepublish":"yarn lint && yarn test && yarn compile"},"dependencies":{"@actions/core":"^1.6.0","@octokit/rest":"^18.12.0","argparse":"^2.0.1","fs-extra":"^10.0.1","object-resolve-path":"^1.1.1","tmp":"^0.2.1"},"devDependencies":{"@vercel/ncc":"^0.33.3","dotenv":"^16.0.0","eslint":"^8.11.0","eslint-plugin-jest":"^26.1.3","jest":"^27.5.1","prettier":"^2.6.0"},"prettier":{"trailingComma":"none","arrowParens":"avoid"}}');

/***/ })

Expand Down
2 changes: 1 addition & 1 deletion lib/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -461,7 +461,7 @@ async function fetchApprovalReviewCount(context, pullRequest) {
}

logger.debug("Getting reviews for", number, "...");
let { data: reviews } = await octokit.pulls.listReviews({
const reviews = await octokit.paginate(octokit.pulls.listReviews, {
owner: pullRequest.base.repo.owner.login,
repo: pullRequest.base.repo.name,
pull_number: number
Expand Down
25 changes: 11 additions & 14 deletions test/api.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,9 @@ test("only merge PRs with required approvals", async () => {
pulls: {
list: jest.fn(() => ({ data: [pr] })),
merge: jest.fn(() => (merged = true)),
listReviews: jest.fn(() => ({ data: [] }))
}
listReviews: Symbol("listReviews")
},
paginate: jest.fn(() => [])
};

const event = {
Expand All @@ -63,24 +64,20 @@ test("only merge PRs with required approvals", async () => {
expect(merged).toEqual(false); // if there's no approval, it should fail

merged = false;
octokit.pulls.listReviews.mockReturnValueOnce({
data: [
{ state: "APPROVED", user: { login: "approval_user" } },
{ state: "APPROVED", user: { login: "approval_user2" } }
]
});
octokit.paginate.mockReturnValueOnce([
{ state: "APPROVED", user: { login: "approval_user" } },
{ state: "APPROVED", user: { login: "approval_user2" } }
]);

// WHEN
await api.executeGitHubAction({ config, octokit }, "check_suite", event);
expect(merged).toEqual(true); // if there are two approvals, it should succeed

merged = false;
octokit.pulls.listReviews.mockReturnValueOnce({
data: [
{ state: "APPROVED", user: { login: "approval_user" } },
{ state: "APPROVED", user: { login: "approval_user" } }
]
});
octokit.paginate.mockReturnValueOnce([
{ state: "APPROVED", user: { login: "approval_user" } },
{ state: "APPROVED", user: { login: "approval_user" } }
]);

// WHEN a user has given
await api.executeGitHubAction({ config, octokit }, "check_suite", event);
Expand Down