Skip to content

Commit 5b6381f

Browse files
Merge pull request #3577 from MicrosoftDocs/fix-labeler-regex
Fix DO_NOT_EDIT detection in PR labeler workflow
2 parents 0b91526 + 7470fd4 commit 5b6381f

1 file changed

Lines changed: 12 additions & 13 deletions

File tree

.github/workflows/pr-labeler.yml

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -84,16 +84,14 @@ jobs:
8484
for (const fileDiff of fileDiffs) {
8585
const lines = fileDiff.split('\n');
8686
87-
// Check if changes are inside DO_NOT_EDIT blocks
88-
// We look at the full file content for changed files
8987
const fileMatch = fileDiff.match(/^a\/(.+?) b\//);
9088
if (!fileMatch) continue;
9189
const filePath = fileMatch[1];
9290
9391
// Only analyze markdown files
9492
if (!filePath.endsWith('.md')) continue;
9593
96-
// Count additions and deletions (lines starting with + or - after the header)
94+
// Count additions and deletions
9795
let inHunk = false;
9896
let addedLines = [];
9997
let removedLines = [];
@@ -116,14 +114,11 @@ jobs:
116114
117115
// Check for code block changes (fenced code in AL, json, xml, etc.)
118116
const codeBlockPattern = /^```\s*(al|json|xml|yaml|powershell|csharp|cs|javascript|js)/i;
119-
let inCodeBlock = false;
120117
121118
for (const line of addedLines.concat(removedLines)) {
122119
if (codeBlockPattern.test(line.trim())) {
123-
inCodeBlock = !inCodeBlock;
124120
continue;
125121
}
126-
// If a changed line is inside a code fence, or looks like AL/code
127122
if (line.match(/^\s*(trigger|procedure|local|var|begin|end;|if |then|else|exit\(|record\s|codeunit\s|page\s|table\s)/i)) {
128123
hasCodeChanges = true;
129124
}
@@ -138,23 +133,29 @@ jobs:
138133
// Check if changes touch DO_NOT_EDIT sections
139134
if (fs.existsSync(filePath)) {
140135
const content = fs.readFileSync(filePath, 'utf8');
141-
const doNotEditPattern = /(START>DO_NOT_EDIT)([\s\S]*?)(END>DO_NOT_EDIT)/g;
136+
// Match DO_NOT_EDIT blocks using the actual closing marker format.
137+
// AL reference uses: [//]: # (IMPORTANT: END>DO_NOT_EDIT)
138+
// API reference uses: <!-- END>DO_NOT_EDIT -->
139+
// The previous pattern matched prematurely on the instructional comment
140+
// "between here and the END>DO_NOT_EDIT" — fixed by requiring the
141+
// closing marker prefix (IMPORTANT: or <!--).
142+
const doNotEditPattern = /START>DO_NOT_EDIT[\s\S]*?(?:IMPORTANT: END>DO_NOT_EDIT|<!-- END>DO_NOT_EDIT)/g;
142143
let match;
143144
while ((match = doNotEditPattern.exec(content)) !== null) {
144-
// Check if any added/removed line appears within a DO_NOT_EDIT block
145145
const blockContent = match[0];
146-
for (const changed of addedLines) {
146+
// Check both added and removed lines against the block
147+
for (const changed of addedLines.concat(removedLines)) {
147148
if (changed.trim().length > 0 && blockContent.includes(changed.trim())) {
148149
hasDoNotEditChanges = true;
149150
break;
150151
}
151152
}
153+
if (hasDoNotEditChanges) break;
152154
}
153155
}
154156
155157
// Typo detection: large structural changes are not typos
156158
for (const added of addedLines) {
157-
// If any added line is more than a small text change, it's not a typo
158159
if (added.trim().startsWith('#') || added.trim().startsWith('```') ||
159160
added.trim().length > 200) {
160161
isTypoOnly = false;
@@ -167,7 +168,6 @@ jobs:
167168
if (totalChanges > 50 || hasCodeChanges) {
168169
isTypoOnly = false;
169170
}
170-
// A PR with 0 changes isn't a typo either
171171
if (totalChanges === 0) {
172172
isTypoOnly = false;
173173
}
@@ -188,7 +188,6 @@ jobs:
188188
const labelsArray = [...labels];
189189
console.log(`Applying labels: ${labelsArray.join(', ')}`);
190190
191-
// Ensure labels exist (create if they don't)
192191
for (const label of labelsArray) {
193192
try {
194193
await github.rest.issues.getLabel({
@@ -218,4 +217,4 @@ jobs:
218217
console.log('No labels to apply.');
219218
}
220219
env:
221-
BASE_REF: ${{ github.base_ref }}
220+
BASE_REF: ${{ github.base_ref }}

0 commit comments

Comments
 (0)