npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

node-red-contrib-github-plus

v0.3.1

Published

Node-RED nodes to talk to GitHub

Downloads

41

Readme

GitHub Nodes

Node-RED nodes to interact with GitHub.

Install

Run the following command in the root directory of your Node-RED instance:

npm install --save node-red-contrib-github-plus

Usage

This set provides 2 nodes:

  • github-rest-api - a GitHub REST API client node. It makes REST API requests by sending msg.payload data to the specified API endpoint and outputs the response data as msg.payload.
  • github-webhook - a GitHub Webhook listener node. It listens to GitHub webhooks and outputs the event name as the msg.topic and the event payload object as the msg.payload.

Configuration

Setting Up GitHub API Client

Before making any API requests, you have to create a GitHub App. To do that follow the steps as per Creating a GitHub App guide:

  • create app and enter the basic info (steps 1 - 7)
  • skip the User authorization steps (8 - 11). The app is private and will be used to do automated things on its own. It doesn't need any user auth logic.
  • skip the Webhook steps (12 - 13) - will set it up later
  • specify permissions (step 14)
  • skip the events subscription (step 15) - will set it up later with the webhook
  • for "Where can this integration be installed?" set Only on this account (step 16)
  • push Create GitHub App
  • once created, you will be redirected to the App Settings page. There is the App ID number in the About section. You will need this number later.

Then you need to generate a private key:

  1. In the App settings scroll down to Private keys
  2. Click Generate a private key
  3. You should see a private key in .PEM format downloaded to your computer

Now you need to install the app on your repository(-ies). To do that follow the Installing your private GitHub App on your repository guide:

  • once installed, you will be redirected to the configuration options for the app installation. The url of the installation config page should look like https://github.com/.../settings/installations/<InstID>. You will need the <InstID> number later.

And finally configure your GitHub API client:

  1. Open your Node-RED instance
  2. Drag & drop the github-rest api node from the palette to the workspace and double-click on it, to open the node editor
  3. In the Client dropdown menu pick the Add New github-api-config option and press the pencil button at the right to add a new API configuration
  4. Copy-paste App ID from the App Settings page on GitHub to the node editor
  5. In the Private Key open the .PEM key file you downloaded from GitHub
  6. Copy-paste Inst ID from the app installation config page url to the node editor
  7. In then User-Agent enter your username or the name of your GitHub Application. Empty value defaults to node-red-contrib-github-plus. Read more why it is required.
  8. Push Update

Setting Up GitHub Webhooks

To listen for GitHub events, you first need to start a webhook listener on your server:

  1. Open your Node-RED instance
  2. Drag & drop the github-webhook node from the palette to the workspace and double-click on it, to open the node editor
  3. In the Path field set the url path the webhook listener will listen to notifications on.
  4. Push Generate Secret - you'll need the secret later
  5. Push Update
  6. Deploy

Now you need to setup a webhook on GitHub to send event notifications to your server. Follow the steps from Creating webhooks guide. Here are some tips:

  • if the app will be doing the same things for all repos it installed on, then setup a webhook in your GitHub App or Organization settings
  • if the app will have different logic from repo to repo, then setup a webhook in Repository settings
  • content type should be application/json - this is the content type used by github-webhook node
  • webhook url should be the url to the webhook listener on your server
  • webhook secret should be the Secret value you generated above

Making REST API Requests

To make REST API requests using the github-rest-api node, select API client you added and set the API endpoint the node will call. The API endpoint can be either specified in the node settings, or provided in msg.endpoint (if the endpoint is empty in the node settings). The request parameters are set via the msg.payload.

After executing a request the node outputs a message with the response data set to msg.payload.

If an API endpoint is in Preview mode and requires a Media Type to be set in the Accept header, then specify it in the Media Type node setting or via msg.mediaType (if the node setting is empty).

Handling Incoming Webhook Payloads

When GitHub sends an event notification to the url where you setup a webhook node to listen on, it will trigger the node output with the following properties:

  • msg.guid - GUID to identify the delivery. Value of X-GitHub-Delivery header.
  • msg.topic - Name of the event that triggered the delivery. Value of X-GitHub-Event header.
  • msg.payload - Webhook event payload.

Example

Adding Label To New Issues

This example flow adds a needs-response label to all new issues opened in the repository where the app is installed.

Adding Label To New Issues

Flow json for Node-RED: github-adding-label-to-new-issues.json

References

  • REST API Reference: https://docs.github.com/en/free-pro-team@latest/rest/reference
  • REST API Endpoints available for GitHub Apps: https://docs.github.com/en/free-pro-team@latest/rest/overview/endpoints-available-for-github-apps
  • REST API Media Types: https://docs.github.com/en/free-pro-team@latest/rest/overview/media-types
  • Webhook events and payloads: https://docs.github.com/en/free-pro-team@latest/developers/webhooks-and-events/webhook-events-and-payloads

Backers 💝

Red BTC Backer Red BTC Backer Red BTC Backer Red BTC Backer Red BTC Backer Red BTC Backer Red BTC Backer Red BTC Backer Red BTC Backer Red BTC Backer

[Donate] Thank you for your support! 🙌

Developing Nodes

Build & Test in Watch mode:

yarn dev

Testing Node Set in Node-RED

Read Node-RED docs on how to install the node set into your Node-RED runtime.

License

MIT © Alex Kaul