Skip to content

Commit

Permalink
Rebuild action
Browse files Browse the repository at this point in the history
migrate: auto approve to auto request changes

docs: update readme.md

fix: REQUEST_CHANGES required body

chore: rebuild action

feat: add comment body

docs: update readme.md

docs: update readme.md

docs: update readme.md

docs: update readme.md
  • Loading branch information
roryabraham authored and ntsd committed Nov 20, 2021
1 parent b11635b commit 88bb76a
Show file tree
Hide file tree
Showing 8 changed files with 162 additions and 140 deletions.
77 changes: 44 additions & 33 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,78 +1,89 @@
# Auto Approve GitHub Action
# Auto Request Changes GitHub Action

**Name:** `hmarr/auto-approve-action`
This action is a fork from [hmarr/auto-approve-action](https://github.com/hmarr/auto-approve-action)

Automatically approve GitHub pull requests. The `GITHUB_TOKEN` secret must be provided as the `github-token` input for the action to work.
**Name:** `ntsd/auto-request-changes-action`

**Important:** use v2.0.0 or later, as v1 was designed for the initial GitHub Actions beta, and no longer works.
Automatically request changes GitHub pull requests. The `GITHUB_TOKEN` secret will default provided as the `github-token` input for the action to work. otherwise you can add a token to `github-token` input.

## Why?

Because sometimes you want to automate create request changes review. for example, create a request changes review when a lint or testing workflow is failed.

## Usage instructions

Create a workflow file (e.g. `.github/workflows/auto-approve.yml`) that contains a step that `uses: hmarr/auto-approve-action@v2`. Here's an example workflow file:
Create a workflow file (e.g. `.github/workflows/auto-request-changes.yml`) that contains a step that `uses: ntsd/auto-request-changes-action@v2`. Here's an example workflow file:

for all github action contexts check <https://docs.github.com/en/actions/learn-github-actions/contexts>

```yaml
name: Auto approve
name: Auto request changes
on: pull_request_target

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: hmarr/auto-approve-action@v2
with:
github-token: "${{ secrets.GITHUB_TOKEN }}"
- uses: ntsd/auto-request-changes-action@v2
with:
github-token: "${{ secrets.GITHUB_TOKEN }}"
comment-body: "custom comment body"
```
Combine with an `if` can only auto-request-changes with only failure workflow

```yaml
name: Auto request changes
Combine with an `if` clause to only auto-approve certain users. For example, to auto-approve [Dependabot][dependabot] pull requests, use:
on: pull_request_target
jobs:
auto-request-changes:
runs-on: ubuntu-latest
steps:
- uses: ntsd/auto-request-changes-action@v2
if: ${{ github.event.pull_request && failure() }}
```

Using with [auto-approve-action](https://github.com/hmarr/auto-approve-action) to approve when the job success.

```yaml
name: Auto approve
name: Auto request changes and approve
on:
pull_request_target
on: pull_request_target
jobs:
auto-approve:
auto-review:
runs-on: ubuntu-latest
steps:
- uses: hmarr/auto-approve-action@v2
if: github.actor == 'dependabot[bot]' || github.actor == 'dependabot-preview[bot]'
with:
github-token: "${{ secrets.GITHUB_TOKEN }}"
- uses: ntsd/auto-request-changes-action@v2
if: ${{ github.event.pull_request && failure() }}
- uses: hmarr/auto-approve-action@v2
if: ${{ github.event.pull_request && success() }}
with:
github-token: "${{ secrets.GITHUB_TOKEN }}"
```

If you want to use this action from a workflow file that doesn't run on the `pull_request` or `pull_request_target` events, use the `pull-request-number` input:

```yaml
name: Auto approve
name: Auto request changes
on:
workflow_dispatch:
inputs: pullRequestNumber
description: Pull request number to auto-approve
description: Pull request number to auto-request-changes
required: false
jobs:
auto-approve:
auto-request-changes:
runs-on: ubuntu-latest
steps:
- uses: hmarr/auto-approve-action@v2
- uses: ntsd/auto-request-changes-action@v2
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
pull-request-number: ${{ github.event.inputs.pullRequestNumber }}
```

## Why?

GitHub lets you prevent merges of unapproved pull requests. However, it's occasionally useful to selectively circumvent this restriction - for instance, some people want Dependabot's automated pull requests to not require approval.

[dependabot]: https://github.com/marketplace/dependabot

## Code owners

If you're using a [CODEOWNERS file](https://docs.github.com/en/github/creating-cloning-and-archiving-repositories/about-code-owners), you'll need to give this action a personal access token for a user listed as a code owner. Rather than using a real user's personal access token, you're probably better off creating a dedicated bot user, and adding it to a team which you assign as the code owner. That way you can restrict the bot user's permissions as much as possible, and your workflow won't break when people leave the team.

## Development and release process

Each major version corresponds to a branch (e.g. `v1`, `v2`). The latest major version (`v2` at the time of writing) is the repository's default branch. Releases are tagged with semver-style version numbers (e.g. `v1.2.3`).
23 changes: 14 additions & 9 deletions action.yml
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
name: 'Auto Approve'
description: 'Automatically approve pull requests'
name: "Auto Request Changes"
description: "Automatically request changes pull requests"
branding:
icon: 'check-circle'
color: 'green'
icon: "check-circle"
color: "green"
inputs:
github-token:
description: 'The GITHUB_TOKEN secret'
required: true
description: "The GITHUB_TOKEN secret"
default: ${{ github.token }}
required: false
comment-body:
description: "Comment body to show when create request changes"
default: "Some actions are not successful, please fix it."
required: false
pull-request-number:
description: '(optional) The ID of a pull request to auto-approve. By default, this action tries to use the pull_request event payload.'
description: "(optional) The ID of a pull request to auto-request-changes. By default, this action tries to use the pull_request event payload."
required: false
runs:
using: 'node12'
main: 'dist/index.js'
using: "node12"
main: "dist/index.js"
126 changes: 64 additions & 62 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5828,7 +5828,62 @@ function wrappy (fn, cb) {

/***/ }),

/***/ 609:
/***/ 399:
/***/ (function(__unused_webpack_module, exports, __nccwpck_require__) {

"use strict";

var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", ({ value: true }));
const core = __importStar(__nccwpck_require__(186));
const github = __importStar(__nccwpck_require__(438));
const request_changes_1 = __nccwpck_require__(45);
function run() {
return __awaiter(this, void 0, void 0, function* () {
const token = core.getInput("github-token", { required: true });
const commentBody = core.getInput("comment-body", { required: true });
const prNumber = parseInt(core.getInput("pull-request-number"), 10);
if (!Number.isNaN(prNumber)) {
yield request_changes_1.requestChanges(token, github.context, commentBody, prNumber);
}
else {
yield request_changes_1.requestChanges(token, github.context, commentBody);
}
});
}
run();


/***/ }),

/***/ 45:
/***/ (function(__unused_webpack_module, exports, __nccwpck_require__) {

"use strict";
Expand Down Expand Up @@ -5862,11 +5917,11 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
});
};
Object.defineProperty(exports, "__esModule", ({ value: true }));
exports.approve = void 0;
exports.requestChanges = void 0;
const core = __importStar(__nccwpck_require__(186));
const github = __importStar(__nccwpck_require__(438));
const request_error_1 = __nccwpck_require__(537);
function approve(token, context, prNumber) {
function requestChanges(token, context, commentBody, prNumber) {
var _a;
return __awaiter(this, void 0, void 0, function* () {
if (!prNumber) {
Expand All @@ -5878,15 +5933,16 @@ function approve(token, context, prNumber) {
return;
}
const client = github.getOctokit(token);
core.info(`Creating approving review for pull request #${prNumber}`);
core.info(`Creating request changes review for pull request #${prNumber}`);
try {
yield client.pulls.createReview({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: prNumber,
event: "APPROVE",
event: "REQUEST_CHANGES",
body: commentBody,
});
core.info(`Approved pull request #${prNumber}`);
core.info(`Requested changes pull request #${prNumber}`);
}
catch (error) {
if (error instanceof request_error_1.RequestError) {
Expand All @@ -5906,7 +5962,7 @@ function approve(token, context, prNumber) {
"or review the scopes assigned to your personal access token.");
break;
case 422:
core.setFailed(`${error.message}. This typically happens when you try to approve the pull ` +
core.setFailed(`${error.message}. This typically happens when you try to request changes the pull ` +
"request with the same user account that created the pull request. Try using " +
"the built-in `${{ secrets.GITHUB_TOKEN }}` token, or if you're using a personal " +
"access token, use one that belongs to a dedicated bot account.");
Expand All @@ -5921,61 +5977,7 @@ function approve(token, context, prNumber) {
}
});
}
exports.approve = approve;


/***/ }),

/***/ 399:
/***/ (function(__unused_webpack_module, exports, __nccwpck_require__) {

"use strict";

var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", ({ value: true }));
const core = __importStar(__nccwpck_require__(186));
const github = __importStar(__nccwpck_require__(438));
const approve_1 = __nccwpck_require__(609);
function run() {
return __awaiter(this, void 0, void 0, function* () {
const token = core.getInput("github-token", { required: true });
const prNumber = parseInt(core.getInput("pull-request-number"), 10);
if (Number.isNaN(prNumber)) {
yield approve_1.approve(token, github.context, prNumber);
}
else {
yield approve_1.approve(token, github.context);
}
});
}
run();
exports.requestChanges = requestChanges;


/***/ }),
Expand Down
7 changes: 4 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 6 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "auto-approve-action",
"name": "auto-request-changes-action",
"version": "2.1.0",
"description": "Automatically approve pull requests",
"description": "Automatically request changes pull requests",
"main": "dist/main.ts",
"scripts": {
"build": "ncc build src/main.ts",
Expand All @@ -12,17 +12,17 @@
},
"repository": {
"type": "git",
"url": "git+https://github.com/hmarr/auto-approve-action.git"
"url": "git+https://github.com/ntsd/auto-request-changes-action.git"
},
"keywords": [
"actions"
],
"author": "hmarr",
"author": "ntsd",
"license": "MIT",
"bugs": {
"url": "https://github.com/hmarr/auto-approve-action/issues"
"url": "https://github.com/ntsd/auto-request-changes-action/issues"
},
"homepage": "https://github.com/hmarr/auto-approve-action#readme",
"homepage": "https://github.com/ntsd/auto-request-changes-action#readme",
"dependencies": {
"@actions/core": "^1.2.0",
"@actions/github": "^4.0.0"
Expand Down
7 changes: 4 additions & 3 deletions src/main.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
import * as core from "@actions/core";
import * as github from "@actions/github";
import { approve } from "./approve";
import { requestChanges } from "./request-changes";

async function run() {
const token = core.getInput("github-token", { required: true });
const commentBody = core.getInput("comment-body", { required: true });
const prNumber: number = parseInt(core.getInput("pull-request-number"), 10);
if (!Number.isNaN(prNumber)) {
await approve(token, github.context, prNumber);
await requestChanges(token, github.context, commentBody, prNumber);
} else {
await approve(token, github.context);
await requestChanges(token, github.context, commentBody);
}
}

Expand Down
Loading

0 comments on commit 88bb76a

Please sign in to comment.