Skip to content

Commit 75474c7

Browse files
subatoiCopilotheiskr
authored
Add conditions to close certain spammy PRs in OS repo (#54752)
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Co-authored-by: Kevin Heis <heiskr@users.noreply.github.com>
1 parent 48438fc commit 75474c7

3 files changed

Lines changed: 47 additions & 2 deletions

File tree

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

.github/workflows/close-on-invalid-label.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ permissions:
1919

2020
jobs:
2121
close-if-invalid:
22-
if: github.repository == 'github/docs' && (github.event.label.name == 'invalid' || github.event.pull_request.title == 'Revert "Repo sync"')
22+
if: github.repository == 'github/docs' && github.event.label.name == 'invalid'
2323
runs-on: ubuntu-latest
2424

2525
steps:

src/workflows/tests/actions-workflows.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { flatten } from 'flat'
88
import { chain, get } from 'lodash-es'
99

1010
const githubOwnedActionsRegex =
11-
/^(actions\/(cache|checkout|download-artifact|upload-artifact)@v\d+(\.\d+)*)$/
11+
/^(actions\/(cache|checkout|download-artifact|upload-artifact)@v\d+(\.\d+)*)|(octokit\/(request-action)@v\d+(\.\d+)*)$/
1212
const actionHashRegexp = /^[A-Za-z0-9-/]+@[0-9a-f]{40}$/
1313
const checkoutRegexp = /^[actions/checkout]+@(v\d+(\.\d+)*|[0-9a-f]{40})$/
1414
const permissionsRegexp = /(read|write)/

0 commit comments

Comments
 (0)