This GitHub Action is intended to replace repeated if
statements within a workflow file, by allowing the user to cancel an action based on attributes of the GitHub context that is generated on the event.
It utilizes PegJS to generate a simple filter language that allows you to traverse the context and validate that attributes match what you are looking for.
Generate a Personal Access Token and save it in your secrets for the Repo that you wish to use this action.
FILTER
: This is the filter that is used validate the GitHub context. When it evaluates to True the action exits and your workflow continues on. When it evaluates to False the action will utilize the Actions API to cancel the current workflow
GITHUB_TOKEN
: This is thePAT
that you generated earlier. This is used to call the Actions API to cancel the current workflow run
Currently the grammer is quite simple. You can have a string, surrounded by single or double quotes, or a path to a property within the GitHub Context. Paths and Strings can be compared with the standard boolean operators, <
, <=
, >
, >=
, ==
.
Additionally you can validate that a property is in a list of strings using the in
operator (examples below).
Finally there is a not operator, !
that can be prepended to the command group to negate the result.
Commands can be chained with ||
and &&
. Currently the grammer does not support operator precedence and will combine commands together in order from left to right.
Command grouping with parenthesis is not currently implemented, but it is on the wishlist (PR's welcome!)
Paths use the standard javascript dot notation, so to get the issue number of an issue you would have a path like so: payload.issue.number
Strings are any group of text surrounded by a single or double quotes. Anything else will be assumed to be a path
in
lets you validate that a property is one of a list of strings like so payload.label.name in ['bug','documentation']
.
Temporarily we also will check the labels
object for their names, so if you want to make sure that your issue is labeled with a certain label, you can write a filter like this payload.issue.labels in ["bug","documentation"]
This is will be further fleshed out once we implement full object comparison.
- Filter the issue
labeled
event to onlybug
orquestion
payload.label.name in [ 'bug', 'question' ]
- Filter the comment created event to a certain user
payload.comment.user.login == "Chocrates"
- When a user opens a new
bug
leave them a comment with next steps and links to other resources to get help
name: Test workflow to add a comment to bugs
on:
issues:
types: [labeled]
jobs:
add-comment:
runs-on: ubuntu-latest
steps:
- uses: chocrates/stop-action-filter@master
with:
filter: 'payload.issue.labels in ["bug"]'
env:
GITHUB_TOKEN: ${{ secrets.TOKEN }}
- uses: ActionsDesk/add-comment-action@release/v1
with:
message: 'Thank you for opening an issue! I am sorry you are having troubles. While you wait for your issue to get Triaged, please consider glancing at the documentation in the wiki: https://github.com/Chocrates/stop-action-filter/wiki'
stepStatus: 'success'
env:
GITHUB_TOKEN: ${{ secrets.TOKEN }}
Please submit PR's for patches you would like to see merged into the mainline. If you have any questions or would like some help with please open an issue. When submitting PR's please make sure you have added tests covering the new functionality.
All code and documentation are released under the MIT License