Repository navigation
63 lines (56 loc) · 2.23 KB
/
Copy pathautomatic_pr_comment.yaml
File metadata and controls
63 lines (56 loc) · 2.23 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
name: UofT-DSI Main Repository PR Workflow
on:
pull_request_target:
types: [opened, reopened]
permissions:
contents: read
issues: write
pull-requests: write
jobs:
handle-pr:
if: github.repository_owner == 'UofT-DSI'
runs-on: ubuntu-latest
steps:
- name: Handle PR based on author access
uses: actions/github-script@v6
with:
script: |
const pr = context.payload.pull_request;
const issue_number = pr.number;
const repo = context.repo;
let permission = "none";
try {
const response = await github.rest.repos.getCollaboratorPermissionLevel({
owner: repo.owner,
repo: repo.repo,
username: pr.user.login
});
permission = response.data.permission;
} catch (error) {
if (error.status !== 404) {
throw error;
}
}
if (!["write", "admin"].includes(permission)) {
const commentBody = `This pull request was made to the wrong repository. If you are a participant, please close it and open it in your own fork instead. Refer to the [Assignment Submission Guide](https://github.com/UofT-DSI/onboarding/blob/main/onboarding_documents/submissions.md) for detailed instructions.`;
await github.rest.issues.createComment({
owner: repo.owner,
repo: repo.repo,
issue_number: issue_number,
body: commentBody
});
await github.rest.pulls.update({
owner: repo.owner,
repo: repo.repo,
pull_number: issue_number,
state: "closed"
});
} else {
const commentBody = `Thanks for your contribution! 🎉\n\nPlease remember to tag or request a review from the DSI team. Give us up to 72 hours to review your pull request. We appreciate your patience and efforts.`;
await github.rest.issues.createComment({
owner: repo.owner,
repo: repo.repo,
issue_number: issue_number,
body: commentBody
});
}