Skip to content

Commit

Permalink
Update index.js
Browse files Browse the repository at this point in the history
  • Loading branch information
melscoop authored Sep 23, 2024
1 parent bafed8c commit c022a90
Showing 1 changed file with 5 additions and 7 deletions.
12 changes: 5 additions & 7 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,21 @@ const github = require('@actions/github');

async function run() {
try {
// Retrieve the GitHub token from the environment
const token = process.env.GITHUB_TOKEN || core.getInput('GITHUB_TOKEN');
const octokit = github.getOctokit(token);
const token = core.getInput('github_token'); // Get the github_token input
const octokit = github.getOctokit(token); // Use the token for GitHub API requests

const { context } = github;
const { review, pull_request, repository } = context.payload;

// Check if the review is an approval and has no comment
if (review.state === "approved" && (!review.body || review.body.trim() === "")) {
// Post a comment on the pull request notifying the user
await octokit.rest.issues.createComment({
issue_number: pull_request.number,
owner: repository.owner.login,
repo: repository.name,
issue_number: pull_request.number,
body: `@${review.user.login}, approval without a comment is not allowed. Please provide a comment when approving the PR.`
});

throw new Error(`Approval without a comment is not allowed. Please provide a comment.`);
throw new Error('Approval without a comment is not allowed. Please provide a comment.');
}
} catch (error) {
core.setFailed(error.message);
Expand Down

0 comments on commit c022a90

Please sign in to comment.