Auto Request Changes review when the job failed using Github Action
Tags: actionshackathon21, github, opensource, action
Published: 2021-11-21 17:19:00

---
title: Auto Request Changes review when the job failed using Github Action
published: true
description: using Github Action to auto create request changes pr review when the workflow job failed
tags: actionshackathon21, github, opensource, ActionsHackathon21, action
---

[Instructions]: # (To submit to the GitHub Actions x DEV Hackathon 2021, please fill out all sections.)

### My Workflow
[Note]: # (Please make sure the project links to the appropriate GitHub Actions repository, and includes [an open source license](https://choosealicense.com/) and README.)

The Github Action is forked from [hmarr/auto-approve-action](https://github.com/hmarr/auto-approve-action). The action will automatically create a `Request Changes` pull request review. A use case is to create a request changes review when a workflow job failed.

![auto-request-changes-action](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/thy53zlz4uvhuqljg3k2.png)
 
The action support 3 input parameters. You can use with [jobs.<job_id>.steps[*].with](https://docs.github.com/en/actions/learn-github-actions/workflow-syntax-for-github-actions#jobsjob_idstepswith) to add the input parameters.

- `github-token`: The Github token. By default, it will using `${{ github.token }}` to use the repo token.

- `comment-body`: The comment body to create a request changes review. The `comment-body` also support markdown text by Github. The default is `Some actions are not successful, please fix it`.

- `pull-request-number`: (optional) The ID of a pull request to auto-request-changes. By default, this action tries to use the pull_request event payload.

### Example use

you can use with `if` to avoid no pull request event and run only when the job failed. 

*for more [Github Action Context](https://docs.github.com/en/actions/learn-github-actions/contexts).

```
name: Auto request changes
on: pull_request_target

jobs:
  build:
    runs-on: ubuntu-latest
    steps:
      - uses: ntsd/auto-request-changes-action@v2
        if: ${{ github.event.pull_request && failure() }}
        with:
          comment-body: "The job ran failed please fix it."
```

You can also use it with `auto-approve-action` to make it auto approve when the job success.

```
name: Auto request changes
on: pull_request_target

jobs:
  build:
    runs-on: ubuntu-latest
    steps:
      - uses: ntsd/auto-request-changes-action@v2
        if: ${{ github.event.pull_request && failure() }}
        with:
          comment-body: "The job ran failed please fix it."
      - uses: hmarr/auto-approve-action@v2
        if: ${{ github.event.pull_request && success() }}
        with:
          github-token: "${{ secrets.GITHUB_TOKEN }}"
```

### Submission Category: 

[Note]: # (Maintainer Must-Haves, DIY Deployments, Interesting IoT, Phone Friendly, or Wacky Wildcards)

Maintainer Must-Haves

### Yaml File or Link to Code

[Note]: # (Our markdown editor supports pretty embeds. Try this syntax: `{% github link_to_your_repo %}` to share a GitHub repository)

{% github https://github.com/ntsd/auto-request-changes-action %}

### Additional Resources / Info

[Auto Request Changes Action Repo](https://github.com/ntsd/auto-request-changes-action)

[Auto Request Changes Action Marketplace](https://github.com/marketplace/actions/auto-request-changes)

[Auto Approve Action Repo](https://github.com/hmarr/auto-approve-action)

[Github Action Context](https://docs.github.com/en/actions/learn-github-actions/contexts)