Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions packages/core/src/changelogRefs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,3 +126,14 @@ export function neutralizeDescriptionRefs(
// `( ?)` only eats the space before a ref, so one removed from the very start leaves the following space behind.
return out.trim();
}

/** Removes each ref in `refs` from `text`, leaving any other ref as written. */
export function removeDescriptionRefs(text: string, refs: Array<string | undefined>): string {
const remove = new Set(refs.filter((r): r is string => !!r).map((r) => Number(r.replace(/^#/, ''))));
return text
.replace(CODE_SPAN_OR_DESC_REF, (match, _lead: string | undefined, parenNum?: string, bareNum?: string) => {
const num = parenNum ?? bareNum;
return num !== undefined && remove.has(Number(num)) ? '' : match;
})
.trim();
}
1 change: 1 addition & 0 deletions packages/core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export {
escapeChangelogMentions,
neutralizeDescriptionRefs,
parseGitHubOwnerRepo,
removeDescriptionRefs,
renderIssueRefs,
} from './changelogRefs.js';
export { readPackageVersion, writeEnvelope, writeErrorEnvelope } from './cli.js';
Expand Down
10 changes: 10 additions & 0 deletions packages/core/test/unit/changelogRefs.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {
escapeChangelogMentions,
neutralizeDescriptionRefs,
parseGitHubOwnerRepo,
removeDescriptionRefs,
renderIssueRefs,
} from '../../src/changelogRefs.js';

Expand Down Expand Up @@ -200,3 +201,12 @@ describe('neutralizeDescriptionRefs', () => {
expect(neutralizeDescriptionRefs('#999 see here', [], 'strip', repo)).toBe('see here');
});
});

describe('removeDescriptionRefs', () => {
it('should remove the given refs and leave other refs and code spans as written', () => {
expect(removeDescriptionRefs('Fixed the parser (#720), see #12 (#720)', ['#720'])).toBe(
'Fixed the parser, see #12',
);
expect(removeDescriptionRefs('Kept `#720` in code (#720)', ['#720'])).toBe('Kept `#720` in code');
});
});
4 changes: 2 additions & 2 deletions packages/notes/src/llm/tasks/enhance-and-categorize.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { warn } from '@releasekit/core';
import { removeDescriptionRefs, warn } from '@releasekit/core';
import type { ChangelogEntry, LLMCategory } from '../../core/types.js';
import { LLMError } from '../../errors/index.js';
import { LLM_DEFAULTS } from '../defaults.js';
Expand Down Expand Up @@ -105,7 +105,7 @@ export function createEnhanceAndCategorizeValidator(
}
return {
...original,
description: llmEntry.description,
description: removeDescriptionRefs(llmEntry.description, [...(original.issueIds ?? []), original.prNumber]),
scope: llmEntry.scope ?? undefined,
breaking: original.breaking || llmEntry.breaking === true,
leadIn: llmEntry.leadIn ?? undefined,
Expand Down
7 changes: 5 additions & 2 deletions packages/notes/src/llm/tasks/enhance.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { warn } from '@releasekit/core';
import { removeDescriptionRefs, warn } from '@releasekit/core';
import type { ChangelogEntry } from '../../core/types.js';
import { LLM_DEFAULTS } from '../defaults.js';
import type { EnhanceContext, LLMProvider } from '../index.js';
Expand Down Expand Up @@ -58,7 +58,10 @@ export async function enhanceEntries(
batch.map(async (entry) => {
try {
const newDescription = await enhanceEntry(provider, entry, context);
return { ...entry, description: newDescription };
return {
...entry,
description: removeDescriptionRefs(newDescription, [...(entry.issueIds ?? []), entry.prNumber]),
};
} catch {
// Keep the raw entry so one failure doesn't sink the batch.
failures++;
Expand Down
14 changes: 14 additions & 0 deletions packages/notes/test/unit/llm/tasks.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,20 @@ describe('createEnhanceAndCategorizeValidator()', () => {
expect(result.error).toBe('Unknown categories: Mystery. Valid categories: New, Fixed, Changed');
});

it('should strip refs the renderer will append from an enhanced description', () => {
const validate = createEnhanceAndCategorizeValidator(
[{ type: 'changed', description: 'Rename preset', prNumber: '608' }],
ctx,
);
const result = validate(structured({ entries: [fullEntry('Renamed the preset (#608)', 'Changed')] }));

expect(result.valid).toBe(true);
if (!result.valid) {
return;
}
expect(result.value.enhancedEntries[0]?.description).toBe('Renamed the preset');
});

it.each([
['keep a breaking change breaking when the model says it is not', true, false],
['mark an entry breaking when the model says it is', undefined, true],
Expand Down
Loading