Merge branch 'origin/main' into 'next-release/main'

This commit is contained in:
oauth 2024-10-27 22:30:46 +00:00
commit 50a3ad8374

View file

@ -541,7 +541,6 @@ func (g *GitLab) Deactivate(ctx context.Context, user *model.User, repo *model.R
return err return err
} }
hookID := -1
listProjectHooksOptions := &gitlab.ListProjectHooksOptions{ listProjectHooksOptions := &gitlab.ListProjectHooksOptions{
PerPage: perPage, PerPage: perPage,
Page: 1, Page: 1,
@ -553,13 +552,15 @@ func (g *GitLab) Deactivate(ctx context.Context, user *model.User, repo *model.R
} }
for _, hook := range hooks { for _, hook := range hooks {
if hook.URL == webURL { if strings.Contains(hook.URL, webURL) {
hookID = hook.ID _, err = client.Projects.DeleteProjectHook(_repo.ID, hook.ID, gitlab.WithContext(ctx))
break log.Info().Msg(fmt.Sprintf("successfully deleted hook with ID %d for repo %s", hook.ID, repo.FullName))
if err != nil {
return err
}
} }
} }
// Exit the loop when we've seen all pages
if resp.CurrentPage >= resp.TotalPages { if resp.CurrentPage >= resp.TotalPages {
break break
} }
@ -568,13 +569,7 @@ func (g *GitLab) Deactivate(ctx context.Context, user *model.User, repo *model.R
listProjectHooksOptions.Page = resp.NextPage listProjectHooksOptions.Page = resp.NextPage
} }
if hookID == -1 { return nil
return fmt.Errorf("could not find hook to delete")
}
_, err = client.Projects.DeleteProjectHook(_repo.ID, hookID, gitlab.WithContext(ctx))
return err
} }
// Branches returns the names of all branches for the named repository. // Branches returns the names of all branches for the named repository.