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

ref(releases): Make it easier to read #80820

Merged
merged 4 commits into from
Nov 15, 2024
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 34 additions & 34 deletions src/sentry/api/helpers/group_index/update.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
from sentry.issues.status_change import handle_status_update, infer_substatus
from sentry.issues.update_inbox import update_inbox
from sentry.models.activity import Activity, ActivityIntegration
from sentry.models.commit import Commit
from sentry.models.group import STATUS_UPDATE_CHOICES, Group, GroupStatus
from sentry.models.groupassignee import GroupAssignee
from sentry.models.groupbookmark import GroupBookmark
Expand Down Expand Up @@ -137,15 +138,13 @@ def get_current_release_version_of_group(group: Group, follows_semver: bool = Fa
if follows_semver:
try:
# This sets current_release_version to the latest semver version associated with a group
order_by_semver_desc = [f"-{col}" for col in Release.SEMVER_COLS]
associated_release_id = GroupRelease.objects.filter(
project_id=group.project.id, group_id=group.id
).values_list("release_id")

current_release_version = (
Release.objects.filter_to_semver() # Only releases that have major set
get_semver_releases(group.project)
.filter(id__in=associated_release_id)
.annotate_prerelease_column()
.order_by(*order_by_semver_desc)
.values_list("version", flat=True)[:1]
.get()
)
Expand Down Expand Up @@ -269,7 +268,7 @@ def update_groups(
status=400,
)
# may not be a release yet
release = status_details.get("inNextRelease") or get_latest_release(projects[0])
release = status_details.get("inNextRelease") or get_release_to_resolve_by(projects[0])
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A more appropriate name for the function.


activity_type = ActivityType.SET_RESOLVED_IN_RELEASE.value
activity_data = {
Expand All @@ -294,14 +293,7 @@ def update_groups(
{"detail": "Cannot set resolved in upcoming release for multiple projects."},
status=400,
)
release = (
status_details.get("inUpcomingRelease")
or Release.objects.filter(
projects=projects[0], organization_id=projects[0].organization_id
)
.extra(select={"sort": "COALESCE(date_released, date_added)"})
.order_by("-sort")[0]
)
release = status_details.get("inUpcomingRelease") or most_recent_release(projects[0])
activity_type = ActivityType.SET_RESOLVED_IN_RELEASE.value
activity_data = {"version": ""}

Expand Down Expand Up @@ -383,11 +375,7 @@ def update_groups(
# we need to update this to find the release for each project (we shouldn't assume
# it's the same)
try:
release = (
Release.objects.filter(projects__in=projects, releasecommit__commit=commit)
armenzg marked this conversation as resolved.
Show resolved Hide resolved
.extra(select={"sort": "COALESCE(date_released, date_added)"})
.order_by("-sort")[0]
)
release = most_recent_release(projects[0], commit)
res_type = GroupResolution.Type.in_release
res_status = GroupResolution.Status.resolved
except IndexError:
Expand Down Expand Up @@ -423,7 +411,7 @@ def update_groups(
)
and follows_semver
):
current_release_version = get_latest_release(projects[0]).version
current_release_version = get_release_to_resolve_by(projects[0]).version
else:
current_release_version = get_current_release_version_of_group(
group=group, follows_semver=follows_semver
Expand Down Expand Up @@ -712,33 +700,45 @@ def update_groups(
return Response(result)


def get_latest_release(project: Project) -> Release | None:
release = None

def get_release_to_resolve_by(project: Project) -> Release | None:
# XXX: Remove block once released
follows_semver = False
if features.has("organizations:releases-resolve-next-release-semver-fix", project.organization):
follows_semver = follows_semver_versioning_scheme(
org_id=project.organization_id, project_id=project.id
)

releases = Release.objects.filter(projects=project, organization_id=project.organization_id)
if follows_semver:
release = (
releases.filter_to_semver()
.annotate_prerelease_column()
.order_by(*[f"-{col}" for col in Release.SEMVER_COLS])
.first()
)
release = greatest_semver_release(project)
else:
release = (
releases.extra(select={"sort": "COALESCE(date_released, date_added)"})
.order_by("-sort")
.first()
)
release = most_recent_release(project)
return release


def most_recent_release(project: Project, commit: Commit | None = None) -> Release | None:
queryset = Release.objects.filter(projects=project, organization_id=project.organization_id)
if commit:
queryset = queryset.filter(releasecommit__commit=commit)
return (
queryset.extra(select={"sort": "COALESCE(date_released, date_added)"})
.order_by("-sort")
.first()
)


def greatest_semver_release(project: Project) -> Release | None:
return get_semver_releases(project).first()


def get_semver_releases(project: Project) -> Release:
return (
Release.objects.filter(projects=project, organization_id=project.organization_id)
.filter_to_semver()
.annotate_prerelease_column()
.order_by(*[f"-{col}" for col in Release.SEMVER_COLS])
)


def handle_is_subscribed(
is_subscribed: bool,
group_list: Sequence[Group],
Expand Down
Loading