-
Notifications
You must be signed in to change notification settings - Fork 29
Add filter condition to update less often #1080
Changes from 1 commit
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 |
|---|---|---|
|
|
@@ -48,7 +48,7 @@ lint.install: | |
| pip install -Iv ruff | ||
|
|
||
| lint.run: | ||
| ruff check | ||
| ruff check --fix | ||
| ruff format | ||
|
|
||
| lint.check: | ||
|
|
||
| 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: | ||
|
Contributor
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.
Contributor
Author
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( | ||
|
|
@@ -265,9 +267,11 @@ def push(self, request, *args, **kwargs): | |
| commits=[commit.get("id") for commit in commits], | ||
| ), | ||
| ) | ||
| else: | ||
|
||
| commits_queryset.update(branch=pushed_to_branch_name) | ||
|
|
||
| log.info( | ||
| f"Branch name updated for commits to {branch_name}", | ||
| f"Branch name updated for commits to {pushed_to_branch_name}", | ||
| extra=dict( | ||
|
||
| repoid=repo.repoid, | ||
| github_webhook_event=self.event, | ||
|
|
@@ -300,7 +304,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