-
Notifications
You must be signed in to change notification settings - Fork 8
56 lines (46 loc) · 2.03 KB
/
pr-description-check.yml
File metadata and controls
56 lines (46 loc) · 2.03 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
name: PR Description Check
on: [pull_request]
permissions:
contents: read
pull-requests: write
jobs:
check-pr-description:
runs-on: ubuntu-latest
steps:
- name: Check PR Description
uses: actions/github-script@v7
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
// Fetch the current PR data
const pr = await github.rest.pulls.get({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: context.issue.number
});
const description = pr.data.body || '';
const defaultText = "Please include a summary of the fix/feature/change, including any relevant motivation and context.";
// Only check for default template text
if (description.includes(defaultText)) {
const errorMessage = ` PR Description Error:
Your PR description needs attention.
Description Requirements:
- Must not contain the default template text
- Should include:
* A clear summary of the changes
* Motivation for the changes
* Any relevant context
Please replace the default text with a meaningful description of your changes.`;
// Add comment to the PR
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
body: errorMessage
});
core.setFailed('PR description validation failed. Please check the comment for details.');
}
// Log the description for debugging
console.log('PR Description:', description);
console.log('Description length:', description.length);
console.log('Trimmed length:', description.trim().length);