Using octokit its possible to interact with Github from CI pipelines. The example below adds a comment to a PR.
const {
env: { OWNER, ACCESS_TOKEN, REPOSITORY_URL, REVIEW_ID, PULL_REQUEST },
} = require('process');
function init() {
const { Octokit } = require('@octokit/rest');
const octokit = new Octokit({
auth: ACCESS_TOKEN,
});
return {
createComment: async (comment) => {
const config = {
owner: OWNER,
repo: REPOSITORY_URL.split('/').pop(),
issue_number: REVIEW_ID,
};
await octokit.issues.createComment({
...config,
body: comment,
});
},
};
}
And here's how you might use that in a Netlify plugin.
module.exports = {
onSuccess: async () => {
const { createComment } = initialiseGithub();
await createComment('The Netlify build has succeeded');
},
onError: async () => {
const { createComment } = initialiseGithub();
await createComment('The Netlify build has failed');
},
};
Top comments (0)