Introduce a project's settings to reset integrations and webhooks

Everyone can contribute. Help move this issue forward while earning points, leveling up and collecting rewards.

Proposal

In cases that integrations for certain projects are no longer working or giving 500 errors, the only workflow outlined in our dosc is Fix integrations and webhooks, which is through db console, and it truncates all integration data.

What one of our customers (Internal Link) was aiming for is only remove the failed integrations for only certain projects.

Based on the internal discussions here, the integrations team was able to provide the rails commands to reset integrations on projects level.

It would be a good idea if we make this available through UI as well.

The code introduced by @bmarjanovic as a start is:

def fix_integrations_and_hooks_settings(project_name)
  project = Project.includes(:integrations, :hooks).find_by_name(project_name)
  integration_ids = project.integration_ids

  objects_to_delete = {}

  objects_to_delete[Integration] = integration_ids
  objects_to_delete[WebHook] = project.hook_ids
  objects_to_delete[ServiceHook] = ServiceHook.where(integration_id: integration_ids)
  objects_to_delete[ChatName] = ChatName.where(integration_id: integration_ids)
  objects_to_delete[Integrations::IssueTrackerData] = Integrations::IssueTrackerData.where(integration_id: integration_ids)
  objects_to_delete[Integrations::JiraTrackerData] = Integrations::JiraTrackerData.where(integration_id: integration_ids)
  objects_to_delete[Integrations::ZentaoTrackerData] = Integrations::ZentaoTrackerData.where(integration_id: integration_ids)
  objects_to_delete[SlackIntegration] = SlackIntegration.where(integration_id: integration_ids)

  objects_to_delete.each do |object_class, object_ids|
    object_class.delete(object_ids)
  end
end
Edited by 🤖 GitLab Bot 🤖