-
Notifications
You must be signed in to change notification settings - Fork 0
136 lines (105 loc) · 4.58 KB
/
pull-requests.yml
File metadata and controls
136 lines (105 loc) · 4.58 KB
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
name: pull requests
# Credit: https://github.com/github/docs/blob/main/.github/workflows/notify-when-maintainers-cannot-edit.yaml
on:
workflow_call:
jobs:
draft:
runs-on: ubuntu-latest
steps:
- uses: actions/github-script@v7
with:
script: |
const repo = context.repo.repo;
const query = `
query($number: Int!) {
repository(owner: "doppar", name: "${repo}") {
pullRequest(number: $number) {
headRepositoryOwner {
login
}
isDraft
state
}
}
}
`;
const pullNumber = context.issue.number;
const variables = { number: pullNumber };
try {
console.log(`Determine if pull request is submitted as draft ...`);
const result = await github.graphql(query, variables);
console.log(JSON.stringify(result, null, 2));
const pullRequest = result.repository.pullRequest;
if (pullRequest.headRepositoryOwner.login === 'doppar') {
console.log('PR owned by doppar');
return;
}
if (pullRequest.state !== 'OPEN') {
console.log('PR has already been closed or merged.');
return;
}
if (pullRequest.isDraft) {
console.log('PR not owned by Laravel and is submitted as a draft.');
await github.rest.issues.createComment({
issue_number: pullNumber,
owner: 'doppar',
repo: context.repo.repo,
body: "Thanks for submitting a PR!\n\nNote that draft PR's are not reviewed. If you would like a review, please mark your pull request as ready for review in the GitHub user interface.\n\nPull requests that are abandoned in draft may be closed due to inactivity."
});
}
} catch(e) {
console.log(e);
}
uneditable:
runs-on: ubuntu-latest
steps:
- uses: actions/github-script@v7
with:
script: |
const repo = context.repo.repo;
const query = `
query($number: Int!) {
repository(owner: "doppar", 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 === 'doppar') {
console.log('PR owned by doppar');
return;
}
if (pullRequest.state !== 'OPEN') {
console.log('PR has already been closed or merged');
return;
}
if (! pullRequest.maintainerCanModify) {
console.log('PR not owned by Laravel and does not have maintainer edits enabled');
await github.rest.issues.createComment({
issue_number: pullNumber,
owner: 'doppar',
repo: context.repo.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: 'doppar',
repo: context.repo.repo,
state: 'closed'
});
}
} catch(e) {
console.log(e);
}