Adding a comment to a PR

Hi!

I’m trying to add a comment to a PR by doing the following

async function createComment(body) {
  try {
    const { context } = github;
    if (context.payload.pull_request == null) {
      core.setFailed('No pull request found.');
      return;
    }

    const pullNumber = context.payload.pull_request.number;
    const octokit = github.getOctokit(GITHUB_TOKEN);
    const owner = context.payload.sender.login;
    const repo = context.payload.repository.name;
    const newComment = octokit.issues.createComment({
      owner,
      repo,
      issue_number: pullNumber,
      body,
    });
  } catch (error) {
    core.setFailed(error.message);
  }
}

// ....
await createComment(message);
process.exit();
// ...

The action runs and I get no errors but the comment is never posted, any ideas what I may be doing wrong?

Thanks

Figured it out, it was using the wrong owner

1 Like