-
Notifications
You must be signed in to change notification settings - Fork 28
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
Add filter condition to update less often #1080
Changes from 4 commits
4b6c28d
08416b3
cfa3d82
4f2558a
4d4741b
2f0dbaf
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,7 @@ | |
from hashlib import sha1, sha256 | ||
from typing import Optional | ||
|
||
from django.db.models import Q | ||
from django.utils import timezone | ||
from django.utils.crypto import constant_time_compare | ||
from rest_framework import status | ||
|
@@ -239,24 +240,25 @@ def push(self, request, *args, **kwargs): | |
) | ||
return Response(data=WebhookHandlerErrorMessages.SKIP_WEBHOOK_IGNORED) | ||
|
||
branch_name = self.request.data.get("ref")[11:] | ||
pushed_to_branch_name = self.request.data.get("ref")[11:] | ||
commits = self.request.data.get("commits", []) | ||
|
||
if not commits: | ||
log.debug( | ||
f"No commits in webhook payload for branch {branch_name}", | ||
f"No commits in webhook payload for branch {pushed_to_branch_name}", | ||
extra=dict(repoid=repo.repoid, github_webhook_event=self.event), | ||
) | ||
return Response() | ||
|
||
commits_queryset = Commit.objects.filter( | ||
~Q(branch=pushed_to_branch_name), | ||
repository=repo, | ||
commitid__in=[commit.get("id") for commit in commits], | ||
merged=False, | ||
) | ||
commits_queryset.update(branch=branch_name) | ||
if branch_name == repo.branch: | ||
commits_queryset.update(merged=True) | ||
|
||
if pushed_to_branch_name == repo.branch: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For more optimization, we can probably also call this before querying. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. donee |
||
commits_queryset.update(branch=pushed_to_branch_name, merged=True) | ||
log.info( | ||
"Pushed commits to default branch; setting merged to True", | ||
extra=dict( | ||
|
@@ -267,7 +269,7 @@ def push(self, request, *args, **kwargs): | |
) | ||
|
||
log.info( | ||
f"Branch name updated for commits to {branch_name}", | ||
f"Branch name updated for commits to {pushed_to_branch_name}", | ||
extra=dict( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This will probably also need to be in the if statement now. We're not updating the branch if it's not the default branch. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Pushed and consolidated into 1 log |
||
repoid=repo.repoid, | ||
github_webhook_event=self.event, | ||
|
@@ -300,7 +302,7 @@ def push(self, request, *args, **kwargs): | |
TaskService().status_set_pending( | ||
repoid=repo.repoid, | ||
commitid=most_recent_commit.get("id"), | ||
branch=branch_name, | ||
branch=pushed_to_branch_name, | ||
on_a_pull_request=False, | ||
) | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Had to change branch name for these commits to non-default branch names for the test to make sense - I believe it originally wasn't working as intended