Skip to content
This repository was archived by the owner on Mar 13, 2025. It is now read-only.

Commit 0f49c5c

Browse files
authored
Merge pull request #433 from afrisalyp/develop
#432 fix registeredWebhookId missing in the update project function.
2 parents 3c76321 + a04dca2 commit 0f49c5c

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

src/services/ProjectService.js

+12-1
Original file line numberDiff line numberDiff line change
@@ -202,15 +202,20 @@ async function update(project, currentUser) {
202202
return item;
203203
});
204204
const oldRepositories = await dbHelper.queryRepositoriesByProjectId(dbProject.id);
205+
const weebhookIds = {};
205206
for (const repo of oldRepositories) { // eslint-disable-line
207+
if (repo.registeredWebhookId) {
208+
weebhookIds[repo.url] = repo.registeredWebhookId;
209+
}
206210
await dbHelper.removeById(models.Repository, repo.id);
207211
}
208212
for (const repoUrl of repoUrls) { // eslint-disable-line no-restricted-syntax
209213
await dbHelper.create(models.Repository, {
210214
id: helper.generateIdentifier(),
211215
projectId: dbProject.id,
212216
url: repoUrl,
213-
archived: project.archived
217+
archived: project.archived,
218+
registeredWebhookId: weebhookIds[repoUrl]
214219
})
215220
}
216221
dbProject.updatedAt = new Date();
@@ -542,6 +547,12 @@ async function createHook(body, currentUser, repoUrl) {
542547
_.find(hooks, {id: parseInt(dbRepo.registeredWebhookId, 10)})) {
543548
await client.ProjectHooks.remove(`${repoOwner}/${repoName}`, dbRepo.registeredWebhookId);
544549
}
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+
}
545556
const hook = await client.ProjectHooks.add(`${repoOwner}/${repoName}`,
546557
`${config.HOOK_BASE_URL}/webhooks/gitlab`, {
547558
push_events: true,

0 commit comments

Comments
 (0)