Skip to content
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

[Pre-Commit] Continue Even if Fetch Failed #3878

Merged
merged 11 commits into from
Jan 30, 2024

Conversation

MichaelYochpaz
Copy link
Contributor

@MichaelYochpaz MichaelYochpaz commented Dec 19, 2023

Related Issues

fixes: https://jira-dc.paloaltonetworks.com/browse/CIAC-9231

Description

Fix an issue (visible mainly on pre-commit) where if fetching from git fails due to connection problems, the whole command fails, even though it should be able to continue (just won't run fully up-to-date)

Screenshot 2023-12-19 at 17 59 36

@GuyAfik
Copy link
Contributor

GuyAfik commented Dec 19, 2023

@MichaelYochpaz does it fail because of connection errors? if yes lets use the retry decorator (you can find it in tools.py)

@MichaelYochpaz MichaelYochpaz changed the title Add try and except blocks [Pre-Commit] Continue Even if Fetch Failed Dec 19, 2023
@MichaelYochpaz MichaelYochpaz force-pushed the pre-commit-continue-on-fetch-failure branch from b085333 to 042c44c Compare January 17, 2024 15:58
@coveralls
Copy link
Collaborator

coveralls commented Jan 17, 2024

Pull Request Test Coverage Report for Build 4331656b-3878-4fbb-8ccd-6e87677beba6

  • 3 of 6 (50.0%) changed or added relevant lines in 1 file are covered.
  • 8023 unchanged lines in 291 files lost coverage.
  • Overall coverage decreased (-18.3%) to 80.583%

Changes Missing Coverage Covered Lines Changed/Added Lines %
demisto_sdk/commands/common/git_util.py 3 6 50.0%
Files with Coverage Reduction New Missed Lines %
demisto_sdk/commands/common/clients/configs.py 1 97.14%
demisto_sdk/commands/common/content/objects/pack_objects/incident_field/incident_field.py 1 65.0%
demisto_sdk/commands/common/content/objects/pack_objects/job/job.py 1 83.33%
demisto_sdk/commands/common/content/objects/pack_objects/lists/lists.py 1 85.71%
demisto_sdk/commands/common/files/errors.py 1 71.43%
demisto_sdk/commands/common/files/text_file.py 1 78.13%
demisto_sdk/commands/common/hook_validations/deprecation.py 1 98.72%
demisto_sdk/commands/common/hook_validations/job.py 1 98.41%
demisto_sdk/commands/common/hook_validations/layout_rule.py 1 88.89%
demisto_sdk/commands/common/hook_validations/lists.py 1 96.55%
Totals Coverage Status
Change from base Build 7694890770: -18.3%
Covered Lines: 35762
Relevant Lines: 44379

💛 - Coveralls

@GuyAfik
Copy link
Contributor

GuyAfik commented Jan 22, 2024

@MichaelYochpaz see my comment here

@ilaner is there a reason not to continue if fetch fails?

@MichaelYochpaz
Copy link
Contributor Author

MichaelYochpaz commented Jan 28, 2024

@MichaelYochpaz does it fail because of connection errors? if yes lets use the retry decorator (you can find it in tools.py)
This PR is for a case where there is no connection to GitHub for some reason (like firewall issues), to allow the pre-commit flow to continue even without fetching.

@GuyAfik Adding a retry mechanism for a different case (where it's an issue that might be fixed on a retry), is a good idea, but handles a different case.

Current code handles a case where there is no connection at all (like firewall issues, where retrying won't help).
But we can do retries first, and then if they all failed, skip the fetch. Will probably be better than the current code with no retries.

However, it's going to be problematic as the retry wrapper is in the tools module, which imports the git_util module that contains the fetch method. So this will cause circular imports issues.
The updated code would look like:

class GitUtil:

    @retry(times=3, exceptions=(ConnectionError, Timeout))
    @lru_cache
    def fetch(self):
        self.repo.remote().fetch()
...

We can create a new module (that doesn't have any internal imports, like constants and logger) and move the retry wrapper there if you think that's a good idea.

@MichaelYochpaz MichaelYochpaz force-pushed the pre-commit-continue-on-fetch-failure branch from 0169feb to 741a85c Compare January 28, 2024 11:57
.changelog/3878.yml Outdated Show resolved Hide resolved
.changelog/3878.yml Outdated Show resolved Hide resolved
demisto_sdk/commands/common/git_util.py Outdated Show resolved Hide resolved
Copy link
Contributor

@ilaner ilaner left a comment

Choose a reason for hiding this comment

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

good job

@MichaelYochpaz MichaelYochpaz merged commit 411b244 into master Jan 30, 2024
32 checks passed
@MichaelYochpaz MichaelYochpaz deleted the pre-commit-continue-on-fetch-failure branch January 30, 2024 13:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
4 participants