Skip to content
You're viewing an older version of this GitHub Action. Do you want to see the latest version instead?
arrow-up-right

GitHub Action

use-herald-action

v1.3.0

use-herald-action

arrow-up-right

use-herald-action

GitHub action to add reviewers, subscribers and assignees to your PR

Installation

Copy and paste the following snippet into your .yml file.

              

- name: use-herald-action

uses: gagoar/[email protected]

Learn more about this action in gagoar/use-herald-action

Choose a version

GitHub Marketplace Workflow codecov MIT license

Use Herald Action

This action allows you to add comments, reviewers and assignees to a pull request depending on rules you define!

Table of contents


What is use-herald-action?

Given a set of rules defined in a JSON document, this action will execute actions based on those rules.

A rule is a way of defining an action that is to be performed once a certain set of conditions is met. For example, you might want to get notified every time somebody opens a pull request that affects some file you're interested in, even if they didn't add you as a reviewer and you are not a codeowner.

Working with a more concrete example, we have the power to create a rule that:

  • Has conditions:
    • { pull_request title contains node}
    • { files matching *.ts are changed }
  • If all conditions met, will take the action:
    • notify me

One way to think about these rules is to compare it to mail filters (Gmail filters) that will, for example, apply labels to incoming mail if certain keywords are found in the subject or body. In this context, we are dealing with pull requests instead of emails.

Motivation

This action is particularly useful when you want to subscribe to changes made to certain files, much like the "Subscriber" concept used in Phabricator.

For attaching reviewers, GitHub offers CODEOWNERS. However, no equivalent exists for assigning users. Nor does there exist a method to automatically subscribe to said pull requests (without being a reviewer).

Although the main motivation behind this GitHub Action is to bridge the gap described above, this can be extended to many different use cases.


How to create a rule

Every rule can be written in JSON with the following key-value pairs:

Key Type Required Description
name string No Friendly name to recognize the rule; defaults to the rule filename
action string Yes Currently, supported actions are comment review and assign
users string[] No GitHub user handles (or emails) on which the rule will take action
teams string[] No GitHub teams on which the rule will take action
includes string | string[] No Glob pattern/s used to match changed filenames in the pull request
excludes string | string[] No Glob pattern/s used to exclude changed filenames (requires includes key to be provided)
eventJsonPath string No JsonPath expression used to filter information in the pull request event
includesInPatch string | string[] No regex to match file content changes (ignored if malformed or invalid)
customMessage string No Message to be commented on the pull request when the rule is applied (requires action === comment)

Rule Examples

Notify users @eeny, @meeny, @miny and @moe when all files matching *.ts are changed

{
  "users": ["@eeny", "@meeny", "@miny", "@moe"],
  "action": "comment",
  "includes": "*.ts"
}

Notify team @myTeam when files matching directory/*.js are changed, excluding directory/notThisFile.js

{
  "teams": ["@myTeam"],
  "action": "comment",
  "includes": "directory/*.ts",
  "excludes": "directory/notThisFile.js"
}

Assign team @QATeam when files matching integration/*.js are changed and the title of the pull request includes QA

{
  "teams": ["@QATeam"],
  "action": "assign",
  "includes": "integration/*.ts",
  "eventJSONPath": "$[?(@.title =~ /QA/)].title"
}

Input parameters

Key Type Required Description
GITHUB_TOKEN string Yes GitHub token, necessary for adding reviewers, assignees or comments on the PR
rulesLocation string Yes Directory where the rules can be found
base string No Fixed base - tag/branch against which to always compare changes (more info on base
DEBUG string No Provide to enable verbose logging (ex: DEBUG: "*")
dryRun boolean No Evaluate rule conditions but do not execute actions - see output for results

Output

This action will store the rules applied in outputs.appliedRules. Here, you will find the matching rules, grouped by actions (comment | assign | review).

Note that you will have to parse the output using the fromJSON function before accessing individual properties. See the Using Output example for more details.


Examples

Basic example

This step runs the action without regard for output:

- name: Apply Herald rules
  uses: gagoar/use-herald-action@master
  with:
    GITHUB_ACTION: ${{ secrets.GITHUB_ACTION }}
    rulesLocation: 'rules/*.json'
    dryRun: true

Using output

These steps stores the action's outputs into a JSON file:

- name: Apply Herald rules
  uses: gagoar/use-herald-action@master
  id: foobar
  with:
    GITHUB_ACTION: ${{ secrets.GITHUB_ACTION }}
    rulesLocation: 'rules/*.json'
    dryRun: true
- name: Store applied rules to file
  run: echo '\${{ fromJSON(steps.foobar.outputs.appliedRules) }}' > rulesApplied.json

Notice the inclusion of the id field in the first step (Invoke foobarFunction Lambda). This is so that the second step (Store response payload to file) can reference the result of the first step. For more information for Github Actions outputs, see their reference.