-
-
Save developer-guy/14beba1e7077cc73ec214b3d5e815c40 to your computer and use it in GitHub Desktop.
src/index.js for github action
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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