diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..60c6c8a --- /dev/null +++ b/.github/workflows/ci.yml @@ -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 + 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 + 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 diff --git a/README.md b/README.md index fbb271e..078a0e2 100644 --- a/README.md +++ b/README.md @@ -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) diff --git a/action.yml b/action.yml index 3a5ef7d..da38b1d 100644 --- a/action.yml +++ b/action.yml @@ -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' diff --git a/dist/index.js b/dist/index.js index 5873dee..91dd1e5 100644 --- a/dist/index.js +++ b/dist/index.js @@ -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, }); } diff --git a/src/index.js b/src/index.js index 46eab7d..2061cfb 100644 --- a/src/index.js +++ b/src/index.js @@ -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, }); }