@@ -202,15 +202,20 @@ async function update(project, currentUser) {
202
202
return item ;
203
203
} ) ;
204
204
const oldRepositories = await dbHelper . queryRepositoriesByProjectId ( dbProject . id ) ;
205
+ const weebhookIds = { } ;
205
206
for ( const repo of oldRepositories ) { // eslint-disable-line
207
+ if ( repo . registeredWebhookId ) {
208
+ weebhookIds [ repo . url ] = repo . registeredWebhookId ;
209
+ }
206
210
await dbHelper . removeById ( models . Repository , repo . id ) ;
207
211
}
208
212
for ( const repoUrl of repoUrls ) { // eslint-disable-line no-restricted-syntax
209
213
await dbHelper . create ( models . Repository , {
210
214
id : helper . generateIdentifier ( ) ,
211
215
projectId : dbProject . id ,
212
216
url : repoUrl ,
213
- archived : project . archived
217
+ archived : project . archived ,
218
+ registeredWebhookId : weebhookIds [ repoUrl ]
214
219
} )
215
220
}
216
221
dbProject . updatedAt = new Date ( ) ;
@@ -542,6 +547,12 @@ async function createHook(body, currentUser, repoUrl) {
542
547
_ . find ( hooks , { id : parseInt ( dbRepo . registeredWebhookId , 10 ) } ) ) {
543
548
await client . ProjectHooks . remove ( `${ repoOwner } /${ repoName } ` , dbRepo . registeredWebhookId ) ;
544
549
}
550
+ for ( const currentHook of hooks ) { // eslint-disable-line no-restricted-syntax
551
+ if ( currentHook . id !== parseInt ( dbRepo . registeredWebhookId , 10 ) &&
552
+ currentHook . url === `${ config . HOOK_BASE_URL } /webhooks/gitlab` ) {
553
+ await client . ProjectHooks . remove ( `${ repoOwner } /${ repoName } ` , currentHook . id ) ;
554
+ }
555
+ }
545
556
const hook = await client . ProjectHooks . add ( `${ repoOwner } /${ repoName } ` ,
546
557
`${ config . HOOK_BASE_URL } /webhooks/gitlab` , {
547
558
push_events : true ,
0 commit comments