Skip to content

Instantly share code, notes, and snippets.

@Deborah-Digges
Created October 16, 2020 19:59
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save Deborah-Digges/f0edad96e22bfe272a888aaa659a783f to your computer and use it in GitHub Desktop.
Save Deborah-Digges/f0edad96e22bfe272a888aaa659a783f to your computer and use it in GitHub Desktop.
src/index.js for github action
const core = require('@actions/core');
const github = require('@actions/github');
async function run() {
try {
const accessToken = core.getInput('access-token');
const message = core.getInput('message');
const payload = github.context.payload;
const githubClient = github.getOctokit(accessToken);
core.info("Request received");
if (payload.action === "opened") {
core.info("New Pull Request..");
const pullRequest = payload.pull_request;
const userName = pullRequest.user.login;
const owner = pullRequest.base.repo.owner.login;
const repoName = pullRequest.base.repo.name;
const issueNumber = pullRequest.number;
const comment = message.replace(/{}/g, userName);
const shouldComment = await isFirstPull(
githubClient, owner, repoName,
userName, issueNumber
);
// Comment on the pull request made by a new contributor
if (shouldComment) {
core.info("Commenting");
githubClient.issues.createComment({ owner, repo: repoName, issue_number: issueNumber, body: comment });
}
}
} catch (err) {
core.setFailed(err.message);
}
}
run();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment