-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit is a fix for the recent issue where branch heads were all set to the same value each time they were updated due to a bug in the Branch django model. This fix creates a helper function that checks for the 2 remaining innacurate commit shas that a large number of branches were set to. If the current branch head is set to one of those shas, we update the branch head by fetching the latest commit on that branch from the db. Note that we must use a raw sql query here to update the branch object because using the django ORM to update it would lead to the same issue we are trying to fix. Signed-off-by: joseph-sentry <joseph.sawaya@sentry.io>
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
from django.db import connection | ||
|
||
|
||
def get_or_update_branch_head( | ||
commits, | ||
branch, | ||
repoid, | ||
): | ||
# there was a bug that set a large number of branch heads to these two shas, so we are rectifying that issue here | ||
if ( | ||
branch.head == "81c2b4fa3ae9ef615c8f740c5cba95d9851f9ae8s" | ||
or branch.head == "9587100eacc554aa9c03422e28b269c551dc1a72" | ||
): | ||
commit = ( | ||
Check warning on line 14 in utils/temp_branch_fix.py Codecov / codecov/patchutils/temp_branch_fix.py#L14
Check warning on line 14 in utils/temp_branch_fix.py Codecov Public QA / codecov/patchutils/temp_branch_fix.py#L14
Check warning on line 14 in utils/temp_branch_fix.py Codecov - Staging / codecov/patchutils/temp_branch_fix.py#L14
|
||
commits.filter(branch=branch.name, repoid=repoid) | ||
.defer("_report") | ||
.order_by("-updatestamp") | ||
.first() | ||
) | ||
|
||
if commit is None: | ||
return None | ||
Check warning on line 22 in utils/temp_branch_fix.py Codecov / codecov/patchutils/temp_branch_fix.py#L21-L22
Check warning on line 22 in utils/temp_branch_fix.py Codecov Public QA / codecov/patchutils/temp_branch_fix.py#L21-L22
Check warning on line 22 in utils/temp_branch_fix.py Codecov - Staging / codecov/patchutils/temp_branch_fix.py#L21-L22
|
||
|
||
# using this raw sql because the current branches table does not allow for updating based on repoid | ||
# it only updates based on branch name which means if we were to use the django orm to update this | ||
# branch.head, all branches with the same name as the one we are trying to update would have their head | ||
# updated to the value of this ones head | ||
with connection.cursor() as cursor: | ||
cursor.execute( | ||
Check warning on line 29 in utils/temp_branch_fix.py Codecov / codecov/patchutils/temp_branch_fix.py#L28-L29
Check warning on line 29 in utils/temp_branch_fix.py Codecov Public QA / codecov/patchutils/temp_branch_fix.py#L28-L29
Check warning on line 29 in utils/temp_branch_fix.py Codecov - Staging / codecov/patchutils/temp_branch_fix.py#L28-L29
|
||
"UPDATE branches SET head = %s WHERE branches.repoid = %s AND branches.branch = %s", | ||
[commit.commitid, repoid, branch.name], | ||
) | ||
|
||
commit_sha = commit.commitid | ||
return commit_sha | ||
Check warning on line 35 in utils/temp_branch_fix.py Codecov / codecov/patchutils/temp_branch_fix.py#L34-L35
Check warning on line 35 in utils/temp_branch_fix.py Codecov Public QA / codecov/patchutils/temp_branch_fix.py#L34-L35
Check warning on line 35 in utils/temp_branch_fix.py Codecov - Staging / codecov/patchutils/temp_branch_fix.py#L34-L35
|
||
|
||
else: | ||
return branch.head |