Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions check_resource_updates.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from main import get_app
from src.config import RevancedConfig
from src.manager.github import GitHubManager
from src.utils import default_build, integration_version_key, patches_version_key
from src.utils import default_build, integration_version_key, integrations_dl_key, patches_dl_key, patches_version_key


def check_if_build_is_required() -> bool:
Expand All @@ -19,14 +19,20 @@ def check_if_build_is_required() -> bool:
logger.info(f"Checking {app_name}")
app_obj = get_app(config, app_name)
old_integration_version = GitHubManager(env).get_last_version(app_obj, integration_version_key)
old_integration_source = GitHubManager(env).get_last_version_source(app_obj, integrations_dl_key)
old_patches_version = GitHubManager(env).get_last_version(app_obj, patches_version_key)
old_patches_source = GitHubManager(env).get_last_version_source(app_obj, patches_dl_key)
Comment on lines +22 to +24

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion (testing): Missing test cases for new source comparison logic in build triggers.

The changes include new logic to compare sources for integrations and patches to decide on triggering builds. It's crucial to add tests that verify this new functionality works as expected and handles edge cases, such as when sources are identical or when one is null.

Suggested change
old_integration_source = GitHubManager(env).get_last_version_source(app_obj, integrations_dl_key)
old_patches_version = GitHubManager(env).get_last_version(app_obj, patches_version_key)
old_patches_source = GitHubManager(env).get_last_version_source(app_obj, patches_dl_key)
github_manager = GitHubManager(env)
old_integration_source = github_manager.get_last_version_source(app_obj, integrations_dl_key)
old_patches_version = github_manager.get_last_version(app_obj, patches_version_key)
old_patches_source = github_manager.get_last_version_source(app_obj, patches_dl_key)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this comment correct?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this comment helpful?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the comment type correct?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the comment area correct?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What type of LLM test could this comment become?

  • 👍 - this comment is really good/important and we should always make it
  • 👎 - this comment is really bad and we should never make it
  • no reaction - don't turn this comment into an LLM test

app_obj.download_patch_resources(config)
if GitHubManager(env).should_trigger_build(
old_integration_version,
old_integration_source,
app_obj.resource["integrations"]["version"],
app_obj.patches_dl,
) or GitHubManager(env).should_trigger_build(
old_patches_version,
old_patches_source,
app_obj.resource["patches"]["version"],
app_obj.integrations_dl,
):
caused_by = {
"app_name": app_name,
Expand All @@ -42,7 +48,7 @@ def check_if_build_is_required() -> bool:
logger.info(f"New build can be triggered caused by {caused_by}")
needs_to_repatched.append(app_name)
logger.info(f"{needs_to_repatched} are need to repatched.")
if len(needs_to_repatched) > 0:
if needs_to_repatched:
print(",".join(needs_to_repatched)) # noqa: T201
return True
return False
Expand Down
14 changes: 13 additions & 1 deletion src/manager/github.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

from src.app import APP
from src.manager.release_manager import ReleaseManager
from src.utils import branch_name, updates_file, updates_file_url
from src.utils import app_dump_key, branch_name, updates_file, updates_file_url


class GitHubManager(ReleaseManager):
Expand All @@ -34,3 +34,15 @@ def get_last_version(self: Self, app: APP, resource_name: str) -> str:
if data.get(app.app_name):
return str(data[app.app_name][resource_name])
return "0"

def get_last_version_source(self: Self, app: APP, resource_name: str) -> str:
"""Get last patched version."""
if os.getenv("DRY_RUN", default=None):
with Path(updates_file).open() as url:
data = json.load(url)
else:
with urllib.request.urlopen(self.update_file_url) as url:
data = json.load(url)
if data.get(app.app_name):
return str(data[app.app_name][app_dump_key][resource_name])
Comment on lines +38 to +47

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion (code_refinement): Consider handling exceptions for JSON operations.

Loading JSON data can fail due to malformed data or I/O issues. It's advisable to wrap the json.load calls in a try-except block to handle potential exceptions and maintain robustness.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this comment correct?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this comment helpful?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the comment type correct?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the comment area correct?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What type of LLM test could this comment become?

  • 👍 - this comment is really good/important and we should always make it
  • 👎 - this comment is really bad and we should never make it
  • no reaction - don't turn this comment into an LLM test

return "0"
5 changes: 4 additions & 1 deletion src/manager/release_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,11 @@ def get_last_version(self: Self, app: APP, resource_name: str) -> str:
"""Get last patched version."""
raise NotImplementedError

def should_trigger_build(self: Self, old_version: str, new_version: str) -> bool:
def should_trigger_build(self: Self, old_version: str, old_source: str, new_version: str, new_source: str) -> bool:
"""Function to check if we should trigger a build."""
if old_source != new_source:
logger.info(f"Trigger build because old source {old_source}, is different from new source {new_source}")
return True
Comment on lines +18 to +22

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion (code_refinement): Refactor 'should_trigger_build' to reduce complexity.

The method now handles multiple conditions and logging, which increases its complexity. Consider breaking down the functionality into smaller, more manageable methods.

Suggested change
def should_trigger_build(self: Self, old_version: str, old_source: str, new_version: str, new_source: str) -> bool:
"""Function to check if we should trigger a build."""
if old_source != new_source:
logger.info(f"Trigger build because old source {old_source}, is different from new source {new_source}")
return True
def should_trigger_build(self: Self, old_version: str, old_source: str, new_version: str, new_source: str) -> bool:
"""Function to check if we should trigger a build."""
if self._is_source_changed(old_source, new_source):
return True
def _is_source_changed(self, old_source: str, new_source: str) -> bool:
if old_source != new_source:
logger.info(f"Trigger build because old source {old_source}, is different from new source {new_source}")
return True
return False

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this comment correct?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this comment helpful?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the comment type correct?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the comment area correct?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What type of LLM test could this comment become?

  • 👍 - this comment is really good/important and we should always make it
  • 👎 - this comment is really bad and we should never make it
  • no reaction - don't turn this comment into an LLM test

Comment on lines +18 to +22

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion (testing): Consider adding tests for the updated should_trigger_build method.

This method now includes additional parameters and logic for source comparison. Ensure there are tests that cover various scenarios, including cases where versions are the same but sources differ, and vice versa.

Suggested change
def should_trigger_build(self: Self, old_version: str, old_source: str, new_version: str, new_source: str) -> bool:
"""Function to check if we should trigger a build."""
if old_source != new_source:
logger.info(f"Trigger build because old source {old_source}, is different from new source {new_source}")
return True
def should_trigger_build(self: Self, old_version: str, old_source: str, new_version: str, new_source: str) -> bool:
"""Function to check if we should trigger a build."""
if old_source != new_source:
logger.info(f"Trigger build because old source {old_source} is different from new source {new_source}")
return True

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this comment correct?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this comment helpful?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the comment type correct?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the comment area correct?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What type of LLM test could this comment become?

  • 👍 - this comment is really good/important and we should always make it
  • 👎 - this comment is really bad and we should never make it
  • no reaction - don't turn this comment into an LLM test

logger.info(f"New version {new_version}, Old version {old_version}")
try:
return Version(new_version) > Version(old_version) # type: ignore[no-any-return]
Expand Down
3 changes: 3 additions & 0 deletions src/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@
status_code_200 = 200
resource_folder = "apks"
branch_name = "changelogs"
app_dump_key = "app_dump"
patches_dl_key = "patches_dl"
integrations_dl_key = "integrations_dl"


def update_changelog(name: str, response: dict[str, str]) -> None:
Expand Down