|
1 | | -import logging |
2 | 1 | import typing |
3 | 2 |
|
4 | | -from shared.django_apps.core.models import Commit |
5 | | - |
6 | 3 | from codecov_auth.models import Owner, Service |
7 | 4 | from core.models import Repository |
8 | 5 |
|
9 | | -log = logging.getLogger(__name__) |
10 | | - |
11 | 6 |
|
12 | 7 | def get_repository_and_owner_from_string( |
13 | 8 | service: Service, repo_identifier: str |
@@ -50,45 +45,3 @@ def get_repository_from_string( |
50 | 45 | service=service, repo_identifier=repo_identifier |
51 | 46 | ) |
52 | 47 | return repository |
53 | | - |
54 | | - |
55 | | -def get_repository_and_owner_from_slug_and_commit( |
56 | | - slug: str, commitid: str |
57 | | -) -> tuple[Repository | None, Owner | None]: |
58 | | - if "::::" not in slug: |
59 | | - return None, None |
60 | | - |
61 | | - owner_username, repository_name = slug.rsplit("::::", 1) |
62 | | - |
63 | | - # formatting for GL subgroups |
64 | | - if ":::" in owner_username: |
65 | | - owner_username = owner_username.replace(":::", ":") |
66 | | - |
67 | | - matching_repositories = Repository.objects.filter( |
68 | | - author__username=owner_username, name=repository_name |
69 | | - ).select_related("author") |
70 | | - if matching_repositories.count() == 1: |
71 | | - log.info( |
72 | | - "get_repository_and_owner_from_slug_and_commit success", |
73 | | - extra=dict(slug=slug), |
74 | | - ) |
75 | | - repository = matching_repositories.first() |
76 | | - return repository, repository.author |
77 | | - else: |
78 | | - # commit might not exist yet (if this is first upload for it) |
79 | | - try: |
80 | | - # Commit has UniqueConstraint on commitid + repository |
81 | | - commit = Commit.objects.select_related( |
82 | | - "repository", "repository__author" |
83 | | - ).get(commitid=commitid, repository__in=matching_repositories) |
84 | | - log.info( |
85 | | - "get_repository_and_owner_from_slug_and_commit multiple matches success", |
86 | | - extra=dict(slug=slug), |
87 | | - ) |
88 | | - return commit.repository, commit.repository.author |
89 | | - except (Commit.DoesNotExist, Commit.MultipleObjectsReturned): |
90 | | - log.info( |
91 | | - "get_repository_and_owner_from_slug_and_commit fail", |
92 | | - extra=dict(slug=slug), |
93 | | - ) |
94 | | - return None, None |
0 commit comments