Skip to content

Commit

Permalink
ref: make create or update typesafe (#75149)
Browse files Browse the repository at this point in the history
<!-- Describe your PR here. -->
  • Loading branch information
asottile-sentry authored Jul 29, 2024
1 parent f222b77 commit 4bc2ada
Showing 1 changed file with 13 additions and 11 deletions.
24 changes: 13 additions & 11 deletions src/sentry/models/release.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import re
from collections.abc import Mapping, Sequence
from time import time
from typing import ClassVar
from typing import ClassVar, TypedDict

import orjson
import sentry_sdk
Expand Down Expand Up @@ -36,6 +36,7 @@
from sentry.locks import locks
from sentry.models.activity import Activity
from sentry.models.artifactbundle import ArtifactBundle
from sentry.models.commitauthor import CommitAuthor
from sentry.models.commitfilechange import CommitFileChange
from sentry.models.grouphistory import GroupHistoryStatus, record_group_history
from sentry.models.groupinbox import GroupInbox, GroupInboxRemoveAction, remove_group_from_inbox
Expand Down Expand Up @@ -178,6 +179,12 @@ def get_group_release_version(
return release_version or None


class _CommitDataKwargs(TypedDict, total=False):
author: CommitAuthor
message: str
date_added: str


@region_silo_model
class Release(Model):
"""
Expand Down Expand Up @@ -658,7 +665,6 @@ def set_commits(self, commit_list):

# TODO(dcramer): this function could use some cleanup/refactoring as it's a bit unwieldy
from sentry.models.commit import Commit
from sentry.models.commitauthor import CommitAuthor
from sentry.models.group import Group, GroupStatus
from sentry.models.grouplink import GroupLink
from sentry.models.groupresolution import GroupResolution
Expand Down Expand Up @@ -752,7 +758,7 @@ def set_commits(self, commit_list):
else:
author = authors[author_email]

commit_data = {}
commit_data: _CommitDataKwargs = {}

# Update/set message and author if they are provided.
if author is not None:
Expand All @@ -768,14 +774,10 @@ def set_commits(self, commit_list):
key=data["id"],
defaults=commit_data,
)
if not created:
commit_data = {
key: value
for key, value in commit_data.items()
if getattr(commit, key) != value
}
if commit_data:
commit.update(**commit_data)
if not created and any(
getattr(commit, key) != value for key, value in commit_data.items()
):
commit.update(**commit_data)

if author is None:
author = commit.author
Expand Down

0 comments on commit 4bc2ada

Please sign in to comment.