Skip to content

Commit

Permalink
Fixes #3
Browse files Browse the repository at this point in the history
  • Loading branch information
peckjon authored Jun 15, 2022
1 parent c3e8229 commit d6e0f18
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 61 deletions.
36 changes: 4 additions & 32 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
const core = __importStar(__webpack_require__(470));
const github = __importStar(__webpack_require__(469));
function removeExistingApprovalsIfExist(client, pr) {
var _a, _b, _c, _d;
var _a, _b, _c;
return __awaiter(this, void 0, void 0, function* () {
// Get list of all reviews on a PR
const { data: listReviews } = yield client.rest.pulls.listReviews({
Expand All @@ -396,47 +396,19 @@ function removeExistingApprovalsIfExist(client, pr) {
});
// Remove PR approvals by any committer to the PR
for (let review of listReviews) {
core.info(`review.id: ${review.id}`);
core.info(`review.state: ${review.state}`);
core.info(`review.pull_request_url: ${review.pull_request_url}`);
core.info(`review.user.login: ${(_a = review.user) === null || _a === void 0 ? void 0 : _a.login}`);
core.info(`commitAuthorLogins: ${commitAuthorLogins}`);
if (review.state === 'APPROVED' &&
review.user &&
commitAuthorLogins.includes(review.user.login)) {
core.info(`Removing an approval from ${(_b = review.user) === null || _b === void 0 ? void 0 : _b.login} (cannot approve this PR since they committed to it)`);
// core.info(`review.body: ${review.body}`);
// if (review.body.length > 0) {
// core.info(
// `Moving review comment to a new comment in order to dismiss review.`
// );
// const { data: submitReview } = await client.rest.pulls.submitReview({
// owner: github.context.repo.owner,
// repo: github.context.repo.repo,
// pull_number: pr.number,
// review_id: review.id,
// body: `Moving review comment by ${review.user?.login} to a new comment in order to dismiss review:\n\nreview.body`,
// event: 'COMMENT',
// });
// core.debug(`submitReview: ${JSON.stringify(submitReview)}`);
// const { data: updateReview } = await client.rest.pulls.updateReview({
// owner: github.context.repo.owner,
// repo: github.context.repo.repo,
// pull_number: pr.number,
// review_id: review.id,
// body: '',
// });
// core.debug(`updateReview: ${JSON.stringify(updateReview)}`);
// }
core.info(`Removing an approval (${review.id}) from ${(_a = review.user) === null || _a === void 0 ? void 0 : _a.login} (cannot approve this PR since they committed to it)`);
const dismissResponse = yield client.rest.pulls.dismissReview({
owner: github.context.repo.owner,
repo: github.context.repo.repo,
pull_number: pr.number,
review_id: review.id,
message: `${(_c = review.user) === null || _c === void 0 ? void 0 : _c.login} cannot approve this PR since they committed to it`,
message: `${(_b = review.user) === null || _b === void 0 ? void 0 : _b.login} cannot approve this PR since they committed to it`,
});
core.debug(`dismissResponse: ${JSON.stringify(dismissResponse)}`);
core.setFailed(`${(_d = review.user) === null || _d === void 0 ? void 0 : _d.login} cannot approve this PR since they committed to it`);
core.setFailed(`${(_c = review.user) === null || _c === void 0 ? void 0 : _c.login} cannot approve this PR since they committed to it`);
}
}
});
Expand Down
30 changes: 1 addition & 29 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,42 +25,14 @@ async function removeExistingApprovalsIfExist(client: GitHub, pr: any) {

// Remove PR approvals by any committer to the PR
for (let review of listReviews) {
core.info(`review.id: ${review.id}`);
core.info(`review.state: ${review.state}`);
core.info(`review.pull_request_url: ${review.pull_request_url}`);
core.info(`review.user.login: ${review.user?.login}`);
core.info(`commitAuthorLogins: ${commitAuthorLogins}`);
if (
review.state === 'APPROVED' &&
review.user &&
commitAuthorLogins.includes(review.user.login)
) {
core.info(
`Removing an approval from ${review.user?.login} (cannot approve this PR since they committed to it)`
`Removing an approval (${review.id}) from ${review.user?.login} (cannot approve this PR since they committed to it)`
);
// core.info(`review.body: ${review.body}`);
// if (review.body.length > 0) {
// core.info(
// `Moving review comment to a new comment in order to dismiss review.`
// );
// const { data: submitReview } = await client.rest.pulls.submitReview({
// owner: github.context.repo.owner,
// repo: github.context.repo.repo,
// pull_number: pr.number,
// review_id: review.id,
// body: `Moving review comment by ${review.user?.login} to a new comment in order to dismiss review:\n\nreview.body`,
// event: 'COMMENT',
// });
// core.debug(`submitReview: ${JSON.stringify(submitReview)}`);
// const { data: updateReview } = await client.rest.pulls.updateReview({
// owner: github.context.repo.owner,
// repo: github.context.repo.repo,
// pull_number: pr.number,
// review_id: review.id,
// body: '',
// });
// core.debug(`updateReview: ${JSON.stringify(updateReview)}`);
// }
const dismissResponse = await client.rest.pulls.dismissReview({
owner: github.context.repo.owner,
repo: github.context.repo.repo,
Expand Down

0 comments on commit d6e0f18

Please sign in to comment.