Skip to content

Commit 7d2139b

Browse files
committed
chore: update pull request template and add automated checks
1 parent 31d8c58 commit 7d2139b

2 files changed

Lines changed: 99 additions & 2 deletions

File tree

‎.github/pull_request_template.md‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
### Motivation
55

6-
<!-- Explain the **motivation** for making this change. What existing problem does the pull request solve? -->
6+
<!-- Explain the **motivation** for making this change. What existing problem does the pull request solve? Keep it concise and don't describe implementation details. -->
77

88
### Related issue
99

@@ -15,4 +15,4 @@
1515

1616
### Test plan
1717

18-
<!-- Describe the **steps to test this change**, so that a reviewer can verify it. -->
18+
<!-- Describe the **steps to test this change manually**, so that a reviewer can verify it. Don't repeat checks already covered in automated tests. -->
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
name: Pull Request Checks
2+
3+
on:
4+
pull_request_target:
5+
types: [opened, edited, reopened]
6+
7+
permissions:
8+
issues: write
9+
pull-requests: read
10+
11+
concurrency:
12+
group: pull-request-checks-${{ github.event.pull_request.number }}
13+
cancel-in-progress: true
14+
15+
jobs:
16+
check:
17+
name: Check description and visual evidence
18+
runs-on: ubuntu-latest
19+
steps:
20+
- name: Check pull request details
21+
uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0
22+
with:
23+
github-token: ${{ secrets.GITHUB_TOKEN }}
24+
script: |
25+
const MAX_PR_BODY_LENGTH = 1000;
26+
const MARKER = '<!-- pull-request-details-check -->';
27+
28+
const { owner, repo } = context.repo;
29+
30+
const issueNumber = context.payload.pull_request.number;
31+
const body = context.payload.pull_request.body || '';
32+
33+
const problems = [];
34+
35+
if (Array.from(body).length > MAX_PR_BODY_LENGTH) {
36+
problems.push(
37+
`- The description is too long. Please keep it under ${MAX_PR_BODY_LENGTH} characters.`
38+
);
39+
}
40+
41+
if (
42+
!/(?:https?:\/\/[^\s)"']+\.(?:png|jpe?g|gif|webp|avif|mp4|mov|webm|m4v)(?:[?#][^\s)"']*)?|https?:\/\/github\.com\/user-attachments\/assets\/[^\s)"']+)/i.test(
43+
body
44+
)
45+
) {
46+
problems.push(
47+
'- Screenshot or video evidence is missing. Make sure to include one if it affects the UI.'
48+
);
49+
}
50+
51+
const existingComment = (
52+
await github.paginate(github.rest.issues.listComments, {
53+
owner,
54+
repo,
55+
issue_number: issueNumber,
56+
per_page: 100,
57+
})
58+
).find(
59+
(comment) =>
60+
comment.user?.login === 'github-actions[bot]' &&
61+
comment.body?.includes(MARKER)
62+
);
63+
64+
if (problems.length === 0) {
65+
if (existingComment) {
66+
await github.rest.issues.deleteComment({
67+
owner,
68+
repo,
69+
comment_id: existingComment.id,
70+
});
71+
}
72+
73+
return;
74+
}
75+
76+
const commentBody = [
77+
MARKER,
78+
'Found potential problems with the pull request:',
79+
'',
80+
problems.join('\n'),
81+
].join('\n');
82+
83+
if (existingComment) {
84+
await github.rest.issues.updateComment({
85+
owner,
86+
repo,
87+
comment_id: existingComment.id,
88+
body: commentBody,
89+
});
90+
} else {
91+
await github.rest.issues.createComment({
92+
owner,
93+
repo,
94+
issue_number: issueNumber,
95+
body: commentBody,
96+
});
97+
}

0 commit comments

Comments
 (0)