Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Delete GitLab webhooks with partial URL match #4259

Merged
merged 9 commits into from
Oct 27, 2024
17 changes: 7 additions & 10 deletions server/forge/gitlab/gitlab.go
Original file line number Diff line number Diff line change
Expand Up @@ -553,13 +553,16 @@ func (g *GitLab) Deactivate(ctx context.Context, user *model.User, repo *model.R
}

for _, hook := range hooks {
if hook.URL == webURL {
if strings.Contains(hook.URL, webURL) {
hookID = hook.ID
break
_, err = client.Projects.DeleteProjectHook(_repo.ID, hookID, gitlab.WithContext(ctx))
log.Info().Msg(fmt.Sprintf("successfully deleted hook with ID %d for repo %s", hookID, repo.FullName))
if err != nil {
return err
}
}
}

// Exit the loop when we've seen all pages
if resp.CurrentPage >= resp.TotalPages {
break
}
Expand All @@ -568,13 +571,7 @@ func (g *GitLab) Deactivate(ctx context.Context, user *model.User, repo *model.R
listProjectHooksOptions.Page = resp.NextPage
}

if hookID == -1 {
return fmt.Errorf("could not find hook to delete")
}

_, err = client.Projects.DeleteProjectHook(_repo.ID, hookID, gitlab.WithContext(ctx))

return err
return nil
}

// Branches returns the names of all branches for the named repository.
Expand Down