|
| 1 | +<?php |
| 2 | + |
| 3 | +if ('cli' !== PHP_SAPI) { |
| 4 | + echo "This script can only be run from the command line.\n"; |
| 5 | + exit(1); |
| 6 | +} |
| 7 | + |
| 8 | +$mainRepo = 'https://github.com/symfony/polyfill'; |
| 9 | +exec('find src/ -name composer.json -not -path "src/Xml/*"', $packages); |
| 10 | + |
| 11 | +foreach ($packages as $package) { |
| 12 | + $package = dirname($package); |
| 13 | + $c = file_get_contents($package.'/.gitattributes'); |
| 14 | + $c = preg_replace('{^/\.git.*+\n}m', '', $c); |
| 15 | + $c .= "/.git* export-ignore\n"; |
| 16 | + file_put_contents($package.'/.gitattributes', $c); |
| 17 | + |
| 18 | + |
| 19 | + @mkdir($package.'/.github'); |
| 20 | + file_put_contents($package.'/.github/PULL_REQUEST_TEMPLATE.md', <<<EOTXT |
| 21 | + Please do not submit any Pull Requests here. They will be closed. |
| 22 | + --- |
| 23 | +
|
| 24 | + Please submit your PR here instead: |
| 25 | + {$mainRepo} |
| 26 | +
|
| 27 | + This repository is what we call a "subtree split": a read-only subset of that main repository. |
| 28 | + We're looking forward to your PR there! |
| 29 | +
|
| 30 | + EOTXT |
| 31 | + ); |
| 32 | + |
| 33 | + @mkdir($package.'/.github/workflows'); |
| 34 | + file_put_contents($package.'/.github/workflows/check-subtree-split.yml', <<<EOTXT |
| 35 | + name: Check subtree split |
| 36 | + on: |
| 37 | + pull_request_target: |
| 38 | + jobs: |
| 39 | + close-pull-request: |
| 40 | + runs-on: ubuntu-latest |
| 41 | + steps: |
| 42 | + - name: Close pull request |
| 43 | + uses: actions/github-script@v6 |
| 44 | + with: |
| 45 | + script: | |
| 46 | + if (context.repo.owner === "symfony") { |
| 47 | + github.rest.issues.createComment({ |
| 48 | + owner: "symfony", |
| 49 | + repo: context.repo.repo, |
| 50 | + issue_number: context.issue.number, |
| 51 | + body: ` |
| 52 | + Thanks for your Pull Request! We love contributions. |
| 53 | +
|
| 54 | + However, you should instead open your PR on the main repository: |
| 55 | + {$mainRepo} |
| 56 | +
|
| 57 | + This repository is what we call a "subtree split": a read-only subset of that main repository. |
| 58 | + We're looking forward to your PR there! |
| 59 | + ` |
| 60 | + }); |
| 61 | + github.rest.pulls.update({ |
| 62 | + owner: "symfony", |
| 63 | + repo: context.repo.repo, |
| 64 | + pull_number: context.issue.number, |
| 65 | + state: "closed" |
| 66 | + }); |
| 67 | + } |
| 68 | +
|
| 69 | + EOTXT |
| 70 | + ); |
| 71 | +} |
0 commit comments