Skip to content

Git sync fixes#664

Open
jayapradha-p wants to merge 5 commits intomainfrom
GitSync_fixes
Open

Git sync fixes#664
jayapradha-p wants to merge 5 commits intomainfrom
GitSync_fixes

Conversation

@jayapradha-p
Copy link
Copy Markdown
Contributor

@jayapradha-p jayapradha-p commented Apr 6, 2026

GitSync QA fixes

Please use a clear and concise title that summarizes your changes.
If this PR is related to an internal Buganizer ticket, please include its ID at the beginning.

Convention: [Optional Buganizer ID: 123456789] Short, descriptive title of changes

Examples:

  • Fix: Resolve issue with API endpoint returning 500 error
  • [Buganizer ID: 987654321] Feature: Add support for custom data types
  • Docs: Update README with installation instructions

Description

Please provide a detailed description of your changes. This helps reviewers understand your work and its context.

What problem does this PR solve?
(e.g., "Fixes a bug where X was happening," "Implements feature Y to allow Z," "Improves performance of function A.")

How does this PR solve the problem?
(e.g., "Modified algorithm in src/foo.js," "Added new component Bar.vue," "Updated dependency baz to version 1.2.3.")

Any other relevant information (e.g., design choices, tradeoffs, known issues):
(e.g., "Chose approach A over B due to performance considerations," "This change might affect X in certain edge cases," "Requires manual migration steps for existing users.")


Checklist:

Please ensure you have completed the following items before submitting your PR.
This helps us review your contribution faster and more efficiently.

General Checks:

  • I have read and followed the project's contributing.md guide.
  • My code follows the project's coding style guidelines.
  • I have performed a self-review of my own code.
  • My changes do not introduce any new warnings.
  • My changes pass all existing tests.
  • I have added new tests where appropriate to cover my changes. (If applicable)
  • I have updated the documentation where necessary (e.g., README, API docs). (If applicable)

Open-Source Specific Checks:

  • My changes do not introduce any Personally Identifiable Information (PII) or sensitive customer data.
  • My changes do not expose any internal-only code examples, configurations, or URLs.
  • All code examples, comments, and messages are generic and suitable for a public repository.
  • I understand that any internal context or sensitive details related to this work are handled separately in internal systems (Buganizer for Google team members).

For Google Team Members and Reviewers Only:

  • I have included the Buganizer ID in the PR title or description (e.g., "Internal Buganizer ID: 123456789" or "Related Buganizer: go/buganizer/123456789").
  • I have ensured that all internal discussions and PII related to this work remain in Buganizer.
  • I have tagged the PR with one or more labels that reflect the pull request purpose.

Screenshots (If Applicable)

If your changes involve UI or visual elements, please include screenshots or GIFs here.
Ensure any sensitive data is redacted or generalized.


Further Comments / Questions

Any additional comments, questions, or areas where you'd like specific feedback.


Note

Medium Risk
Touches core GitSync content push/pull/install flows and replaces many direct REST calls with TIPCommon 1P wrappers, which can change payload shapes and behavior across multiple asset types (workflows, instances, mappings, environments). Risk is mitigated by mostly being adapter-level changes, but failures could impact sync/install operations broadly.

Overview
GitSync is updated to better support 1P API migration by routing most platform operations through TIPCommon.rest.soar_api helpers and updating callers to pass chronicle_soar and handle new response/data-model shapes (e.g., integrations, jobs, connectors, playbooks, environments, tags/stages, lists, denylists, SLA, simulated cases).

Workflow syncing now supports Playbook Blocks as a first-class artifact: blocks are pushed into a new Blocks/ folder (GitContentManager.push_block, read support in get_playbook/get_playbooks), and push jobs (PushContent, PushPlaybook) detect WorkflowTypes.BLOCK and optionally export referenced blocks.

QA/robustness fixes include: improved README templating for varied parameter schemas, safer integration zip parsing (fallback .json definition, skip non-JSON files), more defensive handling of get_ide_cards formats, job install/push logic updated for displayName/duplicate detection, and simplifying Git.push() by removing stderr push-error parsing. Dependencies are bumped (GitSync 45.1, TIPCommon/integration-testing to 2.3.6, add setuptools).

Reviewed by Cursor Bugbot for commit c65b456. Bugbot is set up for automated code reviews on this repo. Configure here.

@jayapradha-p jayapradha-p requested review from a team as code owners April 6, 2026 07:29
@gemini-code-assist
Copy link
Copy Markdown
Contributor

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request introduces significant improvements to the GitSync functionality, primarily focusing on supporting 'Blocks' and refactoring API interactions to leverage the TIPCommon SDK. These changes enhance the reliability of Git sync operations and ensure better compatibility with the platform's API, while also addressing several bugs related to content synchronization and environment handling.

Highlights

  • GitSync Functionality Enhancements: Added support for 'Blocks' in GitSync, including new methods for pushing and retrieving block content.
  • API Integration Refactoring: Refactored SiemplifyApiClient to utilize the TIPCommon SDK for various operations, improving consistency and maintainability.
  • Bug Fixes and Stability: Implemented several fixes for Git sync operations, including improved error handling for push operations and better handling of integration card responses.
  • Dependency Updates: Updated project versions and dependencies, including TIPCommon and integration-testing packages to version 2.3.6.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request refactors the GitSync integration to support 1P migration by transitioning to TIPCommon.rest.soar_api for SOAR interactions and introducing support for "Blocks" as a content type. Key changes include a major overhaul of SiemplifyApiClient and GitSyncManager to utilize standardized API functions, updates to job scripts for compatibility with the new architecture, and enhancements to Jinja2 templates for README generation. Feedback identifies critical logic errors in job name matching and mapping pushes, a missing f-string prefix, and violations of the repository style guide regarding the use of pathlib and yaml.safe_load. Additionally, recommendations were made to remove unused imports and commented-out code, optimize function definitions within loops, and improve error handling by logging caught exceptions.

(
x
for x in self.api.get_jobs(chronicle_soar=self._siemplify)
if x.get("name") or x.get("displayName") == job.name
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

high

The logical condition x.get("name") or x.get("displayName") == job.name is incorrect. Because or has lower precedence than ==, and a non-empty string evaluates to True, this condition will always be truthy if x.get("name") exists, regardless of whether it matches job.name.

Suggested change
if x.get("name") or x.get("displayName") == job.name
if job.name in [x.get("name"), x.get("displayName")]

if source and source.lower() == integration.lower():
rules.append(rule)
break
gitsync.content.push_mapping(Mapping(source, records, rules))
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

high

There is a variable mismatch here. The loop iterates using the variable integration, but the Mapping object is being instantiated using the source parameter from the job. This will likely result in incorrect data being pushed for each integration in the loop.

Suggested change
gitsync.content.push_mapping(Mapping(source, records, rules))
gitsync.content.push_mapping(Mapping(integration, records, rules))

return Workflow(json.loads(playbook.content))
for block in self.git.get_file_objects_from_path(BLOCKS_PATH):
if block.path.endswith(f"/{playbook_name}.json"):
return Workflow(json.loads(block.content))
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

The repository style guide explicitly mandates the use of yaml.safe_load() instead of json.loads() to prevent potential security vulnerabilities related to arbitrary code execution, even when handling JSON data.

References
  1. Use yaml.safe_load() instead of yaml.load() and json.loads() to prevent arbitrary code execution. (link)

block,
block.name,
"Block",
f"{BLOCKS_PATH}/{block.category}/{block.name}",
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

The style guide requires using pathlib.Path for all file system operations and prohibits raw string concatenation for path construction. Please refactor this to use the / operator with Path objects.

Suggested change
f"{BLOCKS_PATH}/{block.category}/{block.name}",
Path(BLOCKS_PATH) / block.category / block.name,
References
  1. Always use pathlib.Path for file system operations. Do not use raw string concatenation or os.path.join. (link)

else:
self.logger.warning(
"Unexpected response format from get_ide_cards "
"for integration '{integration.identifier}'. "
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

The variable {integration.identifier} is placed within a single-quoted string that lacks the f prefix. Consequently, the variable will not be interpolated, and the literal string will be logged.

Suggested change
"for integration '{integration.identifier}'. "
f"for integration '{integration.identifier}'. "

Comment on lines +73 to +75
# current_parameters = gitsync.api.get_env_dynamic_parameters(chronicle_soar=siemplify)

# current_by_name = {p.get("name"): p for p in current_parameters}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

Avoid leaving commented-out code in the repository. This reduces readability and can lead to confusion for future maintainers.

Comment on lines +82 to +94
def get_fields(rule):
"""Extract iterable fields from either response format."""
if "familyFields" in rule or "systemFields" in rule:
return rule.get("familyFields", []) + rule.get("systemFields", [])
elif "mapping_rules" in rule:
return rule.get("mapping_rules", [])
return []

def get_mapping_rule(r, rule):
"""Get the mappingRule dict from either format."""
if "mappingRule" in r:
return r["mappingRule"]
return r
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

Defining helper functions get_fields and get_mapping_rule inside a loop is inefficient as they are redefined in every iteration. These should be moved outside the loop or defined as static methods.

Comment on lines +18 to +19
import time
import threading
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

The imports time and threading appear to be unused in this module and should be removed to keep the code clean.

Comment on lines +272 to +273
except json.JSONDecodeError:
pass
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

Swallowing json.JSONDecodeError with a pass statement is discouraged. It hides potential issues with malformed integration files and makes debugging significantly harder. At a minimum, the error should be logged.

Copy link
Copy Markdown

@cursor cursor Bot left a comment

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 5 potential issues.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit c65b456. Configure here.

(
x
for x in self.api.get_jobs(chronicle_soar=self._siemplify)
if x.get("name") or x.get("displayName") == job.name
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Operator precedence causes wrong job matching logic

High Severity

The condition x.get("name") or x.get("displayName") == job.name is incorrect due to Python operator precedence. It evaluates as (x.get("name")) or (x.get("displayName") == job.name), meaning any job with a non-empty "name" field is treated as truthy and matches. This causes the next() call to always return the first job in the list, regardless of whether it actually matches job.name. The correct expression is x.get("name") == job.name or x.get("displayName") == job.name.

Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit c65b456. Configure here.

self._define_workflow_as_new(workflow)
self._process_steps(workflow)
self.api.save_playbook(workflow.raw_data)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Missing chronicle_soar parameter in get_playbook call

High Severity

self.api.get_playbook(playbook_id) passes the playbook identifier as the chronicle_soar parameter, since the get_playbook method signature was changed in this PR to require chronicle_soar as the first positional argument followed by identifier. This call site was not updated, so playbook_id is passed as chronicle_soar and identifier is missing entirely, causing a TypeError at runtime when updating existing workflows.

Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit c65b456. Configure here.

if source and source.lower() == integration.lower():
rules.append(rule)
break
gitsync.content.push_mapping(Mapping(source, records, rules))
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Variable source shadowed, wrong value used in Mapping

High Severity

The source variable (originally the job parameter from extract_job_param) is overwritten at line 75 by source = mapping_rule.get("source") inside the inner loop. Then Mapping(source, records, rules) at line 79 uses this overwritten value instead of integration (the outer loop variable). The analogous code in PushContent.py correctly uses Mapping(integration, records, rules). The overwritten source also corrupts the set_readme_addon call at line 85.

Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit c65b456. Configure here.

else:
self.logger.warning(
"Unexpected response format from get_ide_cards "
"for integration '{integration.identifier}'. "
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Missing f-string prefix causes literal interpolation braces

Low Severity

The string "for integration '{integration.identifier}'. " is missing the f prefix, so {integration.identifier} will be rendered literally in the log message instead of being interpolated. The subsequent string on line 248 has the f prefix, but this one does not.

Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit c65b456. Configure here.

if block_definition:
block = Workflow(block_definition)
block.update_instance_name_in_steps(gitsync.api, siemplify)
gitsync.content.push_block(block)
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Workflow created from step dict causes crash

Medium Severity

When a block is not found in installed playbooks, block_definition is set to block_step (a workflow step dict). Then Workflow(block_definition) is called, but Workflow.__init__ expects a full workflow definition with keys like trigger and modificationTimeUnixTimeInMs. A step dict lacks these, causing a KeyError or TypeError. The equivalent code in PushContent.py correctly uses continue instead.

Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit c65b456. Configure here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants