@@ -3,7 +3,7 @@ import { requirePrincipalSubjectUserId } from '@sim/auth/principal'
33import { getPostgresErrorCode } from '@sim/utils/errors'
44import { generateId } from '@sim/utils/id'
55import { changelogOperations } from '@/lib/changelog/application/operations'
6- import { assertChangelogBody , MAX_CHANGELOG_BODY_BYTES } from '@/lib/changelog/body'
6+ import { assertChangelogBody } from '@/lib/changelog/body'
77import { requireChangelogEnabled } from '@/lib/changelog/feature-flag'
88import { changelogFilePath } from '@/lib/changelog/paths'
99import {
@@ -27,11 +27,7 @@ import {
2727} from '@/lib/changelog/version'
2828import { defineAuthorizedWorkspaceUseCase } from '@/lib/core/application'
2929import { OrchestrationError } from '@/lib/core/orchestration/types'
30- import {
31- createOwnedWorkspaceFile ,
32- fetchWorkspaceFileBuffer ,
33- getWorkspaceFile ,
34- } from '@/lib/uploads/contexts/workspace/workspace-file-manager'
30+ import { createOwnedWorkspaceFile } from '@/lib/uploads/contexts/workspace/workspace-file-manager'
3531import { resolveActiveWorkspaceApplicationContext } from '@/lib/workspaces/application/workspace-context'
3632
3733const authorizationOptions = {
@@ -140,13 +136,6 @@ async function assertChangesInWorkspace(
140136 )
141137}
142138
143- async function readReleaseBody ( row : ChangelogReleaseRow ) : Promise < string > {
144- const file = await getWorkspaceFile ( row . workspaceId , row . bodyFileId , { includeOwnedFiles : true } )
145- if ( ! file ) throw new Error ( `Release ${ row . id } has no body file ${ row . bodyFileId } ` )
146- const buffer = await fetchWorkspaceFileBuffer ( file , { maxBytes : MAX_CHANGELOG_BODY_BYTES } )
147- return buffer . toString ( 'utf-8' )
148- }
149-
150139const resolveWorkspace = ( { input } : { input : { workspaceId : string } } ) =>
151140 resolveActiveWorkspaceApplicationContext ( input . workspaceId )
152141
@@ -168,7 +157,7 @@ export const listChangelogReleases = defineAuthorizedWorkspaceUseCase({
168157 } ,
169158} )
170159
171- /** One release with its markdown body, for Sim to read before it edits . */
160+ /** One release; Sim reads and edits its body at `release.path` with the file tools . */
172161export const getChangelogRelease = defineAuthorizedWorkspaceUseCase ( {
173162 operation : changelogOperations . read ,
174163 resolveContext : ( { input } : { input : { workspaceId : string ; releaseId : string } } ) =>
@@ -179,7 +168,7 @@ export const getChangelogRelease = defineAuthorizedWorkspaceUseCase({
179168 const row = await getRelease ( context . workspaceId , input . releaseId )
180169 if ( ! row ) throw new OrchestrationError ( 'not_found' , 'Release not found' )
181170 const [ release ] = await presentReleases ( [ row ] )
182- return { release, body : await readReleaseBody ( row ) }
171+ return { release }
183172 } ,
184173} )
185174
@@ -276,6 +265,16 @@ export const updateChangelogRelease = defineAuthorizedWorkspaceUseCase({
276265 authorizeResource : ( { context } ) => requireChangelogEnabled ( context . workspaceOrganizationId ) ,
277266 async execute ( { input, context, principal } ) {
278267 const revision = parseRevision ( input . expectedRevision )
268+ if (
269+ input . title === undefined &&
270+ input . bumpReason === undefined &&
271+ input . version === undefined &&
272+ input . changes === undefined
273+ )
274+ throw new OrchestrationError (
275+ 'validation' ,
276+ 'Pass at least one of title, bumpReason, version, or changes'
277+ )
279278 const version = input . version === undefined ? undefined : parseReleaseVersion ( input . version )
280279 const existing = await getRelease ( context . workspaceId , input . releaseId )
281280 if ( ! existing ) throw new OrchestrationError ( 'not_found' , 'Release not found' )
@@ -294,8 +293,7 @@ export const updateChangelogRelease = defineAuthorizedWorkspaceUseCase({
294293 'conflict' ,
295294 'The release changed after it was read; read it again and reapply your edit'
296295 )
297- const [ release ] = await presentReleases ( [ updated ] )
298- return { release }
296+ return { release : presentRelease ( updated . row , updated . changes ) }
299297 } catch ( error ) {
300298 if ( getPostgresErrorCode ( error ) === '23505' && version )
301299 throw new OrchestrationError (
0 commit comments