@@ -2,6 +2,7 @@ import { HTTPException } from "hono/http-exception";
22import type { StoryBookerPermissionAction } from "../adapters/_internal/auth.ts" ;
33import { generateDatabaseCollectionId } from "../utils/adapter-utils.ts" ;
44import { checkAuthorisation } from "../utils/auth.ts" ;
5+ import { dispatchWebhooks } from "../utils/webhooks.ts" ;
56import { BuildsModel } from "./builds-model.ts" ;
67import { ProjectsModel } from "./projects-model.ts" ;
78import { TagSchema , type TagCreateType , type TagType , type TagUpdateType } from "./tags-schema.ts" ;
@@ -41,6 +42,13 @@ export class TagsModel extends Model<TagType> {
4142 } ;
4243 await this . database . createDocument ( this . collectionId , tag , this . dbOptions ) ;
4344
45+ // Do not await, fire and forget
46+ dispatchWebhooks ( "tag:updated" , {
47+ projectId : this . projectId ,
48+ payload : tag ,
49+ projectHooks : await new ProjectsModel ( ) . getWebhooks ( this . projectId ) ,
50+ } ) ;
51+
4452 return tag ;
4553 } catch ( error ) {
4654 throw new HTTPException ( 500 , {
@@ -76,20 +84,35 @@ export class TagsModel extends Model<TagType> {
7684 { ...data , updatedAt : new Date ( ) . toISOString ( ) } ,
7785 this . dbOptions ,
7886 ) ;
87+
88+ // Do not await, fire and forget
89+ dispatchWebhooks ( "tag:updated" , {
90+ projectId : this . projectId ,
91+ payload : data ,
92+ projectHooks : await new ProjectsModel ( ) . getWebhooks ( this . projectId ) ,
93+ } ) ;
7994 }
8095
8196 async delete ( id : string ) : Promise < void > {
8297 this . log ( "Delete tag '%s'..." , id ) ;
98+ const tag = await this . get ( id ) ;
8399
84- const { gitHubDefaultBranch } = await new ProjectsModel ( ) . get ( this . projectId ) ;
85- if ( id === TagsModel . createId ( gitHubDefaultBranch ) ) {
86- const message = `Cannot delete the tag associated with default branch (${ gitHubDefaultBranch } ) of the project '${ this . projectId } '.` ;
100+ const project = await new ProjectsModel ( ) . get ( this . projectId ) ;
101+ if ( id === TagsModel . createId ( project . gitHubDefaultBranch ) ) {
102+ const message = `Cannot delete the tag associated with default branch (${ project . gitHubDefaultBranch } ) of the project '${ this . projectId } '.` ;
87103 this . error ( message ) ;
88104 throw new Error ( message ) ;
89105 }
90106
91107 await this . database . deleteDocument ( this . collectionId , id , this . dbOptions ) ;
92108
109+ // Do not await, fire and forget
110+ dispatchWebhooks ( "tag:updated" , {
111+ projectId : this . projectId ,
112+ payload : tag ,
113+ projectHooks : project . webhooks ,
114+ } ) ;
115+
93116 try {
94117 this . debug ( "Delete builds associated with tag '%s'..." , id ) ;
95118 await new BuildsModel ( this . projectId ) . deleteByTag ( id , false ) ;
0 commit comments