From f041444cf6eda2d43bf88cb3d75435e712ac4003 Mon Sep 17 00:00:00 2001 From: Georgii Kalashnikov Date: Thu, 11 Jun 2026 22:45:28 +0300 Subject: [PATCH] =?UTF-8?q?fixup!=200|=F0=9F=A7=B1:=20welcome=20aboard?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/pull_request_template.md | 3 ++ .github/workflows/auto-pr.yml | 59 +++++++++++++++++++++++++++ .github/workflows/block-manual-pr.yml | 37 +++++++++++++++++ 3 files changed, 99 insertions(+) create mode 100644 .github/pull_request_template.md create mode 100644 .github/workflows/auto-pr.yml create mode 100644 .github/workflows/block-manual-pr.yml diff --git a/.github/pull_request_template.md b/.github/pull_request_template.md new file mode 100644 index 0000000..34b7c67 --- /dev/null +++ b/.github/pull_request_template.md @@ -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/` to let the automation create your PR. diff --git a/.github/workflows/auto-pr.yml b/.github/workflows/auto-pr.yml new file mode 100644 index 0000000..c1e6d5f --- /dev/null +++ b/.github/workflows/auto-pr.yml @@ -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.' + }); + } diff --git a/.github/workflows/block-manual-pr.yml b/.github/workflows/block-manual-pr.yml new file mode 100644 index 0000000..6222371 --- /dev/null +++ b/.github/workflows/block-manual-pr.yml @@ -0,0 +1,37 @@ +name: Instant Close Manual PRs + +on: + pull_request_target: + types: [opened, reopened] + +jobs: + close-manual: + runs-on: ubuntu-latest + steps: + - name: Check if original author was bot + uses: actions/github-script@v7 + with: + script: | + const pr = context.payload.pull_request; + const originalAuthor = pr.user.login; + const headRef = pr.head.ref; + + if (headRef.startsWith('PR/') && originalAuthor !== 'github-actions[bot]') { + console.log(`Manual PR detected from ${originalAuthor}, closing...`); + + await github.rest.issues.createComment({ + owner: context.repo.owner, + repo: context.repo.repo, + issue_number: pr.number, + body: '❌ Manual PRs are not allowed.' + }); + + await github.rest.pulls.update({ + owner: context.repo.owner, + repo: context.repo.repo, + pull_number: pr.number, + state: 'closed' + }); + } else { + console.log(`Bot PR or non-PR/* branch, allowing reopen`); + }