-
Notifications
You must be signed in to change notification settings - Fork 67.1k
45 lines (37 loc) · 1.56 KB
/
check-for-spammy-prs.yml
File metadata and controls
45 lines (37 loc) · 1.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
name: Close certain spammy PRs
# **What it does**: This action closes spammy pull requests in the open-source repository that have the title 'Revert "Repo sync" or contain an empty commit.
# **Why we have it**: We get lots of spam in the open-source repository.
# **Who does it impact**: Open-source contributors.
on:
# Needed in lieu of `pull_request` so that PRs from a fork can be
# closed when marked as invalid.
pull_request_target:
types: [opened]
permissions:
contents: read
issues: write
pull-requests: write
jobs:
close_empty_pr:
if: github.repository == 'github/docs'
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v2
- name: Get PR details
id: pr_details
uses: octokit/request-action@v2
with:
route: GET /repos/${{ github.repository }}/pulls/${{ github.event.pull_request.number }}
mediaType: '{"accept":"application/vnd.github.v3+json"}'
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Save output to a file and then to environment
run: |
echo "${{ steps.pr_details.outputs.data }}" > pr_details.json
echo "files_count=$(jq --arg pr_details.json)" >> $GITHUB_ENV
- name: Add invalid label to PR if no files are changed
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
if: github.event.pull_request.title == 'Revert "Repo sync"' || env.files_count.changed_files == '0'
run: gh issue edit "${{ github.event.pull_request.number }}" --add-label "invalid"