Skip to content
This repository was archived by the owner on Jun 13, 2025. It is now read-only.

Commit 8660eab

Browse files
Add filter condition to update less often (#1080)
1 parent 902a5cb commit 8660eab

File tree

10 files changed

+38
-40
lines changed

10 files changed

+38
-40
lines changed

api/internal/owner/serializers.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ def validate_value(self, value):
136136
extra=dict(owner_id=current_owner.pk, plan=value),
137137
)
138138
raise serializers.ValidationError(
139-
f"Invalid value for plan: {value}; " f"must be one of {plan_values}"
139+
f"Invalid value for plan: {value}; must be one of {plan_values}"
140140
)
141141
return value
142142

codecov_auth/commands/owner/interactors/set_yaml_on_owner.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,9 @@ def convert_yaml_to_dict(self, yaml_input: str) -> Optional[dict]:
4242
except yaml.scanner.ScannerError as e:
4343
line = e.problem_mark.line
4444
column = e.problem_mark.column
45-
message = f"Syntax error at line {line+1}, column {column+1}: {e.problem}"
45+
message = (
46+
f"Syntax error at line {line + 1}, column {column + 1}: {e.problem}"
47+
)
4648
raise ValidationError(message)
4749
if not yaml_dict:
4850
return None

codecov_auth/commands/owner/interactors/tests/test_set_yaml_on_owner.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ async def test_user_is_part_of_org_and_yaml_is_good(self):
9696
"codecov": {
9797
"require_ci_to_pass": True,
9898
},
99-
"to_string": "\n" "codecov:\n" " require_ci_to_pass: yes\n",
99+
"to_string": "\ncodecov:\n require_ci_to_pass: yes\n",
100100
}
101101

102102
async def test_user_is_part_of_org_and_yaml_has_quotes(self):
@@ -109,7 +109,7 @@ async def test_user_is_part_of_org_and_yaml_has_quotes(self):
109109
"codecov": {
110110
"bot": "codecov",
111111
},
112-
"to_string": "\n" "codecov:\n" " bot: 'codecov'\n",
112+
"to_string": "\ncodecov:\n bot: 'codecov'\n",
113113
}
114114

115115
async def test_user_is_part_of_org_and_yaml_is_empty(self):

services/tests/test_comparison.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1298,7 +1298,7 @@ def _report_lines(self, hits):
12981298
]
12991299

13001300
def _src(self, n):
1301-
return [f"line{i+1}" for i in range(n)]
1301+
return [f"line{i + 1}" for i in range(n)]
13021302

13031303
def setUp(self):
13041304
self.file_comparison = FileComparison(

upload/tokenless/appveyor.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ def verify(self):
4949
self.upload_params.get("job")
5050
if "/" in self.upload_params.get("job")
5151
else (
52-
f'{self.upload_params.get("owner")}/{self.upload_params.get("repo")}/{self.upload_params.get("job")}'
52+
f"{self.upload_params.get('owner')}/{self.upload_params.get('repo')}/{self.upload_params.get('job')}"
5353
)
5454
)
5555

upload/tokenless/cirrus.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ def get_build(self):
2626
}}
2727
}}",
2828
"variables": {{
29-
"buildId": {self.upload_params.get('build')}
29+
"buildId": {self.upload_params.get("build")}
3030
}}
3131
}}"""
3232

utils/test_utils.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,10 @@ def app(self):
4343
migrate_to = None
4444

4545
def setUp(self):
46-
assert (
47-
self.migrate_from and self.migrate_to
48-
), "TestCase '{}' must define migrate_from and migrate_to properties".format(
49-
type(self).__name__
46+
assert self.migrate_from and self.migrate_to, (
47+
"TestCase '{}' must define migrate_from and migrate_to properties".format(
48+
type(self).__name__
49+
)
5050
)
5151
self.migrate_from = [(self.app, self.migrate_from)]
5252
self.migrate_to = [(self.app, self.migrate_to)]

webhook_handlers/tests/test_github.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -266,17 +266,19 @@ def test_push_updates_only_unmerged_commits_with_branch_name(self):
266266
commit2.refresh_from_db()
267267
merged_commit.refresh_from_db()
268268

269-
assert commit1.branch == unmerged_branch_name
270-
assert commit2.branch == unmerged_branch_name
271269
assert not commit1.merged
272270
assert not commit2.merged
273271

274272
assert merged_commit.branch == merged_branch_name
275273

276274
@patch("redis.Redis.sismember", lambda x, y, z: False)
277275
def test_push_updates_commit_on_default_branch(self):
278-
commit1 = CommitFactory(merged=False, repository=self.repo)
279-
commit2 = CommitFactory(merged=False, repository=self.repo)
276+
commit1 = CommitFactory(
277+
merged=False, repository=self.repo, branch="feature-branch"
278+
)
279+
commit2 = CommitFactory(
280+
merged=False, repository=self.repo, branch="feature-branch"
281+
)
280282

281283
merged_branch_name = "merged"
282284
repo_branch = self.repo.branch

webhook_handlers/tests/test_github_enterprise.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -222,17 +222,19 @@ def test_push_updates_only_unmerged_commits_with_branch_name(self):
222222
commit2.refresh_from_db()
223223
merged_commit.refresh_from_db()
224224

225-
assert commit1.branch == unmerged_branch_name
226-
assert commit2.branch == unmerged_branch_name
227225
assert not commit1.merged
228226
assert not commit2.merged
229227

230228
assert merged_commit.branch == merged_branch_name
231229

232230
@patch("redis.Redis.sismember", lambda x, y, z: False)
233231
def test_push_updates_commit_on_default_branch(self):
234-
commit1 = CommitFactory(merged=False, repository=self.repo)
235-
commit2 = CommitFactory(merged=False, repository=self.repo)
232+
commit1 = CommitFactory(
233+
merged=False, repository=self.repo, branch="feature-branch"
234+
)
235+
commit2 = CommitFactory(
236+
merged=False, repository=self.repo, branch="feature-branch"
237+
)
236238

237239
merged_branch_name = "merged"
238240
repo_branch = self.repo.branch

webhook_handlers/views/github.py

Lines changed: 13 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
from hashlib import sha1, sha256
66
from typing import Optional
77

8+
from django.db.models import Q
89
from django.utils import timezone
910
from django.utils.crypto import constant_time_compare
1011
from rest_framework import status
@@ -239,42 +240,33 @@ def push(self, request, *args, **kwargs):
239240
)
240241
return Response(data=WebhookHandlerErrorMessages.SKIP_WEBHOOK_IGNORED)
241242

242-
branch_name = self.request.data.get("ref")[11:]
243+
pushed_to_branch_name = self.request.data.get("ref")[11:]
243244
commits = self.request.data.get("commits", [])
244245

245246
if not commits:
246247
log.debug(
247-
f"No commits in webhook payload for branch {branch_name}",
248+
f"No commits in webhook payload for branch {pushed_to_branch_name}",
248249
extra=dict(repoid=repo.repoid, github_webhook_event=self.event),
249250
)
250251
return Response()
251252

252-
commits_queryset = Commit.objects.filter(
253-
repository=repo,
254-
commitid__in=[commit.get("id") for commit in commits],
255-
merged=False,
256-
)
257-
commits_queryset.update(branch=branch_name)
258-
if branch_name == repo.branch:
259-
commits_queryset.update(merged=True)
253+
if pushed_to_branch_name == repo.branch:
254+
commits_queryset = Commit.objects.filter(
255+
~Q(branch=pushed_to_branch_name),
256+
repository=repo,
257+
commitid__in=[commit.get("id") for commit in commits],
258+
merged=False,
259+
)
260+
commits_queryset.update(branch=pushed_to_branch_name, merged=True)
260261
log.info(
261-
"Pushed commits to default branch; setting merged to True",
262+
f"Branch name updated for commits to {pushed_to_branch_name}; setting merged to True",
262263
extra=dict(
263264
repoid=repo.repoid,
264265
github_webhook_event=self.event,
265266
commits=[commit.get("id") for commit in commits],
266267
),
267268
)
268269

269-
log.info(
270-
f"Branch name updated for commits to {branch_name}",
271-
extra=dict(
272-
repoid=repo.repoid,
273-
github_webhook_event=self.event,
274-
commits=[commit.get("id") for commit in commits],
275-
),
276-
)
277-
278270
most_recent_commit = commits[-1]
279271

280272
if regexp_ci_skip(most_recent_commit.get("message")):
@@ -300,7 +292,7 @@ def push(self, request, *args, **kwargs):
300292
TaskService().status_set_pending(
301293
repoid=repo.repoid,
302294
commitid=most_recent_commit.get("id"),
303-
branch=branch_name,
295+
branch=pushed_to_branch_name,
304296
on_a_pull_request=False,
305297
)
306298

0 commit comments

Comments
 (0)