def migrate_repo(repo_id, integration_id, organization_id): integration = Integration.objects.get(id=integration_id) installation = integration.get_installation( organization_id=organization_id, ) repo = Repository.objects.get(id=repo_id) if installation.has_repo_access(repo): # this probably shouldn't happen, but log it just in case if repo.integration_id is not None and repo.integration_id != integration_id: logger.info('repo.migration.integration-change', extra={ 'integration_id': integration_id, 'old_integration_id': repo.integration_id, 'organization_id': organization_id, 'repo_id': repo.id, }) repo.integration_id = integration_id repo.provider = 'integrations:%s' % (integration.provider, ) repo.save() logger.info('repo.migrated', extra={ 'integration_id': integration_id, 'organization_id': organization_id, 'repo_id': repo.id, }) Migrator.run( integration=integration, organization=Organization.objects.get(id=organization_id), )
def migrate_repo(repo_id, integration_id, organization_id): integration = Integration.objects.get(id=integration_id) installation = integration.get_installation( organization_id=organization_id, ) repo = Repository.objects.get(id=repo_id) if installation.has_repo_access(repo): # this probably shouldn't happen, but log it just in case if repo.integration_id is not None and repo.integration_id != integration_id: logger.info('repo.migration.integration-change', extra={ 'integration_id': integration_id, 'old_integration_id': repo.integration_id, 'organization_id': organization_id, 'repo_id': repo.id, }) repo.integration_id = integration_id repo.provider = 'integrations:%s' % (integration.provider, ) # check against disabled specifically -- don't want to accidentally un-delete repos if repo.status == ObjectStatus.DISABLED: repo.status = ObjectStatus.VISIBLE repo.save() logger.info('repo.migrated', extra={ 'integration_id': integration_id, 'organization_id': organization_id, 'repo_id': repo.id, }) from sentry.mediators.plugins import Migrator Migrator.run( integration=integration, organization=Organization.objects.get(id=organization_id), )
def setUp(self): super().setUp() self.organization = self.create_organization() self.project = self.create_project(organization=self.organization) self.integration = Integration.objects.create(provider=ExampleIntegrationProvider.key) self.migrator = Migrator(integration=self.integration, organization=self.organization)
def migrate_repo(repo_id: int, integration_id: int, organization_id: int) -> None: integration = Integration.objects.get(id=integration_id) installation = integration.get_installation( organization_id=organization_id) repo = Repository.objects.get(id=repo_id) if installation.has_repo_access(repo): # This probably shouldn't happen, but log it just in case. if repo.integration_id is not None and repo.integration_id != integration_id: logger.info( "repo.migration.integration-change", extra={ "integration_id": integration_id, "old_integration_id": repo.integration_id, "organization_id": organization_id, "repo_id": repo.id, }, ) repo.integration_id = integration_id repo.provider = f"integrations:{integration.provider}" # Check against disabled specifically -- don't want to accidentally un-delete repos. original_status = repo.status if repo.status == ObjectStatus.DISABLED: repo.status = ObjectStatus.VISIBLE repo.save() logger.info( "repo.migrated", extra={ "integration_id": integration_id, "organization_id": organization_id, "repo_id": repo.id, "original_status": original_status, }, ) from sentry.mediators.plugins import Migrator Migrator.run(integration=integration, organization=Organization.objects.get(id=organization_id))
def migrate_repo(repo_id, integration_id, organization_id): integration = Integration.objects.get(id=integration_id) installation = integration.get_installation( organization_id=organization_id, ) repo = Repository.objects.get(id=repo_id) if installation.has_repo_access(repo): # this probably shouldn't happen, but log it just in case if repo.integration_id is not None and repo.integration_id != integration_id: logger.info( 'repo.migration.integration-change', extra={ 'integration_id': integration_id, 'old_integration_id': repo.integration_id, 'organization_id': organization_id, 'repo_id': repo.id, } ) repo.integration_id = integration_id repo.provider = 'integrations:%s' % (integration.provider,) # check against disabled specifically -- don't want to accidentally un-delete repos if repo.status == ObjectStatus.DISABLED: repo.status = ObjectStatus.VISIBLE repo.save() logger.info( 'repo.migrated', extra={ 'integration_id': integration_id, 'organization_id': organization_id, 'repo_id': repo.id, } ) from sentry.mediators.plugins import Migrator Migrator.run( integration=integration, organization=Organization.objects.get(id=organization_id), )
class MigratorTest(TestCase): def setUp(self): super(MigratorTest, self).setUp() self.organization = self.create_organization() self.project = self.create_project(organization=self.organization) self.integration = Integration.objects.create( provider=ExampleIntegrationProvider.key, ) self.migrator = Migrator( integration=self.integration, organization=self.organization, ) def test_all_repos_migrated(self): Repository.objects.create( organization_id=self.organization.id, provider=self.integration.provider, integration_id=self.integration.id, ) assert self.migrator.all_repos_migrated(self.integration.provider) def test_disable_for_all_projects(self): plugin = plugins.get('example') plugin.enable(self.project) assert plugin in plugins.for_project(self.project) self.migrator.disable_for_all_projects(plugin) assert plugin not in plugins.for_project(self.project) def test_call(self): plugin = plugins.get('example') plugin.enable(self.project) self.migrator.call() assert plugin not in plugins.for_project(self.project) def test_does_not_disable_any_plugin(self): plugin = plugins.get('webhooks') plugin.enable(self.project) self.migrator.call() assert plugin in plugins.for_project(self.project) def test_logs(self): Migrator.run( integration=self.integration, organization=self.organization, )
def setUp(self): super(MigratorTest, self).setUp() self.organization = self.create_organization() self.project = self.create_project(organization=self.organization) self.integration = Integration.objects.create( provider=ExampleIntegrationProvider.key, ) self.migrator = Migrator( integration=self.integration, organization=self.organization, )
def test_logs(self): Migrator.run( integration=self.integration, organization=self.organization, )
def post_install(self, integration, organization, extra=None): Migrator.run(integration=integration, organization=organization)
def post_install(self, integration, organization): Migrator.run( integration=integration, organization=organization )