Skip to content

Commit

Permalink
Merge pull request #1 from peter-evans/ci
Browse files Browse the repository at this point in the history
Add ci workflow
  • Loading branch information
peter-evans authored May 2, 2020
2 parents d4ced21 + a8d089c commit b2e8a5e
Show file tree
Hide file tree
Showing 5 changed files with 144 additions and 7 deletions.
91 changes: 91 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
name: CI
on:
push:
branches: [master]
pull_request:
branches: [master]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v1
with:
node-version: 12.x
- run: npm ci
- run: npm run test
- run: npm run package
- uses: actions/upload-artifact@v2
with:
name: dist
path: dist

test:
needs: [build]
runs-on: ubuntu-latest
strategy:
matrix:
target: [built, committed]
steps:
- if: github.event_name == 'push'
uses: actions/checkout@v2
- if: github.event_name == 'pull_request'
uses: actions/checkout@v2
with:
ref: ${{ github.head_ref }}
- if: matrix.target == 'built'
uses: actions/download-artifact@v2
with:
name: dist
path: dist

- name: Create change
run: date +%s > report.txt

- name: Create Pull Request
id: cpr
uses: peter-evans/create-pull-request@v2
with:
commit-message: '[CI] test ${{ matrix.target }}'
committer: GitHub <[email protected]>
author: ${{ github.actor }} <${{ github.actor }}@users.noreply.github.com>
title: '[CI] test ${{ matrix.target }}'
body: |
- CI test case for target '${{ matrix.target }}'
Auto-generated by [create-pull-request][1]
[1]: https://github.com/peter-evans/create-pull-request
branch: ci-test-${{ matrix.target }}

- name: Close Pull
uses: ./
with:
pull-request-number: ${{ steps.cpr.outputs.pr_number }}
comment: '[CI] test ${{ matrix.target }}'
delete-branch: true

package:
if: github.event_name == 'push' && github.ref == 'refs/heads/master'
needs: [test]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/download-artifact@v2
with:
name: dist
path: dist
- name: Create Pull Request
uses: peter-evans/create-pull-request@v2
with:
commit-message: Update distribution
committer: GitHub <[email protected]>
author: ${{ github.actor }} <${{ github.actor }}@users.noreply.github.com>
title: Update distribution
body: |
- Updates the distribution for changes on `master`
Auto-generated by [create-pull-request][1]
[1]: https://github.com/peter-evans/create-pull-request
branch: update-distribution
50 changes: 48 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,56 @@
# Close Pull Request
# Close Pull
[![GitHub Marketplace](https://img.shields.io/badge/Marketplace-Close%20Pull-blue.svg?colorA=24292e&colorB=0366d6&style=flat&longCache=true&logo=data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAA4AAAAOCAYAAAAfSC3RAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAAM6wAADOsB5dZE0gAAABl0RVh0U29mdHdhcmUAd3d3Lmlua3NjYXBlLm9yZ5vuPBoAAAERSURBVCiRhZG/SsMxFEZPfsVJ61jbxaF0cRQRcRJ9hlYn30IHN/+9iquDCOIsblIrOjqKgy5aKoJQj4O3EEtbPwhJbr6Te28CmdSKeqzeqr0YbfVIrTBKakvtOl5dtTkK+v4HfA9PEyBFCY9AGVgCBLaBp1jPAyfAJ/AAdIEG0dNAiyP7+K1qIfMdonZic6+WJoBJvQlvuwDqcXadUuqPA1NKAlexbRTAIMvMOCjTbMwl1LtI/6KWJ5Q6rT6Ht1MA58AX8Apcqqt5r2qhrgAXQC3CZ6i1+KMd9TRu3MvA3aH/fFPnBodb6oe6HM8+lYHrGdRXW8M9bMZtPXUji69lmf5Cmamq7quNLFZXD9Rq7v0Bpc1o/tp0fisAAAAASUVORK5CYII=)](https://github.com/marketplace/actions/close-pull)

A GitHub action to close a pull request and optionally delete its branch.

## Usage

### Close a pull request and delete its branch

```yml
- name: Close Pull Request
- name: Close Pull
uses: peter-evans/close-pull@v1
with:
pull-request-number: 1
comment: Auto-closing pull request
delete-branch: true
```
### Reject all pull requests to a repository
```yml
on:
pull_request:
types: [opened]
jobs:
closePullRequest:
runs-on: ubuntu-latest
steps:
- name: Close Pull
uses: peter-evans/close-pull@v1
with:
comment: |
Sorry. Pull requests are not accepted for this repository.
Auto-closing this pull request.
```
### Action inputs
| Name | Description | Default |
| --- | --- | --- |
| `token` | `GITHUB_TOKEN` or a `repo` scoped [PAT](https://help.github.com/en/github/authenticating-to-github/creating-a-personal-access-token-for-the-command-line). | `GITHUB_TOKEN` |
| `repository` | The GitHub repository containing the pull request. | Current repository |
| `pull-request-number` | The number of the pull request to close. | `github.event.number` |
| `comment` | A comment to make on the pull request before closing. | |
| `delete-branch` | Delete the pull request branch. | `false` |

Note: Deleting branches will fail silently for pull requests from forks.

### Accessing pull requests in other repositories

You can close pull requests in another repository by using a [PAT](https://help.github.com/en/github/authenticating-to-github/creating-a-personal-access-token-for-the-command-line) instead of `GITHUB_TOKEN`.
The user associated with the PAT must have write access to the repository.

## License

[MIT](LICENSE)
2 changes: 1 addition & 1 deletion action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ inputs:
description: 'GitHub auth token'
default: ${{ github.token }}
repository:
description: 'The target GitHub repository'
description: 'The GitHub repository containing the pull request'
default: ${{ github.repository }}
pull-request-number:
description: 'The number of the pull request to close'
Expand Down
4 changes: 2 additions & 2 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8623,10 +8623,10 @@ async function run() {

if (inputs.comment && inputs.comment.length > 0) {
core.info("Adding a comment before closing the pull request");
await octokit.pulls.createComment({
await octokit.issues.createComment({
owner: repo[0],
repo: repo[1],
pull_number: inputs.pullRequestNumber,
issue_number: inputs.pullRequestNumber,
body: inputs.comment,
});
}
Expand Down
4 changes: 2 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ async function run() {

if (inputs.comment && inputs.comment.length > 0) {
core.info("Adding a comment before closing the pull request");
await octokit.pulls.createComment({
await octokit.issues.createComment({
owner: repo[0],
repo: repo[1],
pull_number: inputs.pullRequestNumber,
issue_number: inputs.pullRequestNumber,
body: inputs.comment,
});
}
Expand Down

0 comments on commit b2e8a5e

Please sign in to comment.