Skip to content
Closed
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
3 changes: 3 additions & 0 deletions .github/pull_request_template.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
## ⚠️ WARNING: DO NOT OPEN THIS MANUALLY
This repository uses an automated PR flow. Manual PRs will be closed immediately.
Please push your branch to `PR/<unique-topic>` to let the automation create your PR.
59 changes: 59 additions & 0 deletions .github/workflows/auto-pr.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
name: Auto Create or Reopen PR

on:
push:
branches:
- 'PR/*'

jobs:
manage-pr:
runs-on: ubuntu-latest
permissions:
pull-requests: write
contents: read
steps:
- name: Check out repository
uses: actions/checkout@v4

- name: Create or Reopen PR
uses: actions/github-script@v7
with:
script: |
const branchName = context.ref.replace('refs/heads/', '');
const targetBranch = 'public';

// 1. Check if a PR already exists for this branch (open or closed)
const { data: prs } = await github.rest.pulls.list({
owner: context.repo.owner,
repo: context.repo.repo,
head: `${context.repo.owner}:${branchName}`,
state: 'all'
});

if (prs.length > 0) {
const latestPr = prs[0];

// 2. If the PR is closed and was NOT merged, reopen it
if (latestPr.state === 'closed' && !latestPr.merged_at) {
console.log(`Reopening existing PR #${latestPr.number}`);
await github.rest.pulls.update({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: latestPr.number,
state: 'open'
});
} else {
console.log('PR is already open or was previously merged. No action taken.');
}
} else {
// 3. If no PR exists, create a new one
console.log(`Creating new PR for ${branchName}`);
await github.rest.pulls.create({
owner: context.repo.owner,
repo: context.repo.repo,
title: `Auto PR: ${branchName}`,
head: branchName,
base: targetBranch,
body: 'This Pull Request was automatically generated by GitHub Actions.'
});
}
26 changes: 26 additions & 0 deletions .github/workflows/block-manual-pr.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: Enforce Automated PRs

on:
pull_request:
types: [opened]

jobs:
check-author:
runs-on: ubuntu-latest
permissions:
pull-requests: write

steps:
- name: Close Manual PRs
# Adjust the actor check if using a custom GitHub App token instead of the default token
if: github.actor != 'github-actions[bot]'
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
echo "Manual PR detected from user: ${{ github.actor }}"

# 1. Post a comment explaining why the PR is being rejected
gh pr comment ${{ github.event.pull_request.number }} --body "❌ **Manual PRs are not allowed.** Pull requests must be automatically generated by pushing your branch matching the pattern to GitHub."

# 2. Close the PR automatically
gh pr close ${{ github.event.pull_request.number }}
Loading