-
Notifications
You must be signed in to change notification settings - Fork 61
89 lines (76 loc) · 3.01 KB
/
Copy pathpr-description-validation.yml
File metadata and controls
89 lines (76 loc) · 3.01 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
name: PR Description Validation
on:
pull_request:
types: [opened, edited, synchronize]
permissions:
pull-requests: write
contents: read
jobs:
validate-pr-description:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Validate PR Description
uses: actions/github-script@v7
with:
script: |
const pr = context.payload.pull_request;
const body = pr.body || '';
// Check if description is empty
if (!body || body.trim().length === 0) {
core.setFailed(' PR description is required and cannot be empty');
return;
}
// Check minimum length (100 characters)
if (body.trim().length < 100) {
core.setFailed('PR description must be at least 100 characters long');
return;
}
// Check for required sections
const requiredSections = ['## What', '## Why', '## How'];
const missingSections = [];
requiredSections.forEach(section => {
if (!body.includes(section)) {
missingSections.push(section);
}
});
if (missingSections.length > 0) {
core.setFailed(` PR description must include these sections: ${missingSections.join(', ')}`);
return;
}
// If all checks pass
core.info(' PR description is valid');
// Add comment with validation result
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: ' PR description validated successfully!'
});
- name: Comment on validation failure
if: failure()
uses: actions/github-script@v7
with:
script: |
const body = '### PR Description Validation Failed \n\n' +
'Please update your PR description to include:\n' +
'- **Minimum 100 characters** of description\n' +
'- **## What** section - What does this PR do?\n' +
'- **## Why** section - Why is this change needed?\n' +
'- **## How** section - How does it accomplish the goal?\n\n' +
'Example format:\n' +
'```\n' +
'## What\n' +
'This PR adds a new authentication system that...\n\n' +
'## Why\n' +
'The current authentication system has X limitations that...\n\n' +
'## How\n' +
'We implemented Y by using Z approach...\n' +
'```';
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: body
});