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

Do not approve the same PR twice #191

Merged
merged 7 commits into from
Apr 2, 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
29 changes: 27 additions & 2 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5867,7 +5867,7 @@ const core = __importStar(__nccwpck_require__(186));
const github = __importStar(__nccwpck_require__(438));
const request_error_1 = __nccwpck_require__(537);
function approve(token, context, prNumber) {
var _a;
var _a, _b;
return __awaiter(this, void 0, void 0, function* () {
if (!prNumber) {
prNumber = (_a = context.payload.pull_request) === null || _a === void 0 ? void 0 : _a.number;
Expand All @@ -5878,8 +5878,33 @@ function approve(token, context, prNumber) {
return;
}
const client = github.getOctokit(token);
core.info(`Creating approving review for pull request #${prNumber}`);
try {
core.info(`Getting current user info`);
const { data: user } = yield client.users.getAuthenticated();
core.info(`Current user is ${user.login}`);
core.info(`Getting pull request #${prNumber} info`);
const pull_request = yield client.pulls.get({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: prNumber,
});
const commit = pull_request.data.head.sha;
core.info(`Commit SHA is ${commit}`);
core.info(`Getting reviews for pull request #${prNumber} and commit ${commit}`);
const reviews = yield client.pulls.listReviews({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: prNumber,
});
for (const review of reviews.data) {
if (((_b = review.user) === null || _b === void 0 ? void 0 : _b.login) == user.login &&
review.commit_id == commit &&
review.state == "APPROVED") {
core.info(`Current user already approved pull request #${prNumber}, nothing to do`);
return;
}
}
core.info(`Pull request #${prNumber} has not been approved yet, creating approving review`);
yield client.pulls.createReview({
owner: context.repo.owner,
repo: context.repo.repo,
Expand Down
Loading