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

Add support for add subcommand to scaffold devfile resources #305

Merged
merged 25 commits into from
Nov 7, 2024

Conversation

tanwigeetika1618
Copy link
Contributor

@tanwigeetika1618 tanwigeetika1618 commented Oct 18, 2024

JIRA ticket: https://issues.redhat.com/browse/AAP-27897
Related Issue : #148

Description:

This commit introduces a new add subcommand to the ansible-creator tool, allowing users to scaffold resources like devfile into an existing project. This feature is designed to streamline the development environment setup by automatically generating the necessary configuration files.

Changes:

  • Created add.py: Added the add subcommand to scaffold:
    • devfile resource setup
  • Updated config.py: Added new attributes to support the add subcommand:
    • resource_type: Specifies the resource type (e.g. devfile).
    • path: Defines the target path for the resource scaffolding.
    • type: Denotes the type of resource being scaffolded.

Unit Tests for add Subcommand:

  • Created test_add.py:

    • Added unit tests for the add subcommand in the units folder.
  • Test Functions:

    1. Successful Scaffolding: Validates that the add subcommand correctly scaffolds the devfile.yaml from the fixtures folder to the temporary path.
    2. Overwrite Scenario: Modifies the devfile.yaml content and checks the behavior of the overwrite parameter, ensuring that conflicts are handled appropriately during scaffolding.
  • Fixtures:

    • Added a devfile.yaml to the fixtures/common/devfile folder for testing purposes.

Notes:

Subcommand add Behavior:

  1. When the devfile.yaml is not present in the provided path:

    • The add subcommand scaffolds the devfile.yaml and outputs the message:
      • Note: Resource added to /path/to/directory
  2. When the devfile.yaml exists in the provided path with the same content:

    • If the devfile.yaml has not been altered (i.e., content matches the original file), the subcommand does not overwrite the file and outputs the same message:
      • Note: Resource added to /path/to/directory
  3. When the devfile.yaml exists in the provided path but has different content:

    • If the devfile.yaml has been modified, the subcommand detects the change and prompts:

      • Files in the destination directory will be overwritten. Do you want to proceed? (y/n)
    • If the user chooses 'y' (Yes):

      • The file is overwritten, and the message confirms the update:
        • Note: Resource added to /path/to/directory
    • If the user chooses 'n' (No):

      • The operation is aborted, and the following warning and error messages are shown:
        • Warning: /path/to/directory/devfile.yaml already exists
        • Files in the destination directory will be overwritten. Do you want to proceed? (y/n): n
        • Error: The destination directory contains files that will be overwritten. Please re-run ansible-creator with --overwrite to continue.
    • Using the --overwrite flag:

      • If the user runs the command with the --overwrite flag:
        • ansible-creator add resource devfile /path/to/directory --overwrite
      • The devfile.yaml is overwritten, and the message confirms successful scaffolding:
        • Note: Resource added to /path/to/directory
  • This PR enhances the existing functionality of the ansible-creator tool by making it easier to add development environment configurations to existing projects.

@tanwigeetika1618 tanwigeetika1618 added the enhancement New feature or request label Oct 18, 2024
@tanwigeetika1618 tanwigeetika1618 self-assigned this Oct 18, 2024
src/ansible_creator/subcommands/add.py Outdated Show resolved Hide resolved
tests/fixtures/common/devfile/devfile.yaml Outdated Show resolved Hide resolved
tests/fixtures/common/devfile/devfile.yaml Outdated Show resolved Hide resolved
@tanwigeetika1618 tanwigeetika1618 marked this pull request as ready for review October 23, 2024 11:50
@tanwigeetika1618 tanwigeetika1618 requested a review from a team as a code owner October 23, 2024 11:50
src/ansible_creator/arg_parser.py Outdated Show resolved Hide resolved
src/ansible_creator/subcommands/add.py Outdated Show resolved Hide resolved
tests/units/test_add.py Show resolved Hide resolved
tests/units/test_add.py Show resolved Hide resolved
@shatakshiiii shatakshiiii force-pushed the Feature-add-subcommand branch from d2894ff to ce8d179 Compare November 4, 2024 08:06
@shatakshiiii
Copy link
Contributor

@tanwigeetika1618, can we also update the docs to mention a bit about add here: https://ansible.readthedocs.io/projects/creator/ ?

Can happen in a separate PR as well!

@ssbarnea ssbarnea merged commit cd506b5 into ansible:main Nov 7, 2024
19 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

4 participants