Skip to content

Commit dbd642e

Browse files
committed
refactor: remove unused findChangelogInsertionPoint function and its tests
1 parent 87b4e12 commit dbd642e

File tree

2 files changed

+1
-199
lines changed

2 files changed

+1
-199
lines changed

danger/dangerfile-utils.js

Lines changed: 0 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -54,91 +54,6 @@ function getFlavorConfig(prFlavor) {
5454
};
5555
}
5656

57-
/// Find the appropriate line to insert a changelog entry
58-
function findChangelogInsertionPoint(lines, sectionName) {
59-
let unreleasedIndex = -1;
60-
let sectionIndex = -1;
61-
let insertionLine = -1;
62-
let isNewSection = false;
63-
64-
// Find the "## Unreleased" section
65-
for (let i = 0; i < lines.length; i++) {
66-
if (lines[i].match(/^##\s+Unreleased/i)) {
67-
unreleasedIndex = i;
68-
break;
69-
}
70-
}
71-
72-
if (unreleasedIndex === -1) {
73-
// No "Unreleased" section found
74-
return { success: false };
75-
}
76-
77-
// Look for the target section under "Unreleased"
78-
for (let i = unreleasedIndex + 1; i < lines.length; i++) {
79-
// Stop if we hit another ## section (next release)
80-
if (lines[i].match(/^##\s+/)) {
81-
break;
82-
}
83-
84-
// Check if this is our target section
85-
if (lines[i].match(new RegExp(`^###\\s+${sectionName}`, 'i'))) {
86-
sectionIndex = i;
87-
break;
88-
}
89-
}
90-
91-
if (sectionIndex !== -1) {
92-
// Found the section, find where to insert within it
93-
for (let i = sectionIndex + 1; i < lines.length; i++) {
94-
// Stop if we hit another section or end
95-
if (lines[i].match(/^##[#]?\s+/)) {
96-
break;
97-
}
98-
99-
// Find the first non-empty line after the section header
100-
if (lines[i].trim() !== '') {
101-
// Insert before this line if it's not already a bullet point
102-
insertionLine = lines[i].match(/^-\s+/) ? i + 1 : i;
103-
break;
104-
}
105-
}
106-
107-
// If we didn't find a good spot, insert right after the section header
108-
if (insertionLine === -1) {
109-
insertionLine = sectionIndex + 2; // +1 for the section, +1 for empty line
110-
}
111-
} else {
112-
// Section doesn't exist, we need to create it
113-
isNewSection = true;
114-
115-
// Find where to insert the new section
116-
// Look for the next section after Unreleased or find a good spot
117-
for (let i = unreleasedIndex + 1; i < lines.length; i++) {
118-
if (lines[i].match(/^##\s+/)) {
119-
// Insert before the next release section
120-
insertionLine = i - 1;
121-
break;
122-
} else if (lines[i].match(/^###\s+/)) {
123-
// Insert before the first existing section
124-
insertionLine = i;
125-
break;
126-
}
127-
}
128-
129-
// If no good spot found, insert after a reasonable gap from Unreleased
130-
if (insertionLine === -1) {
131-
insertionLine = unreleasedIndex + 2;
132-
}
133-
}
134-
135-
return {
136-
success: true,
137-
lineNumber: insertionLine + 1, // Convert to 1-based line numbering
138-
isNewSection: isNewSection,
139-
sectionHeader: isNewSection ? `### ${sectionName}` : null
140-
};
141-
}
14257

14358
/// Extract PR flavor from title or branch name
14459
function extractPRFlavor(prTitle, prBranchRef) {
@@ -160,6 +75,5 @@ function extractPRFlavor(prTitle, prBranchRef) {
16075
module.exports = {
16176
FLAVOR_CONFIG,
16277
getFlavorConfig,
163-
findChangelogInsertionPoint,
16478
extractPRFlavor
16579
};

danger/dangerfile-utils.test.js

Lines changed: 1 addition & 113 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
const { describe, it } = require('node:test');
22
const assert = require('node:assert');
3-
const { getFlavorConfig, findChangelogInsertionPoint, extractPRFlavor, FLAVOR_CONFIG } = require('./dangerfile-utils.js');
3+
const { getFlavorConfig, extractPRFlavor, FLAVOR_CONFIG } = require('./dangerfile-utils.js');
44

55
describe('dangerfile-utils', () => {
66
describe('getFlavorConfig', () => {
@@ -143,118 +143,6 @@ describe('dangerfile-utils', () => {
143143
});
144144
});
145145

146-
describe('findChangelogInsertionPoint', () => {
147-
it('should find insertion point in existing section', () => {
148-
const changelog = [
149-
'# Changelog',
150-
'',
151-
'## Unreleased',
152-
'',
153-
'### Features',
154-
'',
155-
'- Some existing feature ([#123](...))',
156-
'',
157-
'## 1.0.0'
158-
];
159-
160-
const result = findChangelogInsertionPoint(changelog, 'Features');
161-
assert.strictEqual(result.success, true);
162-
assert.strictEqual(result.lineNumber, 8); // Should insert after existing feature
163-
assert.strictEqual(result.isNewSection, false);
164-
assert.strictEqual(result.sectionHeader, null);
165-
});
166-
167-
it('should create new section when section does not exist', () => {
168-
const changelog = [
169-
'# Changelog',
170-
'',
171-
'## Unreleased',
172-
'',
173-
'### Features',
174-
'',
175-
'- Some existing feature ([#123](...))',
176-
'',
177-
'## 1.0.0'
178-
];
179-
180-
const result = findChangelogInsertionPoint(changelog, 'Security');
181-
assert.strictEqual(result.success, true);
182-
assert.strictEqual(result.isNewSection, true);
183-
assert.strictEqual(result.sectionHeader, '### Security');
184-
// Should insert before existing Features section
185-
assert.strictEqual(result.lineNumber, 5);
186-
});
187-
188-
it('should handle changelog with no existing sections', () => {
189-
const changelog = [
190-
'# Changelog',
191-
'',
192-
'## Unreleased',
193-
'',
194-
'## 1.0.0'
195-
];
196-
197-
const result = findChangelogInsertionPoint(changelog, 'Features');
198-
assert.strictEqual(result.success, true);
199-
assert.strictEqual(result.isNewSection, true);
200-
assert.strictEqual(result.sectionHeader, '### Features');
201-
// Should insert after Unreleased header
202-
assert.strictEqual(result.lineNumber, 4);
203-
});
204-
205-
it('should fail when no Unreleased section exists', () => {
206-
const changelog = [
207-
'# Changelog',
208-
'',
209-
'## 1.0.0',
210-
'',
211-
'- Initial release'
212-
];
213-
214-
const result = findChangelogInsertionPoint(changelog, 'Features');
215-
assert.strictEqual(result.success, false);
216-
});
217-
218-
it('should handle empty section', () => {
219-
const changelog = [
220-
'# Changelog',
221-
'',
222-
'## Unreleased',
223-
'',
224-
'### Features',
225-
'',
226-
'### Fixes',
227-
'',
228-
'- Some fix ([#456](...))',
229-
'',
230-
'## 1.0.0'
231-
];
232-
233-
const result = findChangelogInsertionPoint(changelog, 'Features');
234-
assert.strictEqual(result.success, true);
235-
assert.strictEqual(result.isNewSection, false);
236-
// Should insert in empty Features section
237-
assert.strictEqual(result.lineNumber, 7);
238-
});
239-
240-
it('should be case-insensitive for section matching', () => {
241-
const changelog = [
242-
'# Changelog',
243-
'',
244-
'## unreleased',
245-
'',
246-
'### features',
247-
'',
248-
'- Some existing feature ([#123](...))',
249-
'',
250-
'## 1.0.0'
251-
];
252-
253-
const result = findChangelogInsertionPoint(changelog, 'Features');
254-
assert.strictEqual(result.success, true);
255-
assert.strictEqual(result.isNewSection, false);
256-
});
257-
});
258146

259147
describe('FLAVOR_CONFIG integrity', () => {
260148
it('should have unique labels across all configs', () => {

0 commit comments

Comments
 (0)