-
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
Merged
Merged
Changes from 5 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
4b6c28d
Add filter condition to update less often
adrian-codecov 08416b3
Adjust logic
adrian-codecov cfa3d82
Merge branch 'main' of github.com:codecov/codecov-api into 3171-gh-we…
adrian-codecov 4f2558a
remove makefile change
adrian-codecov 4d4741b
Add suggestions
adrian-codecov 2f0dbaf
lint hello?
adrian-codecov File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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,42 +240,33 @@ 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( | ||
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 = 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=pushed_to_branch_name, merged=True) | ||
log.info( | ||
"Pushed commits to default branch; setting merged to True", | ||
f"Branch name updated for commits to {pushed_to_branch_name}; setting merged to True", | ||
extra=dict( | ||
repoid=repo.repoid, | ||
github_webhook_event=self.event, | ||
commits=[commit.get("id") for commit in commits], | ||
), | ||
) | ||
|
||
log.info( | ||
f"Branch name updated for commits to {branch_name}", | ||
extra=dict( | ||
repoid=repo.repoid, | ||
github_webhook_event=self.event, | ||
commits=[commit.get("id") for commit in commits], | ||
), | ||
) | ||
|
||
most_recent_commit = commits[-1] | ||
|
||
if regexp_ci_skip(most_recent_commit.get("message")): | ||
|
@@ -300,7 +292,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, | ||
) | ||
|
||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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