Skip to content

Commit

Permalink
disable populating log_context based on commit_sha/commit_id
Browse files Browse the repository at this point in the history
  • Loading branch information
matt-codecov committed Dec 20, 2024
1 parent 6f971be commit e0de41b
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 52 deletions.
50 changes: 7 additions & 43 deletions helpers/log_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from sentry_sdk import get_current_span
from shared.config import get_config

from database.models.core import Commit, Owner, Repository
from database.models.core import Owner, Repository

log = logging.getLogger("log_context")

Expand Down Expand Up @@ -58,48 +58,13 @@ def populate_from_sqlalchemy(self, dbsession):
return

try:
can_identify_commit = self.commit_id is not None or (
self.commit_sha is not None and self.repo_id is not None
)
# - commit_id (or commit_sha + repo_id) is enough to get everything else
# - however, this slams the commit table and we rarely really need the
# DB PK for a commit, so we don't do this
# - repo_id is enough to get repo and owner
# - owner_id is just enough to get owner

# commit_id or (commit_sha + repo_id) is enough to get everything else
if can_identify_commit:
query = (
dbsession.query(
Commit.id_,
Commit.commitid,
Repository.repoid,
Repository.name,
Owner.ownerid,
Owner.username,
Owner.service,
Owner.plan,
)
.join(Commit.repository)
.join(Repository.owner)
)

if self.commit_id is not None:
query = query.filter(Commit.id_ == self.commit_id)
else:
query = query.filter(
Commit.commitid == self.commit_sha,
Commit.repoid == self.repo_id,
)

(
self.commit_id,
self.commit_sha,
self.repo_id,
self.repo_name,
self.owner_id,
self.owner_username,
self.owner_service,
self.owner_plan,
) = query.first()

# repo_id is enough to get repo and owner
elif self.repo_id:
if self.repo_id:
query = (
dbsession.query(
Repository.name,
Expand All @@ -120,7 +85,6 @@ def populate_from_sqlalchemy(self, dbsession):
self.owner_plan,
) = query.first()

# owner_id is just enough for owner
elif self.owner_id:
query = dbsession.query(
Owner.username, Owner.service, Owner.plan
Expand Down
10 changes: 1 addition & 9 deletions helpers/tests/unit/test_log_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,18 +75,11 @@ def test_populate_just_commit_sha(dbsession):


def test_populate_just_commit_id(dbsession):
owner, repo, commit = create_db_records(dbsession)
_owner, _repo, commit = create_db_records(dbsession)
log_context = LogContext(commit_id=commit.id_)
log_context.populate_from_sqlalchemy(dbsession)

assert log_context == LogContext(
repo_id=repo.repoid,
repo_name="example-python",
owner_id=owner.ownerid,
owner_username="codecove2e",
owner_service="github",
owner_plan="users-basic",
commit_sha=commit.commitid,
commit_id=commit.id_,
)

Expand All @@ -104,7 +97,6 @@ def test_populate_repo_and_commit_sha(dbsession):
owner_service="github",
owner_plan="users-basic",
commit_sha=commit.commitid,
commit_id=commit.id_,
)


Expand Down

0 comments on commit e0de41b

Please sign in to comment.