Skip to content

Commit

Permalink
feat(server): support function history changelog (#1756)
Browse files Browse the repository at this point in the history
* feat(server): support function history changelog
  • Loading branch information
0fatal authored Jan 9, 2024
1 parent dfacca6 commit 829fd8a
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
4 changes: 4 additions & 0 deletions server/src/function/dto/update-function.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ export class UpdateFunctionDto {
@IsNotEmpty({ each: true })
tags: string[]

@ApiPropertyOptional()
@MaxLength(256)
changelog?: string

validate() {
return null
}
Expand Down
3 changes: 3 additions & 0 deletions server/src/function/entities/cloud-function-history.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ export class CloudFunctionHistory {
@ApiProperty({ type: CloudFunctionHistorySource })
source: CloudFunctionHistorySource

@ApiProperty({ type: String })
changelog?: string

@ApiProperty()
createdAt: Date
}
7 changes: 4 additions & 3 deletions server/src/function/function.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ export class FunctionService {

const fn = await this.findOne(appid, dto.name)

await this.addOneHistoryRecord(fn)
await this.addOneHistoryRecord(fn, 'created')
await this.publish(fn)
return fn
}
Expand Down Expand Up @@ -175,7 +175,7 @@ export class FunctionService {
)

const fn = await this.findOne(func.appid, func.name)
await this.addOneHistoryRecord(fn)
await this.addOneHistoryRecord(fn, dto.changelog)
await this.publish(fn)

return fn
Expand Down Expand Up @@ -414,7 +414,7 @@ export class FunctionService {
return history
}

async addOneHistoryRecord(func: CloudFunction) {
async addOneHistoryRecord(func: CloudFunction, changelog = '') {
await this.db
.collection<CloudFunctionHistory>('CloudFunctionHistory')
.insertOne({
Expand All @@ -424,6 +424,7 @@ export class FunctionService {
code: func.source.code,
},
createdAt: new Date(),
changelog,
})
}

Expand Down

0 comments on commit 829fd8a

Please sign in to comment.