Skip to content

Commit

Permalink
Auto-close PRs on subtree-splits
Browse files Browse the repository at this point in the history
  • Loading branch information
kbond committed Apr 18, 2024
1 parent ad93431 commit 2f03eb6
Show file tree
Hide file tree
Showing 26 changed files with 395 additions and 0 deletions.
65 changes: 65 additions & 0 deletions .github/sync-packages.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
<?php

if ('cli' !== PHP_SAPI) {
echo "This script can only be run from the command line.\n";
exit(1);
}

$mainRepo = 'https://github.com/twigphp/Twig';
exec('find extra/ -name composer.json', $packages);

foreach ($packages as $package) {
$package = dirname($package);
$c = file_get_contents($package.'/.gitattributes');
$c = preg_replace('{^/\.git.*+\n}m', '', $c);
$c .= "/.git* export-ignore\n";
file_put_contents($package.'/.gitattributes', $c);


@mkdir($package.'/.github');
file_put_contents($package.'/.github/PULL_REQUEST_TEMPLATE.md', <<<EOTXT
Please do not submit any Pull Requests here. They will be closed.
---
Please submit your PR here instead:
{$mainRepo}
This repository is what we call a "subtree split": a read-only subset of that main repository.
We're looking forward to your PR there!
EOTXT
);

@mkdir($package.'/.github/workflows');
file_put_contents($package.'/.github/workflows/check-subtree-split.yml', <<<EOTXT
name: Check subtree split
on:
pull_request_target:
jobs:
close-pull-request:
runs-on: ubuntu-latest
steps:
- name: Close pull request
uses: actions/github-script@v6
with:
script: |
if (context.repo.owner === "twigphp") {
github.rest.issues.createComment({
owner: "twigphp",
repo: context.repo.repo,
issue_number: context.issue.number,
body: `
Thanks for your Pull Request! We love contributions.
However, you should instead open your PR on the main repository:
{$mainRepo}
This repository is what we call a "subtree split": a read-only subset of that main repository.
We're looking forward to your PR there!
`
});
github.rest.pulls.update({
owner: "twigphp",
repo: context.repo.repo,
pull_number: context.issue.number,
state: "closed"
});
}
EOTXT
);
}
26 changes: 26 additions & 0 deletions .github/workflows/package-tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: Verify Packages

on:
pull_request:
paths:
- extra/**

permissions:
contents: read

jobs:
verify:
name: Verify Packages
runs-on: Ubuntu-20.04
steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Fetch branch from where the PR started
run: git fetch --no-tags --prune --depth=1 origin +refs/heads/*:refs/remotes/origin/*

- name: Verify subtree-splits are auto-closed
run: |
php .github/sync-packages.php
git add extra/
git diff --staged --exit-code || (echo '::error::Please run "php .github/sync-packages.php".' && exit 1)
1 change: 1 addition & 0 deletions extra/cache-extra/.gitattributes
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
/Tests export-ignore
/phpunit.xml.dist export-ignore
/.git* export-ignore
6 changes: 6 additions & 0 deletions extra/cache-extra/.github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Please do not submit any Pull Requests here. They will be closed.
---
Please submit your PR here instead:
https://github.com/twigphp/Twig
This repository is what we call a "subtree split": a read-only subset of that main repository.
We're looking forward to your PR there!
31 changes: 31 additions & 0 deletions extra/cache-extra/.github/workflows/check-subtree-split.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: Check subtree split
on:
pull_request_target:
jobs:
close-pull-request:
runs-on: ubuntu-latest
steps:
- name: Close pull request
uses: actions/github-script@v6
with:
script: |
if (context.repo.owner === "twigphp") {
github.rest.issues.createComment({
owner: "twigphp",
repo: context.repo.repo,
issue_number: context.issue.number,
body: `
Thanks for your Pull Request! We love contributions.
However, you should instead open your PR on the main repository:
https://github.com/twigphp/Twig
This repository is what we call a "subtree split": a read-only subset of that main repository.
We're looking forward to your PR there!
`
});
github.rest.pulls.update({
owner: "twigphp",
repo: context.repo.repo,
pull_number: context.issue.number,
state: "closed"
});
}
1 change: 1 addition & 0 deletions extra/cssinliner-extra/.gitattributes
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
/Tests export-ignore
/phpunit.xml.dist export-ignore
/.git* export-ignore
6 changes: 6 additions & 0 deletions extra/cssinliner-extra/.github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Please do not submit any Pull Requests here. They will be closed.
---
Please submit your PR here instead:
https://github.com/twigphp/Twig
This repository is what we call a "subtree split": a read-only subset of that main repository.
We're looking forward to your PR there!
31 changes: 31 additions & 0 deletions extra/cssinliner-extra/.github/workflows/check-subtree-split.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: Check subtree split
on:
pull_request_target:
jobs:
close-pull-request:
runs-on: ubuntu-latest
steps:
- name: Close pull request
uses: actions/github-script@v6
with:
script: |
if (context.repo.owner === "twigphp") {
github.rest.issues.createComment({
owner: "twigphp",
repo: context.repo.repo,
issue_number: context.issue.number,
body: `
Thanks for your Pull Request! We love contributions.
However, you should instead open your PR on the main repository:
https://github.com/twigphp/Twig
This repository is what we call a "subtree split": a read-only subset of that main repository.
We're looking forward to your PR there!
`
});
github.rest.pulls.update({
owner: "twigphp",
repo: context.repo.repo,
pull_number: context.issue.number,
state: "closed"
});
}
1 change: 1 addition & 0 deletions extra/html-extra/.gitattributes
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
/Tests export-ignore
/phpunit.xml.dist export-ignore
/.git* export-ignore
6 changes: 6 additions & 0 deletions extra/html-extra/.github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Please do not submit any Pull Requests here. They will be closed.
---
Please submit your PR here instead:
https://github.com/twigphp/Twig
This repository is what we call a "subtree split": a read-only subset of that main repository.
We're looking forward to your PR there!
31 changes: 31 additions & 0 deletions extra/html-extra/.github/workflows/check-subtree-split.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: Check subtree split
on:
pull_request_target:
jobs:
close-pull-request:
runs-on: ubuntu-latest
steps:
- name: Close pull request
uses: actions/github-script@v6
with:
script: |
if (context.repo.owner === "twigphp") {
github.rest.issues.createComment({
owner: "twigphp",
repo: context.repo.repo,
issue_number: context.issue.number,
body: `
Thanks for your Pull Request! We love contributions.
However, you should instead open your PR on the main repository:
https://github.com/twigphp/Twig
This repository is what we call a "subtree split": a read-only subset of that main repository.
We're looking forward to your PR there!
`
});
github.rest.pulls.update({
owner: "twigphp",
repo: context.repo.repo,
pull_number: context.issue.number,
state: "closed"
});
}
1 change: 1 addition & 0 deletions extra/inky-extra/.gitattributes
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
/Tests export-ignore
/phpunit.xml.dist export-ignore
/.git* export-ignore
6 changes: 6 additions & 0 deletions extra/inky-extra/.github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Please do not submit any Pull Requests here. They will be closed.
---
Please submit your PR here instead:
https://github.com/twigphp/Twig
This repository is what we call a "subtree split": a read-only subset of that main repository.
We're looking forward to your PR there!
31 changes: 31 additions & 0 deletions extra/inky-extra/.github/workflows/check-subtree-split.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: Check subtree split
on:
pull_request_target:
jobs:
close-pull-request:
runs-on: ubuntu-latest
steps:
- name: Close pull request
uses: actions/github-script@v6
with:
script: |
if (context.repo.owner === "twigphp") {
github.rest.issues.createComment({
owner: "twigphp",
repo: context.repo.repo,
issue_number: context.issue.number,
body: `
Thanks for your Pull Request! We love contributions.
However, you should instead open your PR on the main repository:
https://github.com/twigphp/Twig
This repository is what we call a "subtree split": a read-only subset of that main repository.
We're looking forward to your PR there!
`
});
github.rest.pulls.update({
owner: "twigphp",
repo: context.repo.repo,
pull_number: context.issue.number,
state: "closed"
});
}
1 change: 1 addition & 0 deletions extra/intl-extra/.gitattributes
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
/Tests export-ignore
/phpunit.xml.dist export-ignore
/.git* export-ignore
6 changes: 6 additions & 0 deletions extra/intl-extra/.github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Please do not submit any Pull Requests here. They will be closed.
---
Please submit your PR here instead:
https://github.com/twigphp/Twig
This repository is what we call a "subtree split": a read-only subset of that main repository.
We're looking forward to your PR there!
31 changes: 31 additions & 0 deletions extra/intl-extra/.github/workflows/check-subtree-split.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: Check subtree split
on:
pull_request_target:
jobs:
close-pull-request:
runs-on: ubuntu-latest
steps:
- name: Close pull request
uses: actions/github-script@v6
with:
script: |
if (context.repo.owner === "twigphp") {
github.rest.issues.createComment({
owner: "twigphp",
repo: context.repo.repo,
issue_number: context.issue.number,
body: `
Thanks for your Pull Request! We love contributions.
However, you should instead open your PR on the main repository:
https://github.com/twigphp/Twig
This repository is what we call a "subtree split": a read-only subset of that main repository.
We're looking forward to your PR there!
`
});
github.rest.pulls.update({
owner: "twigphp",
repo: context.repo.repo,
pull_number: context.issue.number,
state: "closed"
});
}
1 change: 1 addition & 0 deletions extra/markdown-extra/.gitattributes
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
/Tests export-ignore
/phpunit.xml.dist export-ignore
/.git* export-ignore
6 changes: 6 additions & 0 deletions extra/markdown-extra/.github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Please do not submit any Pull Requests here. They will be closed.
---
Please submit your PR here instead:
https://github.com/twigphp/Twig
This repository is what we call a "subtree split": a read-only subset of that main repository.
We're looking forward to your PR there!
31 changes: 31 additions & 0 deletions extra/markdown-extra/.github/workflows/check-subtree-split.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: Check subtree split
on:
pull_request_target:
jobs:
close-pull-request:
runs-on: ubuntu-latest
steps:
- name: Close pull request
uses: actions/github-script@v6
with:
script: |
if (context.repo.owner === "twigphp") {
github.rest.issues.createComment({
owner: "twigphp",
repo: context.repo.repo,
issue_number: context.issue.number,
body: `
Thanks for your Pull Request! We love contributions.
However, you should instead open your PR on the main repository:
https://github.com/twigphp/Twig
This repository is what we call a "subtree split": a read-only subset of that main repository.
We're looking forward to your PR there!
`
});
github.rest.pulls.update({
owner: "twigphp",
repo: context.repo.repo,
pull_number: context.issue.number,
state: "closed"
});
}
1 change: 1 addition & 0 deletions extra/string-extra/.gitattributes
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
/Tests export-ignore
/phpunit.xml.dist export-ignore
/.git* export-ignore
6 changes: 6 additions & 0 deletions extra/string-extra/.github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Please do not submit any Pull Requests here. They will be closed.
---
Please submit your PR here instead:
https://github.com/twigphp/Twig
This repository is what we call a "subtree split": a read-only subset of that main repository.
We're looking forward to your PR there!

0 comments on commit 2f03eb6

Please sign in to comment.