本文整理汇总了Python中sentry.models.Release.merge方法的典型用法代码示例。如果您正苦于以下问题:Python Release.merge方法的具体用法?Python Release.merge怎么用?Python Release.merge使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sentry.models.Release
的用法示例。
在下文中一共展示了Release.merge方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: merge_to
# 需要导入模块: from sentry.models import Release [as 别名]
# 或者: from sentry.models.Release import merge [as 别名]
def merge_to(from_org, to_org):
from sentry.models import (
ApiKey, AuditLogEntry, Commit, OrganizationMember,
OrganizationMemberTeam, Project, Release, ReleaseCommit,
ReleaseEnvironment, ReleaseFile, Repository, Team
)
for from_member in OrganizationMember.objects.filter(organization=from_org):
try:
to_member = OrganizationMember.objects.get(
organization=to_org,
user=from_member.user,
)
except OrganizationMember.DoesNotExist:
from_member.update(organization=to_org)
to_member = from_member
else:
qs = OrganizationMemberTeam.objects.filter(
organizationmember=from_member,
is_active=True,
).select_related()
for omt in qs:
OrganizationMemberTeam.objects.create_or_update(
organizationmember=to_member,
team=omt.team,
defaults={
'is_active': True,
},
)
for team in Team.objects.filter(organization=from_org):
try:
with transaction.atomic():
team.update(organization=to_org)
except IntegrityError:
slugify_instance(team, team.name, organization=to_org)
team.update(
organization=to_org,
slug=team.slug,
)
for project in Project.objects.filter(organization=from_org):
try:
with transaction.atomic():
project.update(organization=to_org)
except IntegrityError:
slugify_instance(project, project.name, organization=to_org)
project.update(
organization=to_org,
slug=project.slug,
)
# TODO(jess): update this when adding unique constraint
# on version, organization for releases
for release in Release.objects.filter(organization=from_org):
try:
to_release = Release.objects.get(
version=release.version,
organization=to_org
)
except Release.DoesNotExist:
Release.objects.filter(
id=release.id
).update(organization=to_org)
else:
Release.merge(to_release, [release])
for model in (ApiKey, AuditLogEntry, ReleaseFile):
model.objects.filter(
organization=from_org,
).update(organization=to_org)
for model in (Commit, ReleaseCommit, ReleaseEnvironment, Repository):
model.objects.filter(
organization_id=from_org.id,
).update(organization_id=to_org.id)
示例2: test_simple
# 需要导入模块: from sentry.models import Release [as 别名]
# 或者: from sentry.models.Release import merge [as 别名]
def test_simple(self):
org = self.create_organization()
commit = Commit.objects.create(organization_id=org.id, repository_id=5)
commit2 = Commit.objects.create(organization_id=org.id, repository_id=6)
# merge to
project = self.create_project(organization=org, name='foo')
environment = Environment.get_or_create(project=project, name='env1')
release = Release.objects.create(version='abcdabc', organization=org)
release.add_project(project)
release_commit = ReleaseCommit.objects.create(
organization_id=org.id, release=release, commit=commit, order=1
)
release_environment = ReleaseEnvironment.objects.create(
organization_id=org.id, project_id=project.id, release_id=release.id, environment_id=environment.id
)
release_project_environment = ReleaseProjectEnvironment.objects.create(
release_id=release.id, project_id=project.id, environment_id=environment.id
)
group_release = GroupRelease.objects.create(
project_id=project.id, release_id=release.id, group_id=1
)
group = self.create_group(project=project, first_release=release)
group_resolution = GroupResolution.objects.create(group=group, release=release)
# merge from #1
project2 = self.create_project(organization=org, name='bar')
environment2 = Environment.get_or_create(project=project2, name='env2')
release2 = Release.objects.create(version='bbbbbbb', organization=org)
release2.add_project(project2)
release_commit2 = ReleaseCommit.objects.create(
organization_id=org.id, release=release2, commit=commit, order=2
)
release_environment2 = ReleaseEnvironment.objects.create(
organization_id=org.id,
project_id=project2.id,
release_id=release2.id,
environment_id=environment2.id,
)
release_project_environment2 = ReleaseProjectEnvironment.objects.create(
release_id=release2.id, project_id=project2.id, environment_id=environment2.id
)
group_release2 = GroupRelease.objects.create(
project_id=project2.id, release_id=release2.id, group_id=2
)
group2 = self.create_group(project=project2, first_release=release2)
group_resolution2 = GroupResolution.objects.create(group=group2, release=release2)
# merge from #2
project3 = self.create_project(organization=org, name='baz')
environment3 = Environment.get_or_create(project=project3, name='env3')
release3 = Release.objects.create(version='cccccc', organization=org)
release3.add_project(project3)
release_commit3 = ReleaseCommit.objects.create(
organization_id=org.id, release=release2, commit=commit2, order=3
)
release_environment3 = ReleaseEnvironment.objects.create(
organization_id=org.id,
project_id=project3.id,
release_id=release3.id,
environment_id=environment3.id,
)
release_project_environment3 = ReleaseProjectEnvironment.objects.create(
release_id=release3.id, project_id=project3.id, environment_id=environment3.id
)
group_release3 = GroupRelease.objects.create(
project_id=project3.id, release_id=release3.id, group_id=3
)
group3 = self.create_group(project=project3, first_release=release3)
group_resolution3 = GroupResolution.objects.create(group=group3, release=release3)
Release.merge(release, [release2, release3])
# ReleaseCommit.release
assert ReleaseCommit.objects.get(id=release_commit.id).release == release
# should not exist because they referenced the same commit
assert not ReleaseCommit.objects.filter(id=release_commit2.id).exists()
assert ReleaseCommit.objects.get(id=release_commit3.id).release == release
# ReleaseEnvironment.release_id
assert ReleaseEnvironment.objects.get(id=release_environment.id).release_id == release.id
assert ReleaseEnvironment.objects.get(id=release_environment2.id).release_id == release.id
assert ReleaseEnvironment.objects.get(id=release_environment3.id).release_id == release.id
# ReleaseProject.release
assert release.projects.count() == 3
assert ReleaseProject.objects.filter(release=release, project=project).exists()
assert ReleaseProject.objects.filter(release=release, project=project2).exists()
assert ReleaseProject.objects.filter(release=release, project=project3).exists()
# ReleaseProjectEnvironment.release
assert ReleaseProjectEnvironment.objects.get(
id=release_project_environment.id).release_id == release.id
assert ReleaseProjectEnvironment.objects.get(
id=release_project_environment2.id).release_id == release.id
assert ReleaseProjectEnvironment.objects.get(
id=release_project_environment3.id).release_id == release.id
# GroupRelease.release_id
assert GroupRelease.objects.get(id=group_release.id).release_id == release.id
#.........这里部分代码省略.........
示例3: merge_to
# 需要导入模块: from sentry.models import Release [as 别名]
# 或者: from sentry.models.Release import merge [as 别名]
def merge_to(from_org, to_org):
from sentry.models import (
ApiKey,
AuditLogEntry,
AuthProvider,
Commit,
OrganizationAvatar,
OrganizationIntegration,
OrganizationMember,
OrganizationMemberTeam,
Project,
Release,
ReleaseCommit,
ReleaseEnvironment,
ReleaseFile,
ReleaseHeadCommit,
Repository,
Team,
Environment,
)
for from_member in OrganizationMember.objects.filter(
organization=from_org, user__isnull=False
):
logger = logging.getLogger('sentry.merge')
try:
to_member = OrganizationMember.objects.get(
organization=to_org,
user=from_member.user,
)
except OrganizationMember.DoesNotExist:
from_member.update(organization=to_org)
to_member = from_member
else:
qs = OrganizationMemberTeam.objects.filter(
organizationmember=from_member,
is_active=True,
).select_related()
for omt in qs:
OrganizationMemberTeam.objects.create_or_update(
organizationmember=to_member,
team=omt.team,
defaults={
'is_active': True,
},
)
logger.info('user.migrate', extra={
'instance_id': from_member.id,
'new_member_id': to_member.id,
'from_organization_id': from_org.id,
'to_organization_id': to_org.id,
})
for from_team in Team.objects.filter(organization=from_org):
try:
with transaction.atomic():
from_team.update(organization=to_org)
except IntegrityError:
slugify_instance(from_team, from_team.name, organization=to_org)
from_team.update(
organization=to_org,
slug=from_team.slug,
)
logger.info('team.migrate', extra={
'instance_id': from_team.id,
'new_slug': from_team.slug,
'from_organization_id': from_org.id,
'to_organization_id': to_org.id,
})
for from_project in Project.objects.filter(organization=from_org):
try:
with transaction.atomic():
from_project.update(organization=to_org)
except IntegrityError:
slugify_instance(
from_project,
from_project.name,
organization=to_org,
reserved=RESERVED_PROJECT_SLUGS)
from_project.update(
organization=to_org,
slug=from_project.slug,
)
logger.info('project.migrate', extra={
'instance_id': from_project.id,
'new_slug': from_project.slug,
'from_organization_id': from_org.id,
'to_organization_id': to_org.id,
})
# TODO(jess): update this when adding unique constraint
# on version, organization for releases
for from_release in Release.objects.filter(organization=from_org):
try:
to_release = Release.objects.get(version=from_release.version, organization=to_org)
except Release.DoesNotExist:
Release.objects.filter(id=from_release.id).update(organization=to_org)
else:
Release.merge(to_release, [from_release])
#.........这里部分代码省略.........