DEV Community

James
James

Posted on

2 2

Creating a Github comment from Netlify

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,
      });
    },
  };
}
Enter fullscreen mode Exit fullscreen mode

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');
  },
};
Enter fullscreen mode Exit fullscreen mode

Image of Stellar post

How a Hackathon Win Led to My Startup Getting Funded

In this episode, you'll see:

  • The hackathon wins that sparked the journey.
  • The moment Josรฉ and Joseph decided to go all-in.
  • Building a working prototype on Stellar.
  • Using the PassKeys feature of Soroban.
  • Getting funded via the Stellar Community Fund.

Watch the video ๐ŸŽฅ

Top comments (0)

๐Ÿ‘‹ Kindness is contagious

Value this insightful article and join the thriving DEV Community. Developers of every skill level are encouraged to contribute and expand our collective knowledge.

A simple โ€œthank youโ€ can uplift someoneโ€™s spirits. Leave your appreciation in the comments!

On DEV, exchanging expertise lightens our path and reinforces our bonds. Enjoyed the read? A quick note of thanks to the author means a lot.

Okay