Skip to content

Commit

Permalink
feat(action): action can now review pull requests (#135)
Browse files Browse the repository at this point in the history
* feat(action): action can now review pull requests

* fix: input name

* fix: fix default upstream repo/owner

* docs: update actions instructions
  • Loading branch information
chingor13 authored Oct 7, 2020
1 parent cf1baf6 commit c90a128
Show file tree
Hide file tree
Showing 3 changed files with 132 additions and 36 deletions.
113 changes: 100 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,6 @@ npm i code-suggester -g

#### Syntax


`code-suggester pr [options] --upstream-repo=<string> --upstream-owner=<string>`

#### Environment Variables
Expand Down Expand Up @@ -237,14 +236,46 @@ Whether or not to attempt forking to a separate repository. Default value is: `t
code-suggester pr -o foo -r bar -d 'description' -t 'title' -m 'message' --git-dir=.
```

## Action

### create a pull request
Opens a GitHub Pull Request against the upstream primary branch with the provided git directory. By default the git directory is the same as the `$GITHUB_WORKSPACE` directory.
### code-suggester review
`code-suggester review` - review an open GitHub Pull Request and suggest changes.

#### Syntax

`pr --upstream-repo=<string> --upstream-owner=<string> --title=<string> --description=<string> --message=<string> [options] `
`code-suggester review --upstream-repo=<string> --upstream-owner=<string> --pull-number=<number> --git-dir=<string>`

#### Environment Variables
#### `ACCESS_TOKEN`
*string* <br>
**Required.** The GitHub access token which has permissions to fork, write to its forked repo and its branches, as well as create Pull Requests on the upstream repository.

#### Options

#### `--upstream-repo, -r`
*string* <br>
**Required.** The repository to create the fork off of.


#### `--upstream-owner, -o`
*string* <br>
**Required.** The owner of the upstream repository.

#### `--pull-number, -p`
*number* <br>
**Required.** The pull request number.

#### `--git-dir`
*string* <br>
**Required.** The path of a git directory

### Example
```
code-suggester pr -o foo -r bar -p 1234 --git-dir=.
```

## Action

### Create a Pull Request
Opens a GitHub Pull Request against the upstream primary branch with the provided git directory. By default the git directory is the same as the `$GITHUB_WORKSPACE` directory.

#### Environment Variables
#### `ACCESS_TOKEN`
Expand All @@ -257,12 +288,10 @@ Opens a GitHub Pull Request against the upstream primary branch with the provide
*string* <br>
**Required.** The repository to create the fork off of.


#### `upstream_owner`
*string* <br>
**Required.** The owner of the upstream repository.


#### `description`
*string* <br>
**Required.** The GitHub Pull Request description.
Expand Down Expand Up @@ -299,7 +328,8 @@ Whether or not maintainers can modify the pull request. Default value is: `true`
*boolean* <br>
Whether or not to attempt forking to a separate repository. Default value is: `true`.

### Example
#### Example

The following example is a `.github/workflows/main.yaml` file in repo `Octocat/HelloWorld`. This would add a LICENSE folder to the root `HelloWorld` repo on every pull request if it is not already there.
```yaml
on:
Expand Down Expand Up @@ -328,6 +358,67 @@ jobs:
git_dir: '.'
```
### Review a Pull Request
Suggests changes against an open GitHub Pull Request with changes in the provided git directory. By default the git directory is the same as the `$GITHUB_WORKSPACE` directory.

#### Environment Variables
#### `ACCESS_TOKEN`
*string* <br>
**Required.** The GitHub access token for the user making the suggested changes. We recommend storing it as a secret in your GitHub repository.

#### Options

#### `upstream_repo`
*string* <br>
**Required.** The repository to create the fork off of.

#### `upstream_owner`
*string* <br>
**Required.** The owner of the upstream repository.

#### `pull_number`
*number* <br>
**Required.** The GitHub Pull Request number.

#### `git_dir`
*string* <br>
**Required.** The path of a git directory. Relative to `$GITHUB_WORKSPACE`.

#### Example

The following example is a `.github/workflows/main.yaml` file in repo `Octocat/HelloWorld`. This would run the go formatter on the code and then create a pull request review suggesting `go fmt` fixes.

```yaml
on:
pull_request_target:
types: [opened, synchronize]
branches:
- master
name: ci
jobs:
add-license:
runs-on: ubuntu-latest
env:
ACCESS_TOKEN: ${{ secrets.GITHUB_TOKEN }}
steps:
- uses: actions/checkout@v2
with:
ref: ${{github.event.pull_request.head.ref}}
repository: ${{github.event.pull_request.head.repo.full_name}}
- name: format
run: go fmt
- uses: googleapis/code-suggester@v1 # takes the changes from git directory
with:
command: review
pull_number: ${{ github.event.pull_request.number }}
git_dir: '.'
```

**Important**: When using `pull_request_target` and `actions/checkout` with the pull
request code, make sure that an external developer cannot override the commands run
from the pull request.

## Supported Node.js Versions

Our client libraries follow the [Node.js release schedule](https://nodejs.org/en/about/releases/).
Expand Down Expand Up @@ -355,14 +446,10 @@ _Legacy Node.js versions are supported as a best effort:_
This library follows [Semantic Versioning](http://semver.org/).




This library is considered to be in **alpha**. This means it is still a
work-in-progress and under active development. Any release is subject to
backwards-incompatible changes at any time.



More Information: [Google Cloud Platform Launch Stages][launch_stages]

[launch_stages]: https://cloud.google.com/terms/launch-stages
Expand Down
16 changes: 7 additions & 9 deletions action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,24 +17,20 @@ author: googleapis
description: An action-wrapper for the npm cli code-suggester. It suggests code to your repository
inputs:
command:
description: 'The command for code-suggester to run'
description: 'The command for code-suggester to run. Can be "pr" or "review"'
required: true
upstream_repo:
description: 'The repository to create the fork off of.'
upstream_owner:
description: 'The owner of the upstream repository.'
description:
description: 'The GitHub Pull Request description.'
required: true
description: 'The GitHub Pull Request description. Required for "pr" command.'
title:
description: 'The GitHub Pull Request title.'
required: true
description: 'The GitHub Pull Request title. Required for "pr" command.'
message:
description: 'The GitHub commit message.'
required: true
description: 'The GitHub commit message. Required for "pr" command.'
branch:
description: 'The GitHub working branch name.'
required: true
description: 'The GitHub working branch name. Required for "pr" command.'
primary:
description: 'The primary upstream branch to open a PR against.'
default: master
Expand All @@ -53,6 +49,8 @@ inputs:
description: >-
Whether or not to attempt forking to a separate repository. Default is true.
default: true
pull_number:
description: Pull Request number to review. Required for "review" command.
runs:
using: docker
image: Dockerfile
39 changes: 25 additions & 14 deletions entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,23 +18,34 @@ set -e

if [[ -z "${INPUT_UPSTREAM_REPO}" ]]
then
INPUT_UPSTREAM_REPO=$(cat ${GITHUB_REPOSITORY} | cut -d/ -f2)
INPUT_UPSTREAM_REPO=$(echo ${GITHUB_REPOSITORY} | cut -d/ -f2)
fi

if [[ -z "${INPUT_UPSTREAM_OWNER}" ]]
then
INPUT_UPSTREAM_OWNER=$(cat ${GITHUB_REPOSITORY} | cut -d/ -f1)
INPUT_UPSTREAM_OWNER=$(echo ${GITHUB_REPOSITORY} | cut -d/ -f1)
fi

code-suggester ${INPUT_COMMAND} \
--upstream-repo="${INPUT_UPSTREAM_REPO}" \
--upstream-owner="${INPUT_UPSTREAM_OWNER}" \
--description="${INPUT_DESCRIPTION}" \
--title="${INPUT_TITLE}" \
--branch="${INPUT_BRANCH}" \
--primary="${INPUT_PRIMARY}" \
--message="${INPUT_MESSAGE}" \
--force="${INPUT_FORCE}" \
--maintainers-can-modify="${INPUT_MAINTAINERS_CAN_MODIFY}" \
--git-dir="${INPUT_GIT_DIR}" \
--fork="${INPUT_FORK}"
case "${INPUT_COMMAND}" in
pr)
code-suggester pr \
--upstream-repo="${INPUT_UPSTREAM_REPO}" \
--upstream-owner="${INPUT_UPSTREAM_OWNER}" \
--description="${INPUT_DESCRIPTION}" \
--title="${INPUT_TITLE}" \
--branch="${INPUT_BRANCH}" \
--primary="${INPUT_PRIMARY}" \
--message="${INPUT_MESSAGE}" \
--force="${INPUT_FORCE}" \
--maintainers-can-modify="${INPUT_MAINTAINERS_CAN_MODIFY}" \
--git-dir="${INPUT_GIT_DIR}" \
--fork="${INPUT_FORK}"
;;
review)
code-suggester review \
--upstream-repo="${INPUT_UPSTREAM_REPO}" \
--upstream-owner="${INPUT_UPSTREAM_OWNER}" \
--pull-number="${INPUT_PULL_NUMBER}" \
--git-dir="${INPUT_GIT_DIR}"
;;
esac

0 comments on commit c90a128

Please sign in to comment.