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

feat(cli): Add project command #451

Merged
merged 3 commits into from
Sep 21, 2024
Merged

feat(cli): Add project command #451

merged 3 commits into from
Sep 21, 2024

Conversation

rajdip-b
Copy link
Member

@rajdip-b rajdip-b commented Sep 19, 2024

User description

Description

Fixes #298


PR Type

enhancement


Description

  • Introduced a new ProjectCommand class with various subcommands for managing projects, including create, delete, fork, get, list, sync, unlink, and update operations.
  • Refactored ScanCommand to utilize the Logger for logging instead of direct console output, improving consistency and maintainability.
  • Integrated the ProjectCommand into the CLI command list, enabling project management functionalities.

Changes walkthrough 📝

Relevant files
Enhancement
12 files
project.command.ts
Add `ProjectCommand` class with subcommands for project management

apps/cli/src/commands/project.command.ts

  • Added a new ProjectCommand class extending BaseCommand.
  • Implemented methods to manage project-related commands.
  • Integrated subcommands for project operations.
  • +34/-0   
    create.project.ts
    Add `CreateProject` command for project creation                 

    apps/cli/src/commands/project/create.project.ts

  • Added CreateProject class extending BaseCommand.
  • Implemented methods to create a project.
  • +11/-0   
    delete.project.ts
    Add `DeleteProject` command for project deletion                 

    apps/cli/src/commands/project/delete.project.ts

  • Added DeleteProject class extending BaseCommand.
  • Implemented methods to delete a project.
  • +11/-0   
    fork.project.ts
    Add `ForkProject` command for project forking                       

    apps/cli/src/commands/project/fork.project.ts

  • Added ForkProject class extending BaseCommand.
  • Implemented methods to fork a project.
  • +11/-0   
    get.project.ts
    Add `GetProject` command to fetch project details               

    apps/cli/src/commands/project/get.project.ts

  • Added GetProject class extending BaseCommand.
  • Implemented methods to fetch project details.
  • Added argument handling for project slug.
  • +50/-0   
    list-forks.project.ts
    Add `ListProjectForks` command to list project forks         

    apps/cli/src/commands/project/list-forks.project.ts

  • Added ListProjectForks class extending BaseCommand.
  • Implemented methods to list all forks of a project.
  • +11/-0   
    list.project.ts
    Add `ListProject` command to list workspace projects         

    apps/cli/src/commands/project/list.project.ts

  • Added ListProject class extending BaseCommand.
  • Implemented methods to list all projects in a workspace.
  • Added argument handling for workspace slug.
  • +46/-0   
    sync.project.ts
    Add `SyncProject` command for syncing forked projects       

    apps/cli/src/commands/project/sync.project.ts

  • Added SyncProject class extending BaseCommand.
  • Implemented methods to sync a forked project.
  • +11/-0   
    unlink.project.ts
    Add `UnlinkProject` command to unlink forked projects       

    apps/cli/src/commands/project/unlink.project.ts

  • Added UnlinkProject class extending BaseCommand.
  • Implemented methods to unlink a forked project.
  • +11/-0   
    update.project.ts
    Add `UpdateProject` command for project updates                   

    apps/cli/src/commands/project/update.project.ts

  • Added UpdateProject class extending BaseCommand.
  • Implemented methods to update a project.
  • +11/-0   
    scan.command.ts
    Refactor `ScanCommand` to use `Logger` for logging             

    apps/cli/src/commands/scan.command.ts

  • Replaced console logs with Logger for logging.
  • Removed usage of colors package for output formatting.
  • +23/-37 
    index.ts
    Integrate `ProjectCommand` into CLI command list                 

    apps/cli/src/index.ts

    • Added ProjectCommand to the list of commands.
    +2/-0     

    💡 PR-Agent usage:
    Comment /help on the PR to get a list of all available PR-Agent tools and their descriptions

    @rajdip-b rajdip-b changed the title initiated feat(cli): Add project command Sep 19, 2024
    @codiumai-pr-agent-free codiumai-pr-agent-free bot changed the title feat(cli): Add project command initiated Sep 19, 2024
    Copy link
    Contributor

    codiumai-pr-agent-free bot commented Sep 19, 2024

    CI Failure Feedback 🧐

    (Checks updated until commit 06ac85c)

    Action: Validate PR title

    Failed stage: Lint PR [❌]

    Failed test name: Validate PR title

    Failure summary:

    The action failed because the pull request title did not include a release type prefix. The title
    "initiated" does not conform to the conventional commits specification, which requires a prefix to
    indicate the type of change (e.g., feat, fix, chore).

    Relevant error logs:
    1:  ##[group]Operating System
    2:  Ubuntu
    ...
    
    35:  Download action repository 'amannn/action-semantic-pull-request@v5' (SHA:0723387faaf9b38adef4775cd42cfd5155ed6017)
    36:  Complete job name: Validate PR title
    37:  ##[group]Run amannn/action-semantic-pull-request@v5
    38:  with:
    39:  githubBaseUrl: https://api.github.com
    40:  env:
    41:  GITHUB_TOKEN: ***
    42:  ##[endgroup]
    43:  ##[error]No release type found in pull request title "initiated". Add a prefix to indicate what kind of release this pull request corresponds to. For reference, see https://www.conventionalcommits.org/
    

    ✨ CI feedback usage guide:

    The CI feedback tool (/checks) automatically triggers when a PR has a failed check.
    The tool analyzes the failed checks and provides several feedbacks:

    • Failed stage
    • Failed test name
    • Failure summary
    • Relevant error logs

    In addition to being automatically triggered, the tool can also be invoked manually by commenting on a PR:

    /checks "https://github.com/{repo_name}/actions/runs/{run_number}/job/{job_number}"
    

    where {repo_name} is the name of the repository, {run_number} is the run number of the failed check, and {job_number} is the job number of the failed check.

    Configuration options

    • enable_auto_checks_feedback - if set to true, the tool will automatically provide feedback when a check is failed. Default is true.
    • excluded_checks_list - a list of checks to exclude from the feedback, for example: ["check1", "check2"]. Default is an empty list.
    • enable_help_text - if set to true, the tool will provide a help message with the feedback. Default is true.
    • persistent_comment - if set to true, the tool will overwrite a previous checks comment with the new feedback. Default is true.
    • final_update_message - if persistent_comment is true and updating a previous checks message, the tool will also create a new message: "Persistent checks updated to latest commit". Default is true.

    See more information about the checks tool in the docs.

    Copy link
    Contributor

    PR Reviewer Guide 🔍

    ⏱️ Estimated effort to review: 4 🔵🔵🔵🔵⚪
    🧪 No relevant tests
    🔒 No security concerns identified
    ⚡ Key issues to review

    Error Handling
    The error message in the catch block is too generic. It should provide more specific information about what went wrong.

    Type Safety
    The use of 'any' type for the project object in the forEach loop reduces type safety. Consider defining a proper interface for the project object.

    Duplicate Code
    There are two identical log messages for "🔍 Secret Scan Started". This duplication should be removed.

    @rajdip-b rajdip-b changed the title initiated feat(api): Add project command Sep 19, 2024
    Copy link
    Contributor

    codiumai-pr-agent-free bot commented Sep 19, 2024

    PR Code Suggestions ✨

    CategorySuggestion                                                                                                                                    Score
    Possible issue
    Add a check for the existence of data in the success case to prevent potential runtime errors

    Consider adding error handling for cases where data might be undefined. This can
    prevent potential runtime errors if the API response doesn't contain the expected
    data structure.

    apps/cli/src/commands/project/get.project.ts [38-48]

    -if (success) {
    +if (success && data) {
       Logger.info(`Name: ${data.name}`)
       Logger.info(`Slug: ${data.slug}`)
       Logger.info(`Description: ${data.description}`)
       Logger.info(`Public Key: ${data.publicKey}`)
       Logger.info(`Private Key: ${data.privateKey}`)
       Logger.info(`Is Forked: ${data.isForked}`)
       Logger.info(`Access Level: ${data.accessLevel}`)
    +} else if (success) {
    +  Logger.error('Project data is missing from the response')
     } else {
       Logger.error(`Failed fetching project: ${error.message}`)
     }
     
    • Apply this suggestion
    Suggestion importance[1-10]: 9

    Why: The suggestion addresses a potential runtime error by adding a check for the existence of data before accessing its properties, which is crucial for robust error handling.

    9
    Possible bug
    Add a check for the existence of the regex match result to prevent potential runtime errors

    Consider adding a check for the existence of matched[0] before using it in the
    replace method to prevent potential runtime errors if the regex match fails.

    apps/cli/src/commands/scan.command.ts [91-92]

     const matched = line.match(regex)
    -const highlightedLine = line.replace(regex, matched[0]).trim()
    +const highlightedLine = matched ? line.replace(regex, matched[0]).trim() : line.trim()
     
    • Apply this suggestion
    Suggestion importance[1-10]: 8

    Why: This suggestion addresses a potential bug by ensuring that the code does not attempt to access an undefined element, which is important for preventing runtime errors.

    8
    Enhancement
    Add type safety for the project object in the forEach loop to improve code reliability

    Consider adding type safety for the project object in the forEach loop. This can
    help prevent potential runtime errors and improve code maintainability.

    apps/cli/src/commands/project/list.project.ts [38-44]

    +interface Project {
    +  name: string;
    +  slug: string;
    +}
    +
     if (success) {
    -  data.items.forEach((project: any) => {
    +  data.items.forEach((project: Project) => {
         Logger.info(`- ${project.name} (${project.slug})`)
       })
     } else {
       Logger.error(`Failed fetching projects: ${error.message}`)
     }
     
    • Apply this suggestion
    Suggestion importance[1-10]: 7

    Why: Adding type safety improves code reliability and maintainability by ensuring that the project object has the expected structure, reducing the risk of runtime errors.

    7
    Best practice
    Use template literals for string interpolation to improve code readability

    Consider using template literals for string interpolation instead of concatenation
    for better readability and maintainability.

    apps/cli/src/commands/scan.command.ts [105]

    -Logger.info(`${`${secret.file}:${secret.line}`}: ${secret.content}`)
    +Logger.info(`${secret.file}:${secret.line}: ${secret.content}`)
     
    • Apply this suggestion
    Suggestion importance[1-10]: 5

    Why: The suggestion improves code readability by using template literals, which is a minor enhancement but contributes to better code style and maintainability.

    5

    💡 Need additional feedback ? start a PR chat

    @rajdip-b rajdip-b changed the title feat(api): Add project command feat(cli): Add project command Sep 21, 2024
    Copy link

    codecov bot commented Sep 21, 2024

    Codecov Report

    All modified and coverable lines are covered by tests ✅

    Project coverage is 88.11%. Comparing base (ce50743) to head (dbdaf8b).
    Report is 195 commits behind head on develop.

    Additional details and impacted files
    @@             Coverage Diff             @@
    ##           develop     #451      +/-   ##
    ===========================================
    - Coverage    91.71%   88.11%   -3.60%     
    ===========================================
      Files          111      105       -6     
      Lines         2510     2726     +216     
      Branches       469      413      -56     
    ===========================================
    + Hits          2302     2402     +100     
    - Misses         208      324     +116     
    Flag Coverage Δ
    api-e2e-tests 88.11% <100.00%> (-3.60%) ⬇️

    Flags with carried forward coverage won't be shown. Click here to find out more.

    ☔ View full report in Codecov by Sentry.
    📢 Have feedback on the report? Share it here.

    @rajdip-b rajdip-b merged commit 70448e1 into develop Sep 21, 2024
    8 checks passed
    @rajdip-b rajdip-b deleted the feat/cli/project branch September 21, 2024 11:41
    Kiranchaudhary537 pushed a commit to Kiranchaudhary537/keyshade that referenced this pull request Oct 13, 2024
    rajdip-b pushed a commit that referenced this pull request Oct 24, 2024
    ## [2.6.0](v2.5.0...v2.6.0) (2024-10-24)
    
    ### 🚀 Features
    
    * **api:**  Add icon and remove description field from workspace ([#435](#435)) ([a99c0db](a99c0db))
    * **api-client:** Added workspace-membership and related tests ([#452](#452)) ([6a1c091](6a1c091))
    * **api-client:** Create controller for User module ([#484](#484)) ([f9d8e83](f9d8e83))
    * **api:** Add prod env schema in env file ([#436](#436)) ([21c3004](21c3004))
    * **api:** Add resend otp implementation ([#445](#445)) ([4dc6aa1](4dc6aa1))
    * **api:** Fetch total count of environments, [secure]s and variables in project ([#434](#434)) ([0c9e50a](0c9e50a))
    * **api:** Replace `projectId` with `name` and `slug` in workspace-role response.  ([#432](#432)) ([af06071](af06071))
    * **cli:** Add functionality to operate on Secrets ([#504](#504)) ([1b4bf2f](1b4bf2f))
    * **cli:** Add project command ([#451](#451)) ([70448e1](70448e1))
    * **cli:** Add workspace operations ([#441](#441)) ([ed38d22](ed38d22))
    * **cli:** implement commands to get, list, update, and delete, workspace roles ([#469](#469)) ([957ea8d](957ea8d))
    * **cli:** Implemented pagination support ([#453](#453)) ([feb1806](feb1806))
    * **cli:** Secret scan ([#438](#438)) ([85cb8ab](85cb8ab))
    * **cli:** Update environment command outputs ([f4af874](f4af874))
    * **platform:** Clearing email field after waitlisting the user email ([#481](#481)) ([256d659](256d659))
    * Remove project IDs from workspace role export data and update tests ([#448](#448)) ([8fdb328](8fdb328))
    * **web:** Configured extra check for waitlisted users already in the list and created toast message for them ([#492](#492)) ([2ddd0ef](2ddd0ef))
    * **web:** show the toast only when email add successfully ([#490](#490)) ([783c411](783c411))
    
    ### 🐛 Bug Fixes
    
    * **api,api-client:** Add environmentSlug in multiple places across the variable module ([#468](#468)) ([d970aff](d970aff))
    * **api:** Replace the id with slug in the global-search service ([#455](#455)) ([74804b1](74804b1))
    * **platform:** Fixed duplicate Google Logo UI fix  ([#450](#450)) ([fb0d6f7](fb0d6f7))
    * resolve footer website name cut-off or overlap issue ([#444](#444)) ([fe03ba2](fe03ba2))
    * **web:** Horizontal Scrolling issue on the website ([#440](#440)) ([655177b](655177b))
    
    ### 📚 Documentation
    
    * Add documentation for environment in CLI ([#462](#462)) ([dad7394](dad7394))
    * Add documentation for project in CLI ([#466](#466)) ([341fb32](341fb32))
    * Add documentation for scan in CLI ([#461](#461)) ([72281e6](72281e6))
    * Add documentation for workspace command ([#464](#464)) ([4aad8a2](4aad8a2))
    * Add instructions for resetting the local Prisma database ([#495](#495)) ([#501](#501)) ([b07ea17](b07ea17))
    * Added docker support documentation ([#465](#465)) ([bc04be4](bc04be4))
    * Added documentation for running the platform ([#473](#473)) ([8b8386b](8b8386b))
    * Added missing mappings to pages ([5de9fd8](5de9fd8))
    * Fix Documentation Hyperlink and update expired Discord invite link ([#496](#496)) ([5a10e39](5a10e39))
    * Updated CLI docs ([#460](#460)) ([c7e0f13](c7e0f13))
    
    ### 🔧 Miscellaneous Chores
    
    * Add more logging to Sentry init ([#470](#470)) ([de4925d](de4925d))
    * **api:** Optimise API docker image size ([#360](#360)) ([ea40dc1](ea40dc1))
    * **api:** Updated lockfile ([a968e78](a968e78))
    * **CI:** Add [secure] scan validation ([f441262](f441262))
    * **cli:** Update controller invocation in environment commands ([#477](#477)) ([596bd1a](596bd1a))
    * Minor changes to variables ([fe01ca6](fe01ca6))
    * **[secure]-scan:** Failing lint issues ([#507](#507)) ([48f45df](48f45df))
    * **[secure]-scan:** Formatted files ([5884833](5884833))
    * Update .env.example ([70ad4f7](70ad4f7))
    * Updated scripts ([9eb76a7](9eb76a7))
    * **web:** email validation ([#487](#487)) ([e8e737a](e8e737a))
    @rajdip-b
    Copy link
    Member Author

    🎉 This PR is included in version 2.6.0 🎉

    The release is available on GitHub release

    Your semantic-release bot 📦🚀

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

    Successfully merging this pull request may close these issues.

    CLI: Add functionality to operate on Projects
    1 participant