Skip to content

Commit 25b3330

Browse files
authored
CHORE: Added PR Formatter & Updated PR Template (microsoft#104)
### ADO Work Item Reference <!-- Insert your ADO Work Item ID below (e.g. AB#374562) --> > [AB#37797](https://sqlclientdrivers.visualstudio.com/c6d89619-62de-46a0-8b46-70b92a84d85e/_workitems/edit/37797) ------------------------------------------------------------------- ### Summary <!-- Insert your Copilot Generated Summary here --> This pull request introduces updates to improve the pull request template and enforce formatting checks via GitHub Actions. The changes aim to standardize pull request descriptions and ensure compliance with specific guidelines for titles, work item references, and summary content. ### Pull Request Template Updates: * [`.github/PULL_REQUEST_TEMPLATE.MD`](diffhunk://#diff-f08b7b99b02df328f28fa0e9a3aa25f5039a05dadc9d90c80ff5c34f822972e6L1-R32): Overhauled the pull request template to include a mandatory section for Azure DevOps (ADO) work item references, a structured guide for PR title prefixes, and placeholders for Copilot-generated summaries. Removed redundant sections such as solution implementation and testing details. ### Automated PR Formatting Checks: * [`.github/workflows/pr-format-check.yml`](diffhunk://#diff-ab47c178dfc6aadcbaa82441040a22f76c0d316b979dfb029d99e2caf81c5b1dR1-R58): Added a GitHub Actions workflow to validate PR formatting. The workflow checks for valid PR title prefixes, presence of ADO work item links, and a meaningful summary section with at least 10 characters of content. <!-- ### Additional Notes PR Title Guide > For feature requests FEAT: (short-description) > For non-feature requests like test case updates, config updates , dependency updates etc CHORE: (short-description) > For Fix requests FIX: (short-description) > For doc update requests DOC: (short-description) > For Formatting, indentation, or styling update STYLE: (short-description) > For Refactor, without any feature changes REFACTOR: (short-description) > For release related changes, without any feature changes RELEASE: #<RELEASE_VERSION> (short-description) -->
1 parent 74037cf commit 25b3330

File tree

2 files changed

+123
-36
lines changed

2 files changed

+123
-36
lines changed

.github/PULL_REQUEST_TEMPLATE.MD

Lines changed: 19 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,32 @@
1-
### PR Title
1+
### ADO Work Item Reference
2+
<!-- Insert your ADO Work Item ID below (e.g. AB#37452) -->
3+
> AB#<WORK_ITEM_ID>
4+
-------------------------------------------------------------------
5+
### Summary
6+
<!-- Insert your Copilot Generated Summary below -->
7+
8+
9+
<!--
10+
### PR Title Guide
211
3-
#### For feature requests
12+
> For feature requests
413
FEAT: (short-description)
514
6-
#### For non-feature requests like test case updates, config updates , dependency updates etc
15+
> For non-feature requests like test case updates, config updates , dependency updates etc
716
CHORE: (short-description)
817
9-
### For Fix requests
18+
> For Fix requests
1019
FIX: (short-description)
1120
12-
### For doc update requests
21+
> For doc update requests
1322
DOC: (short-description)
1423
15-
### For Formatting, indentation, or styling update
24+
> For Formatting, indentation, or styling update
1625
STYLE: (short-description)
1726
18-
### For Refactor, without any feature changes
27+
> For Refactor, without any feature changes
1928
REFACTOR: (short-description)
2029
21-
### For release related changes, without any feature changes
22-
RELEASE: #<RELEASE_VERSION> (short-description)
23-
24-
-------------------------------------------------------------------
25-
### Summary
26-
<!-- Briefly describe the new feature -->
27-
28-
### Issue Reference
29-
Fixes #<ISSUE_NUMBER> (if applicable)
30-
31-
### Solution Implemented
32-
<!-- Explain the fix implemented -->
33-
- [ ] Fixed `<describe what was fixed>`
34-
- [ ] Updated `<mention any changed functions/files>`
35-
36-
### Checklist
37-
- [ ] **Tests Passed** (if applicable)
38-
- [ ] **Code is formatted**
39-
- [ ] **Docs Updated** (if necessary)
40-
41-
### Testing Performed
42-
<!-- How was this fix tested? -->
43-
- [ ] Unit Tests
44-
- [ ] Manual Testing
45-
- [ ] Python Version: `<mention Python version>`
46-
- [ ] OS: `<mention OS>`
47-
48-
### Additional Notes
49-
<!-- Any extra details or related links -->
30+
> For release related changes, without any feature changes
31+
RELEASE: #<RELEASE_VERSION> (short-description)
32+
-->
Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
name: PR Formatting Check
2+
3+
on:
4+
pull_request:
5+
types: [opened, edited, reopened, synchronize]
6+
7+
permissions:
8+
pull-requests: write
9+
10+
jobs:
11+
check:
12+
runs-on: ubuntu-latest
13+
steps:
14+
- name: Validate PR title and description content
15+
uses: actions/github-script@v7
16+
with:
17+
script: |
18+
const title = context.payload.pull_request.title;
19+
const body = context.payload.pull_request.body;
20+
21+
const validTitlePrefixes = [
22+
'FEAT:', 'CHORE:', 'FIX:', 'DOC:', 'STYLE:', 'REFACTOR:', 'RELEASE:'
23+
];
24+
25+
const hasValidPrefix = validTitlePrefixes.some(prefix => title.startsWith(prefix));
26+
27+
if (!hasValidPrefix) {
28+
core.setFailed(`❌ PR title must start with one of the allowed prefixes:\n${validTitlePrefixes.join(', ')}`);
29+
}
30+
31+
const azureWorkItemLinkPattern = /https:\/\/sqlclientdrivers\.visualstudio\.com\/[^\/]+\/_workitems\/edit\/\d+/i;
32+
const hasWorkItemLink = azureWorkItemLinkPattern.test(body);
33+
34+
if (!hasWorkItemLink) {
35+
core.setFailed(`❌ PR should contain a valid ADO Work Item ID.\nExpected a hyperlink in the format: https://sqlclientdrivers.visualstudio.com/.../_workitems/edit/<ID>\nPlease ensure the ADO task hyperlink is present in the PR description.`);
36+
}
37+
38+
// Check if PR description contains a meaningful summary section with actual content
39+
const summaryPattern = /###\s*Summary\s*\r?\n([\s\S]*?)(\r?\n###|$)/;
40+
const summaryMatch = body.match(summaryPattern);
41+
42+
let hasValidSummary = false;
43+
44+
if (summaryMatch && summaryMatch[1]) {
45+
// Extract the summary content
46+
const summaryContent = summaryMatch[1];
47+
48+
// Remove all HTML comments including the template placeholder
49+
const contentWithoutComments = summaryContent.replace(/<!--[\s\S]*?-->/g, '');
50+
51+
// Remove whitespace and check if there's actual text content
52+
const trimmedContent = contentWithoutComments.trim();
53+
54+
// Check if there's at least 10 characters of meaningful content
55+
hasValidSummary = trimmedContent.length >= 10;
56+
}
57+
58+
if (!hasValidSummary) {
59+
core.setFailed(`❌ PR must contain a meaningful summary section with actual text content (minimum 10 characters).
60+
Please add a clear description under the '### Summary' heading in your PR description.`);
61+
}
62+
- name: Add size label based on PR diff
63+
uses: actions/github-script@v7
64+
with:
65+
script: |
66+
const pr = context.payload.pull_request;
67+
const additions = pr.additions;
68+
const deletions = pr.deletions;
69+
const totalChanges = additions + deletions;
70+
71+
// Threshold constants
72+
const SMALL_PR_THRESHOLD = 50;
73+
const MEDIUM_PR_THRESHOLD = 200;
74+
75+
let labelToAdd = '';
76+
if (totalChanges < SMALL_PR_THRESHOLD) {
77+
labelToAdd = 'pr-size: small';
78+
} else if (totalChanges < MEDIUM_PR_THRESHOLD) {
79+
labelToAdd = 'pr-size: medium';
80+
} else {
81+
labelToAdd = 'pr-size: large';
82+
}
83+
84+
// Remove existing size labels if any
85+
const existingLabels = pr.labels.map(l => l.name);
86+
const sizeLabels = ['pr-size: small', 'pr-size: medium', 'pr-size: large'];
87+
for (const label of existingLabels) {
88+
if (sizeLabels.includes(label)) {
89+
await github.rest.issues.removeLabel({
90+
...context.repo,
91+
issue_number: pr.number,
92+
name: label,
93+
});
94+
}
95+
}
96+
97+
// Add new size label
98+
await github.rest.issues.addLabels({
99+
...context.repo,
100+
issue_number: pr.number,
101+
labels: [labelToAdd],
102+
});
103+
104+
console.log(`Added label: ${labelToAdd} (Total changes: ${totalChanges})`);

0 commit comments

Comments
 (0)