Skip to content

Commit 507ac7f

Browse files
authored
Merge pull request #89 from saadmk11/use-regex
Use `regex.sub` to replace old versions with new ones
2 parents 9a41457 + 7658202 commit 507ac7f

1 file changed

Lines changed: 19 additions & 11 deletions

File tree

src/main.py

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import re
12
from collections.abc import Generator
23
from functools import cache, cached_property
34
from typing import Any
@@ -169,8 +170,12 @@ def _update_workflow(self, workflow_path: str) -> set[str]:
169170
gha_utils.echo(
170171
f'Updating "{action}" with "{updated_action}"...'
171172
)
172-
updated_workflow_data = updated_workflow_data.replace(
173-
action, updated_action
173+
updated_workflow_data = re.sub(
174+
rf"({action})(\s+|$)",
175+
rf"{updated_action}\2",
176+
updated_workflow_data,
177+
0,
178+
re.MULTILINE,
174179
)
175180
else:
176181
gha_utils.echo(f'No updates found for "{action_repository}"')
@@ -213,7 +218,9 @@ def _generate_updated_item_markdown(
213218
f"branch on {version_data['commit_date']}\n"
214219
)
215220

216-
def _get_github_releases(self, action_repository: str) -> list[dict[str, Any]]:
221+
def _get_github_releases(
222+
self, action_repository: str
223+
) -> list[dict[str, str | Version | LegacyVersion]]:
217224
"""Get the GitHub releases using GitHub API"""
218225
url = f"{self.github_api_url}/repos/{action_repository}/releases?per_page=50"
219226

@@ -261,22 +268,23 @@ def _release_filter_function(self):
261268
checks = []
262269

263270
if ReleaseType.MAJOR in self.user_config.release_types:
264-
checks.append(lambda r, c: r["tag_name_parsed"].major > c.major)
271+
checks.append(lambda r, c: r.major > c.major)
265272

266273
if ReleaseType.MINOR in self.user_config.release_types:
267274
checks.append(
268-
lambda r, c: r["tag_name_parsed"].major == c.major
269-
and r["tag_name_parsed"].minor > c.minor,
275+
lambda r, c: r.major == c.major and r.minor > c.minor,
270276
)
271277

272278
if ReleaseType.PATCH in self.user_config.release_types:
273279
checks.append(
274-
lambda r, c: r["tag_name_parsed"].major == c.major
275-
and r["tag_name_parsed"].minor == c.minor
276-
and r["tag_name_parsed"].micro > c.micro
280+
lambda r, c: r.major == c.major
281+
and r.minor == c.minor
282+
and r.micro > c.micro
277283
)
278284

279-
def filter_func(release_tag: str, current_version: Version) -> bool:
285+
def filter_func(
286+
release_tag: LegacyVersion | Version, current_version: Version
287+
) -> bool:
280288
return any(check(release_tag, current_version) for check in checks)
281289

282290
return filter_func
@@ -305,7 +313,7 @@ def _get_latest_version_release(
305313
latest_release = next(
306314
filter(
307315
lambda r: self._release_filter_function(
308-
r, parsed_current_version
316+
r["tag_name_parsed"], parsed_current_version
309317
),
310318
github_releases,
311319
),

0 commit comments

Comments
 (0)