Git Product home page Git Product logo

pull-request-comment-trigger's Introduction

Pull Request Comment Trigger

Look for a "trigger word" in a pull-request description or comment, so that later steps can know whether or not to run.

Example usage in a workflow

Your workflow needs to listen to the following events:

on:
  pull_request:
    types: [opened]
  issue_comment:
    types: [created]

And then you can use the action in your jobs like this:

jobs:
  deploy:
    runs-on: ubuntu-latest
    steps:
      - uses: khan/[email protected]
        id: check
        with:
          trigger: '@deploy'
          reaction: rocket
        env:
          GITHUB_TOKEN: '${{ secrets.GITHUB_TOKEN }}'
      - run: 'echo Found it!'
        if: steps.check.outputs.triggered == 'true'

Reaction must be one of the reactions here: https://developer.github.com/v3/reactions/#reaction-types And if you specify a reaction, you have to provide the GITHUB_TOKEN env vbl.

Inputs

Input Required? Description
trigger Yes The string to look for in pull-request descriptions and comments. For example "#build/android".
prefix_only No (default 'false') If 'true', the trigger must match the start of the comment.
reaction No (default '') If set, the specified emoji "reaction" is put on the comment to indicate that the trigger was detected. For example, "rocket".

Outputs

Output Description
triggered 'true' or 'false' depending on if the trigger phrase was found.
comment_body The comment body.

pull-request-comment-trigger's People

Contributors

alexjurkiewicz avatar jaredly avatar michael-pr avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

pull-request-comment-trigger's Issues

Quote reply option?

Hello, I was wondering if it could be possible to include a quoted reply instead of some reaction to the original message ?
Maybe is possible with the message body output already included ?

Cannot get the action to work

For some reason I cannot make the action work. I forked the repo (so it has the .github/workflows/example.yml workflow), created a pull-request and left a comment but the action does not trigger: GytisBraz#1 - I don't expect #look or #deploy to work without a GH token but #hello should work.

Am I missing something?

Edit: nevermind, the action appears under the Actions tab

Alternative workflow in yaml without dependancies.

Thank you for the inspiration.

I have written raw workflow without external dependencies in yaml.

https://github.com/kuvaldini/actions-trigger-when-pr-commented

name: on-pr-comment

on:
  push:
  pull_request:
  issue_comment:
    types: [created]
  workflow_dispatch:

jobs:
  rocket:
    ## Just to react to valid comment with rocket
    runs-on: ubuntu-latest
    if: ${{ github.event.comment &&
          github.event.issue.pull_request &&
          startsWith(github.event.comment.body, '/buildme') }}
    steps:
      - 
        name: Reaction
        run: |
          # send reaction to comment to show build was triggered
          curl ${{github.event.comment.url}}/reactions \
            -X POST \
            -d '{"content":"rocket"}' \
            -H "Accept: application/vnd.github.squirrel-girl-preview+json" \
            -H "Authorization: token ${{github.token}}"

  build:
    runs-on: ubuntu-latest
    ## Run on each event, but PR comment is checked for key phrase.
    if: ${{ github.event_name != 'issue_comment' ||
            ( github.event.issue.pull_request &&
            startsWith(github.event.comment.body, '/buildme') ) }}
    steps:
      - #&step_detect_commented_pr
        name: REF and SHA of commented PR to ENV
        if: github.event.comment
        run: >
            curl -fsSL ${{github.event.issue.pull_request.url}}
            -H "Authorization: token ${{github.token}}" |
            jq -r '
              "PR_REF="+.head.ref, 
              "PR_SHA="+.head.sha, 
              "PR_NUM="+(.number|tostring), 
              "PR_REPO="+.head.repo.full_name' >>$GITHUB_ENV
      - #&step_checkout
        name: Checkout
        uses: actions/checkout@v2
        with:
          ref:        ${{env.PR_REF}}  ## not empty on issue_comment, else default value GITHUB_REF
          repository: ${{env.PR_REPO}} ## not empty on issue_comment, else default value github.repository, required by forks

`steps.check.outputs.comment_body` is blank

steps.check.outputs.comment_body seems to always be blank for me.

on:
  pull_request:
    types: [opened]
  issue_comment:
    types: [created]
jobs:
  deploy:
    runs-on: ubuntu-latest
    steps:
      - uses: khan/pull-request-comment-trigger@master
        id: check
        with:
          trigger: 'RunTest'
          prefix_only: 'true'
          reaction: rocket
        env:
          GITHUB_TOKEN: '${{ secrets.GITHUB_TOKEN }}'
      - run: 'echo ${{ steps.check.outputs.comment_body }}'
        if: steps.check.outputs.triggered == 'true'

I'm triggering this with a comment RunTest test1 hoping that the job runs echo RunTest test1

However I get echo as the step name and a blank echo output.

If I replace the echo with 'echo ${{ steps.check.outputs.trigger }}' I get echo true so it seems comment_body has an issue

Repo abandoned?

There seem to be many warnings and no PR approvals. Is this repo still maintained? Otherwise is there a fork where the warnings are addressed? If not I'm happy to take this over.

what's so special about "check"?

I thought since the id was check, changing the id to, say, lint, would allow changing

if: steps.check.outputs.triggered == 'true'
to
if: steps.lint.outputs.triggered == 'true'

however, this didn't work, steps.lint.outputs.triggered == 'true' never cause the next step to run

      - uses: khan/pull-request-comment-trigger@master
         id: lint
         with:
           trigger: '/lint'
           reaction: rocket
         env:
           GITHUB_TOKEN: '${{ secrets.GITHUB_TOKEN }}'
       - uses: yu-iskw/action-sqlfluff@v3
         if: steps.lint.outputs.triggered == 'true'

when I changed back to check everything worked as expected. Why is this? Doesn't really conform with the documentation here: https://docs.github.com/en/actions/learn-github-actions/contexts#steps-context which says you may access steps.<step_id>.outputs

Bump @actions/github version for GitHub Enterprise Server support

I attempted to use this action on a self-hosted GitHub Enterprise Server (GHES), and it's still trying to talk to the github.com API to post the reaction.

The description of actions/github on NPM ( https://www.npmjs.com/package/@actions/github ) says:

Returns an authenticated Octokit client that follows the machine proxy settings and correctly sets GHES base urls.

It looks like actions/github is currently at version 5.0.2 but this project is locked to version 1.1.0.

Bumping actions/github to any version from 2.2.0 up should fix this.

Provide information about PR to outputs

i.e PR_SHA, PR_REF, like GITHUB_SHA and GITHUB_REF. And PR_REPO for forks. They could be later used in checkout step.
Also PR_NUM is useful, or just 'number'

The source code?

Hey! I would like to explore the source code of this action. Can you share the code which you use to build this?

Dev for issue_comment trigger workflow

I write a workflow on issue_comment. The problem that github action will pick up the worflow yaml from master(default) branch. So I can not have the dev and test envrionment for the workflow.

Feature: expose PR head ref

It would be realy helpfull if this plugin also outputs the head ref of the PR, so you can chain actions that do something with the PR.

My current use-case is, that I wan't to run a command that changes some files and commit them to the PR, whenever a given command is commented on the PR.

As far as I can see, the @github/actions package already provides you the information I need, you only need to expose them using setOutput.

const core = require("@actions/core");
const {context} = require('@actions/github')
const headRef = context.payload.pull_request.head.ref;

core.setOutput("headRef", headRef);

Ressources:

does this trigger "later in life"?

we have a PR and when the tester comments "start_testing!" we want to spin up a test environment for this branch.
i had the idea that we just need to listen for comments in PRs and your action would be sufficient, but nothing here gets triggered.

am i right with the assumption, that our usecase won't work?

name: Starting a test environment
on:
  pull_request:
    types: [opened]
  issue_comment:
    types: [created]

jobs:
  spinup:
    runs-on: ubuntu-latest
    steps:
      - uses: khan/pull-request-comment-trigger@master
        id: check
        with:
          trigger: 'start_testing!'
      - run: 'sh deploy.sh #here we can run the pipeline to spin up an environment'
        if: steps.check.outputs.triggered == 'true'


TypeError: Cannot read property 'includes' of null

We now have this error:
Run khan/pull-request-comment-trigger@master TypeError: Cannot read property 'includes' of null at run (/home/runner/work/_actions/khan/pull-request-comment-trigger/master/dist/index.js:10700:15) at Object.871 (/home/runner/work/_actions/khan/pull-request-comment-trigger/master/dist/index.js:10729:1) Error: Unexpected error at __webpack_require__ (/home/runner/work/_actions/khan/pull-request-comment-trigger/master/dist/index.js:23:30) at startup (/home/runner/work/_actions/khan/pull-request-comment-trigger/master/dist/index.js:38:19) at /home/runner/work/_actions/khan/pull-request-comment-trigger/master/dist/index.js:42:18 at Object.<anonymous> (/home/runner/work/_actions/khan/pull-request-comment-trigger/master/dist/index.js:45:10) at Module._compile (internal/modules/cjs/loader.js:959:30) at Object.Module._extensions..js (internal/modules/cjs/loader.js:995:10) at Module.load (internal/modules/cjs/loader.js:815:32) at Function.Module._load (internal/modules/cjs/loader.js:727:14)

While your code didn't changed until a long time, I guess this is due to node/ubuntu versions: the ubuntu:latest has been updated a few days ago and I guess the error comes with it: https://github.com/actions/virtual-environments/releases/tag/ubuntu20%2F20210803.0

I also tried with ubuntu-18.04 but same error.

Thanks for help,
Regards.

Does this action still work?

No matter what I do I can't get this action to execute with a PR comment. My workflow is:

name: 'deploypr'
on:
  pull_request:
    types: [opened]
  issue_comment:
    types: [created]
jobs:
  deploypr:
    runs-on: ubuntu-latest
    steps:
      - uses: khan/pull-request-comment-trigger@master
        id: check
        with:
          trigger: 'deploy'
          prefix_only: 'true'
          reaction: rocket
        env:
          GITHUB_TOKEN: `${{ secrets.GITHUB_TOKEN }}`
      - run: 'echo Found it!'
        if: steps.check.outputs.triggered == 'true'

However when I type a comment with only the word deploy there is no action executed. Am I missing something?

Prefix_only doesn't work

Hi,

I'm encountering this issue using this action khan/pull-request-comment-trigger@master using:

        - uses: khan/pull-request-comment-trigger@master
          id: check
          with:
            trigger: '!deploy'
            prefix_only: 'true'
            reaction: rocket
          env:
            GITHUB_TOKEN: '${{ secrets.GITHUB_TOKEN }}'

Action gets triggered also if "!deploy" is in the middle of a comment (not according to README.md docs)

Also --> trying to get steps.check.outputs.comment_body is empty

Suggestion: pass arguments to workflow

Thank you for this action! I thought that it should be possible to use the trigger phrase to "pass arguments" to a workflow. For example, the trigger phrase "#runsomething" and the comment "#runsomething arg1 arg2" could make "arg1" and "arg2" available inside the workflow (maybe as env variables). Those could in turn be passed as arguments to scripts.

Would that be of interest? Would that be hard to implement?

Multiple trigger key check

I was trying to check multiple keywords to trigger the same workflow based on the input and passing the input comment as parameter to a shell script. Does this support multiple keyword check with an OR ('|') operator? or some other way.

Below is my workflow contents:

on:
issue_comment:
types: [created]

jobs:
deploy:
runs-on: macos-latest
steps:
- uses: khan/pull-request-comment-trigger@master
id: check
with:
trigger: 'qabuild | prodbuild'
prefix_only: true
env:
GITHUB_TOKEN: '${{ secrets.GITHUB_TOKEN }}'
- run: 'echo Found one of the keywords!'
if: steps.check.outputs.triggered == 'true'
- name: run the trigger script
if: steps.check.outputs.triggered == 'true'
run: sudo sh ./.github/scripts/trigger_build.sh ${{ github.event.comment.body }}

I was able to run it successfully with just one trigger keyword but failing when I add other keywords with OR operator.

Different keywords trigger multiple workflows.

I have two commands:
/APPLY -> which does one job
/APPLY_AND_MERGE -> which does one job and if success merge the Pull Requests

When I write any of the above keyword in the comment, both of them fire at the same time.

Is any kind of wildcard for the trigger? I expect each keyword to run only one workflow.

Error: Cannot find module '@actions/core'

in the last hour we have started getting the following errors, is it possible the dist/index.js is broken?

Run khan/pull-request-comment-trigger@master
internal/modules/cjs/loader.js:818
  throw err;
  ^

Error: Cannot find module '@actions/core'
Require stack:
- /home/runner/work/_actions/khan/pull-request-comment-trigger/master/dist/index.js
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:815:15)
    at Function.Module._load (internal/modules/cjs/loader.js:667:27)
    at Module.require (internal/modules/cjs/loader.js:887:19)
    at require (internal/modules/cjs/helpers.js:74:18)
    at Object.880 (/home/runner/work/_actions/khan/pull-request-comment-trigger/master/dist/index.js:137:33)
    at __webpack_require__ (/home/runner/work/_actions/khan/pull-request-comment-trigger/master/dist/index.js:25:31)
    at Object.62 (/home/runner/work/_actions/khan/pull-request-comment-trigger/master/dist/index.js:57:14)
    at __webpack_require__ (/home/runner/work/_actions/khan/pull-request-comment-trigger/master/dist/index.js:25:31)
    at startup (/home/runner/work/_actions/khan/pull-request-comment-trigger/master/dist/index.js:44:19)
    at /home/runner/work/_actions/khan/pull-request-comment-trigger/master/dist/index.js:48:18 {
  code: 'MODULE_NOT_FOUND',
  requireStack: [
    '/home/runner/work/_actions/khan/pull-request-comment-trigger/master/dist/index.js'
  ]
}

cc/ @ajeisens

Create new release

It seems that the prefix_only variable isn't available with the published releases because the code was added but no tag was created. Could you tag the latest commit? Thanks!

Update action to use `node16` instead of `node12`

As we are getting more and more warnings to update our actions to node16, I found we use your pull-request-comment-trigger which still uses node12.

Please update the action to node16 (PR will follow).

Thanks,
Martin

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.