-
-
Notifications
You must be signed in to change notification settings - Fork 539
75 lines (63 loc) · 2.77 KB
/
pull-requests.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
name: Pull Requests
# Credit: https://github.com/github/docs/blob/main/.github/workflows/notify-when-maintainers-cannot-edit.yaml
# https://github.com/laravel/.github/blob/main/.github/workflows/pull-requests.yml
on:
pull_request_target:
types:
- opened
permissions:
pull-requests: write
jobs:
uneditable:
runs-on: ubuntu-latest
steps:
- uses: actions/github-script@v6
with:
script: |
const repo = context.repo.repo;
const query = `
query($number: Int!) {
repository(owner: "statamic", name: "${repo}") {
pullRequest(number: $number) {
headRepositoryOwner {
login
}
maintainerCanModify
state
}
}
}
`;
const pullNumber = context.issue.number;
const variables = { number: pullNumber };
try {
console.log(`Check for maintainer edit access ...`);
const result = await github.graphql(query, variables);
console.log(JSON.stringify(result, null, 2));
const pullRequest = result.repository.pullRequest;
if (pullRequest.headRepositoryOwner.login === 'statamic') {
console.log('PR owned by statamic');
return;
}
if (pullRequest.state !== 'OPEN') {
console.log('PR has already been closed or merged');
return;
}
if (!pullRequest.maintainerCanModify) {
console.log('PR not owned by statamic and does not have maintainer edits enabled');
await github.rest.issues.createComment({
issue_number: pullNumber,
owner: 'statamic',
repo,
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). Additionally, GitHub doesn't allow maintainer permissions from organization accounts. Please resubmit this PR from a personal GitHub account with maintainer permissions enabled."
});
await github.rest.pulls.update({
pull_number: pullNumber,
owner: 'statamic',
repo,
state: 'closed'
});
}
} catch(e) {
console.log(e);
}