Skip to content
Draft

push #5181

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
28 changes: 22 additions & 6 deletions demisto_sdk/commands/content_graph/commands/update.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@
def should_update_graph(
content_graph_interface: ContentGraphInterface,
use_git: bool,
git_util: GitUtil,
git_util: Optional[GitUtil],
imported_path: Optional[Path] = None,
packs_to_update: Optional[List[str]] = None,
):
if content_graph_interface.commit:
if content_graph_interface.commit and git_util:
try:
changed_pack_ids = git_util.get_all_changed_pack_ids(
content_graph_interface.commit
Expand Down Expand Up @@ -97,14 +97,25 @@ def update_content_graph(
logger.info("A path to import the graph from was not provided, using git")
use_git = True

git_util = GitUtil()
is_external_repo = is_external_repository()
try:
git_util = GitUtil()
is_external_repo = is_external_repository()
except Exception as e:
logger.debug(
f"Could not initialize GitUtil: {e}. Assuming external repo and skipping git operations."
)
# If git is not available, we can't use git-based updates
# This can happen in CI/CD environments where the working directory is not a git repo
use_git = False
git_util = None # type: ignore[assignment]
is_external_repo = True

if is_external_repo:
packs_to_update = get_all_repo_pack_ids()
packs_to_update = list(packs_to_update) if packs_to_update else []
builder = ContentGraphBuilder(content_graph_interface)
if not should_update_graph(
# If git_util is None, we can't check if we should update, so assume we should not
if git_util and not should_update_graph(
content_graph_interface, use_git, git_util, imported_path, packs_to_update
):
logger.info(
Expand Down Expand Up @@ -145,7 +156,12 @@ def update_content_graph(
content_graph_interface, marketplace, dependencies, output_path
)
return
if use_git and (commit := content_graph_interface.commit) and not is_external_repo:
if (
use_git
and git_util
and (commit := content_graph_interface.commit)
and not is_external_repo
):
try:
git_util.get_all_changed_pack_ids(commit)
except Exception as e:
Expand Down
4 changes: 3 additions & 1 deletion demisto_sdk/commands/validate/initializer.py
Original file line number Diff line number Diff line change
Expand Up @@ -743,7 +743,9 @@ def git_paths_to_basecontent_set(
old_path = file_path
if isinstance(file_path, tuple):
file_path, old_path = file_path
obj = BaseContent.from_path(file_path, raise_on_exception=True)
obj = BaseContent.from_path(
file_path, git_sha=None, raise_on_exception=True
)
if obj:
obj.git_sha = current_git_sha
obj.git_status = git_status
Expand Down
11 changes: 7 additions & 4 deletions demisto_sdk/commands/validate/validators/base_validator.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,10 +176,13 @@ def graph(self) -> ContentGraphInterface:
if not self.graph_interface:
logger.info("Graph validations were selected, will init graph")
BaseValidator.graph_interface = ContentGraphInterface()
update_content_graph(
BaseValidator.graph_interface,
use_git=True,
)
# Only update the graph if it's not already alive/initialized
# This prevents re-running git operations that may fail in CI/CD environments
if not BaseValidator.graph_interface.is_alive():
update_content_graph(
BaseValidator.graph_interface,
use_git=True,
)
return self.graph_interface

def __dir__(self):
Expand Down
Loading