Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 74 additions & 0 deletions .github/workflows/close-existing-invalid-prs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
name: Close existing invalid PRs

on:
schedule:
- cron: '0 0 * * *'
workflow_dispatch: {}

permissions:
pull-requests: write

jobs:
close-existing-invalid:
if: github.repository == 'smallfawn/decode_action'
runs-on: ubuntu-latest
steps:
- name: Scan and close invalid PRs
env:
GH_TOKEN: ${{ github.token }}
BASE_REPO: ${{ github.repository }}
run: |
set -euo pipefail

echo "Scanning repository $BASE_REPO for all open PRs..."

# Get all open PR numbers
pr_numbers="$(gh pr list --repo "$BASE_REPO" --state open --json number --jq '.[].number')"

if [ -z "$pr_numbers" ]; then
echo "No open PRs found"
exit 0
fi

INVALID_PATTERN='(^|/)(input|output)\.(js|py)$'

while IFS= read -r pr_number; do
echo "Checking PR #$pr_number"

# Get the head repository full name
head_repo="$(gh api "repos/$BASE_REPO/pulls/$pr_number" --jq '.head.repo.full_name')"

# Only process PRs from forks
if [ "$head_repo" = "$BASE_REPO" ]; then
echo " PR is from a branch in the same repository, skipping"
continue
fi

# Get list of changed files
files="$(gh api --paginate "repos/$BASE_REPO/pulls/$pr_number/files" --jq '.[].filename')"

if [ -z "$files" ]; then
echo " No changed files, skipping"
continue
fi

invalid=1
while IFS= read -r file; do
if ! grep -qE "$INVALID_PATTERN" <<< "$file"; then
echo " Found valid file: $file"
invalid=0
break
fi
done <<< "$files"

if [ "$invalid" -ne 1 ]; then
echo " PR is valid, not closing"
continue
fi

echo " Invalid PR, closing..."
gh pr close "$pr_number" --repo "$BASE_REPO" --comment "Automatically closed: this PR only modifies \`input/output.js\` or \`input/output.py\` files, which is considered invalid according to repository rules."

done <<< "$pr_numbers"

echo "Scan complete"
57 changes: 57 additions & 0 deletions .github/workflows/close-invalid-pr.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
name: Close new invalid PRs

on:
pull_request_target:
types: [opened, synchronize, reopened]

permissions:
pull-requests: write

jobs:
close-invalid-pr:
if: github.repository == 'smallfawn/decode_action'
runs-on: ubuntu-latest
steps:
- name: Check and close invalid PR
env:
GH_TOKEN: ${{ github.token }}
PR_NUMBER: ${{ github.event.pull_request.number }}
HEAD_REPO: ${{ github.event.pull_request.head.repo.full_name }}
BASE_REPO: ${{ github.repository }}
run: |
set -euo pipefail

# Only process PRs from forks
if [ "$HEAD_REPO" = "$BASE_REPO" ]; then
echo "PR is from a branch in the same repository, skipping"
exit 0
fi

# Get list of changed files
files="$(gh api --paginate "repos/$BASE_REPO/pulls/$PR_NUMBER/files" --jq '.[].filename')"

if [ -z "$files" ]; then
echo "PR has no changed files, skipping"
exit 0
fi

# Invalid file pattern: input.js / output.js / input.py / output.py
INVALID_PATTERN='(^|/)(input|output)\.(js|py)$'

invalid=1
while IFS= read -r file; do
if ! grep -qE "$INVALID_PATTERN" <<< "$file"; then
echo "Found valid file: $file"
invalid=0
break
fi
done <<< "$files"

if [ "$invalid" -ne 1 ]; then
echo "PR is valid, not closing"
exit 0
fi

echo "Detected invalid PR: only changes input/output.js or input/output.py"

gh pr close "$PR_NUMBER" --repo "$BASE_REPO" --comment "Automatically closed: this PR only modifies \`input/output.js\` or \`input/output.py\` files, which is considered invalid according to repository rules."
6 changes: 6 additions & 0 deletions .github/workflows/decode.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ on:
push:
branches:
- main
paths:
- 'input.js'
- 'input.py'
- 'package.json'
- 'src/**'
- '.github/workflows/decode.yml'

jobs:
decode:
Expand Down