Skip to content

Commit 1c15d08

Browse files
authored
Create pull-requests.yml (#40808)
1 parent 3af82f6 commit 1c15d08

File tree

1 file changed

+64
-0
lines changed

1 file changed

+64
-0
lines changed

.github/workflows/pull-requests.yml

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
name: Pull Requests
2+
3+
# Credit: https://github.com/github/docs/blob/main/.github/workflows/notify-when-maintainers-cannot-edit.yaml
4+
5+
on:
6+
pull_request_target:
7+
types:
8+
- opened
9+
10+
permissions:
11+
pull-requests: write
12+
13+
jobs:
14+
uneditable:
15+
if: github.repository == 'laravel/framework'
16+
runs-on: ubuntu-latest
17+
steps:
18+
- uses: actions/github-script@2b34a689ec86a68d8ab9478298f91d5401337b7d
19+
with:
20+
script: |
21+
const query = `
22+
query($number: Int!) {
23+
repository(owner: "laravel", name: "framework") {
24+
pullRequest(number: $number) {
25+
headRepositoryOwner {
26+
login
27+
}
28+
maintainerCanModify
29+
}
30+
}
31+
}
32+
`;
33+
34+
const pullNumber = context.issue.number;
35+
const variables = { number: pullNumber };
36+
37+
try {
38+
console.log(`Check laravel/framework#${pullNumber} for maintainer edit access ...`);
39+
40+
const result = await github.graphql(query, variables);
41+
42+
console.log(JSON.stringify(result, null, 2));
43+
44+
const pullRequest = result.repository.pullRequest;
45+
46+
if (pullRequest.headRepositoryOwner.login === 'laravel') {
47+
console.log('PR owned by laravel');
48+
49+
return;
50+
}
51+
52+
if (!pullRequest.maintainerCanModify) {
53+
console.log('PR not owned by Laravel and does not have maintainer edits enabled');
54+
55+
await github.issues.createComment({
56+
issue_number: pullNumber,
57+
owner: 'laravel',
58+
repo: 'framework',
59+
body: "Thanks for submitting a PR!\n\nIn order to review and merge PRs most efficiently, we require that all PRs grant maintainer edit access before we review them. For information on how to do this, [see the relevant GitHub documentation](https://docs.github.com/en/github/collaborating-with-pull-requests/working-with-forks/allowing-changes-to-a-pull-request-branch-created-from-a-fork)."
60+
});
61+
}
62+
} catch(e) {
63+
console.log(e);
64+
}

0 commit comments

Comments
 (0)