From d3beb6e370dae0e993901e67cb43c8e64beab2db Mon Sep 17 00:00:00 2001 From: "Nicholas Carrigan (he/him)" Date: Thu, 30 Sep 2021 19:24:59 -0700 Subject: [PATCH] feat(actions): autoclose workflow (#43644) --- .github/workflows/autoclose.yml | 41 +++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 .github/workflows/autoclose.yml diff --git a/.github/workflows/autoclose.yml b/.github/workflows/autoclose.yml new file mode 100644 index 0000000000..0b05340d4c --- /dev/null +++ b/.github/workflows/autoclose.yml @@ -0,0 +1,41 @@ +name: Autoclose +on: + pull_request_target: + branches: + - "main" + paths: + - ".gitignore" + +jobs: + autoclose: + runs-on: ubuntu-latest + steps: + - uses: actions/github-script@v5 + with: + github-token: ${{secrets.GITHUB_TOKEN}} + script: | + const files = await github.rest.pulls.listFiles({ + owner: context.payload.repository.owner.login, + repo: context.payload.repository.name, + pull_number: context.payload.pull_request.number, + }); + if ( + files.data.length === 1 && + files.data[0].filename === ".gitignore" && + files.data[0].patch === + "@@ -63,7 +63,6 @@ $RECYCLE.BIN/\n # Icon must end with two \\r\n Icon\n \n-\n # Thumbnails\n ._*\n " + ) { + core.setFailed("Invalid PR detected."); + github.rest.issues.createComment({ + issue_number: context.issue.number, + owner: context.repo.owner, + repo: context.repo.repo, + body: "Thank you for opening this pull request.\n\nThis is a standard message notifying you that we've reviewed your pull request and have decided not to merge it. We would welcome future pull requests from you.\n\nThank you and happy coding.", + }); + await github.rest.pulls.update({ + owner: context.payload.repository.owner.login, + repo: context.payload.repository.name, + pull_number: context.payload.pull_request.number, + state: "closed" + }); + }