Skip to content

mheap/action-router

master
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
 
 
 
 
 
 
 
 
 
 

Action Router

Handle multiple events in your GitHub Action with ease!

Installation

npm install @mheap/action-router --save

Usage

The router will look for keys that match the event type e.g. pull_request and the subtype e.g. opened and execute any functions listed.

If a pull request was opened with the following configuration, pull_request and pull_request.opened would run.

const router = require("@mheap/action-router");
const allPrAction = require("./allPrs");
const labelAction = require("./label");
const openAction = require("./open");

router({
  "pull_request": [allPrAction],
  "pull_request.opened": [openAction],
  "pull_request.labeled": [labelAction]
});

You can even run multiple methods in response to an event:

router({
  "pull_request.opened": [
    openAction, 
    () => { console.log("This runs too") }
  ]
});

If you need to pass any data to each called method, you can specify it as the second parameter in router:

router({
  "pull_request.opened": [
    openAction,
    () => { console.log("This runs too") }
  ]
}, [someVar, "strings-too"]);

About

Handle multiple GitHub Actions events in a single action

Resources

Stars

Watchers

Forks

Packages

No packages published