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

fix: limit data model fetching to models folder #14625

Merged
merged 10 commits into from
Feb 13, 2025

Conversation

ErlingHauan
Copy link
Contributor

@ErlingHauan ErlingHauan commented Feb 11, 2025

Description

Makes a modification to the GetSchemaFiles method in AltinnAppGitRepository, so it only looks for datamodels in the App/models/ path. This prevents Studio from showing and editing data models not in the models directory.

Related Issue(s)

Video after fix

model-outside-models.mp4

Verification

  • Your code builds clean without any errors or warnings
  • Manual testing done (required)
  • Relevant automated test added (if you find this hard, leave it and we'll help out)

Summary by CodeRabbit

  • New Features

    • Enhanced schema file retrieval functionality with support for JSON and XSD formats.
    • New configuration and schema definitions bolster data validation.
  • Bug Fixes

    • Addressed issues related to schema file retrieval logic.
  • Tests

    • Additional tests verify that only the correct schema files are processed.
    • New tests ensure accurate behavior for schema file retrieval and properties, including checks for file existence and correctness.
    • Updated tests reflect changes in expected schema file counts before and after operations.
  • Documentation

    • User-facing documentation now clearly reflects the updated schema file location.

@ErlingHauan ErlingHauan added backend team/studio-domain1 skip-documentation Issues where updating documentation is not relevant labels Feb 11, 2025
Copy link
Contributor

coderabbitai bot commented Feb 11, 2025

📝 Walkthrough

Walkthrough

The pull request involves significant changes to schema file handling in the AltinnGitRepository class, including the removal of the GetSchemaFiles method and related constants. New functionality is introduced in the AltinnAppGitRepository class with the addition of a public GetSchemaFiles method and new constants for JSON and XSD file patterns. Test coverage is enhanced with new tests for the schema file retrieval functionality, while existing tests are updated to reflect changes in the repository context. New test data, including configuration and schema files, is also introduced.

Changes

File(s) Change Summary
backend/src/Designer/.../AltinnGitRepository.cs Removed GetSchemaFiles method and related constants; removed MapFilesToAltinnCoreFiles method.
backend/src/Designer/.../AltinnAppGitRepository.cs Added new constants for schema file patterns; introduced a new GetSchemaFiles method and a helper method for mapping files.
backend/tests/Designer.Tests/.../AltinnGitRepositoryTests.cs Removed two test methods related to GetSchemaFiles; added three new test methods for schema file retrieval functionality.
backend/tests/Designer.Tests/Services/.../SchemaModelServiceTests.cs Updated repository name in DeleteSchema_ModelsRepo_ShouldDelete test and adjusted expected schema file counts.
backend/tests/Designer.Tests/_TestData/Repositories/.../app-with-misplaced-datamodels/* Added new test data including a settings.json configuration file, a JSON schema (model.schema.json), and an XSD file (model.xsd).
backend/src/Designer/Controllers/.../RepositoryController.cs Adjusted closing brace in ContentsZip method for proper syntax.

Suggested labels

area/content-library, skip-releasenotes

Suggested reviewers

  • Konrad-Simso
  • Jondyr

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@github-actions github-actions bot added solution/studio/designer Issues related to the Altinn Studio Designer solution. quality/testing Tests that are missing, needs to be created or could be improved. labels Feb 11, 2025
Copy link

codecov bot commented Feb 11, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 95.76%. Comparing base (f2a6c5c) to head (38ab424).
Report is 1 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main   #14625   +/-   ##
=======================================
  Coverage   95.76%   95.76%           
=======================================
  Files        1914     1914           
  Lines       24947    24947           
  Branches     2855     2855           
=======================================
  Hits        23890    23890           
  Misses        799      799           
  Partials      258      258           

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

@ErlingHauan ErlingHauan changed the title fix: limit datamodel fetching to models folder fix: limit data model fetching to models folder Feb 11, 2025
@ErlingHauan ErlingHauan marked this pull request as ready for review February 11, 2025 09:50
@TomasEng TomasEng self-assigned this Feb 12, 2025
Copy link
Contributor

@TomasEng TomasEng left a comment

Choose a reason for hiding this comment

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

Med min begrensede C#-kunnskap ser i hvert fall alt i orden ut her.

@TomasEng TomasEng removed their assignment Feb 12, 2025
@ErlingHauan ErlingHauan self-assigned this Feb 12, 2025
@ErlingHauan
Copy link
Contributor Author

Feedback from @Konrad-Simso:
Should consider moving GetSchemaFiles to AltinnAppGitRepository, since it now searches in apps specifically.
Moving PR back to In progress.

@ErlingHauan ErlingHauan assigned TomasEng and unassigned ErlingHauan Feb 12, 2025
@ErlingHauan ErlingHauan requested a review from TomasEng February 12, 2025 09:04
@TomasEng TomasEng removed their assignment Feb 12, 2025
@Konrad-Simso Konrad-Simso self-assigned this Feb 13, 2025
Copy link
Contributor

@Konrad-Simso Konrad-Simso 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, works as expected 👍

I do have 2 comments when it comes to pathing.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (1)
backend/src/Designer/Infrastructure/GitRepository/AltinnAppGitRepository.cs (1)

1003-1013: Consider using LINQ for better readability.

The method could be simplified using LINQ's Select and ToList methods.

Apply this diff to use LINQ:

         private List<AltinnCoreFile> MapFilesToAltinnCoreFiles(IEnumerable<string> schemaFiles)
         {
-            List<AltinnCoreFile> altinnCoreSchemaFiles = new();
-
-            foreach (string file in schemaFiles)
-            {
-                altinnCoreSchemaFiles.Add(AltinnCoreFile.CreateFromPath(file, RepositoryDirectory));
-            }
-
-            return altinnCoreSchemaFiles;
+            return schemaFiles
+                .Select(file => AltinnCoreFile.CreateFromPath(file, RepositoryDirectory))
+                .ToList();
         }
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 496a33d and c2c1608.

📒 Files selected for processing (2)
  • backend/src/Designer/Controllers/RepositoryController.cs (1 hunks)
  • backend/src/Designer/Infrastructure/GitRepository/AltinnAppGitRepository.cs (2 hunks)
✅ Files skipped from review due to trivial changes (1)
  • backend/src/Designer/Controllers/RepositoryController.cs
⏰ Context from checks skipped due to timeout of 90000ms (6)
  • GitHub Check: Run dotnet build and test (macos-latest)
  • GitHub Check: Run dotnet build and test (windows-latest)
  • GitHub Check: Build environment and run e2e test
  • GitHub Check: Run dotnet build and test (ubuntu-latest)
  • GitHub Check: Run integration tests against actual gitea and db
  • GitHub Check: Analyze
🔇 Additional comments (2)
backend/src/Designer/Infrastructure/GitRepository/AltinnAppGitRepository.cs (2)

60-61: Rename constants to match past review suggestions.

The constants should be renamed to maintain consistency with past review feedback.

Apply this diff to rename the constants:

-        private const string SchemaFilePatternJson = "*.schema.json";
-        private const string SchemaFilePatternXsd = "*.xsd";
+        private const string SchemaFilesPatternJson = "*.schema.json";
+        private const string SchemaFilesPatternXsd = "*.xsd";

980-1001: Improve path construction for schema files.

The path construction should be simplified using Path.Combine as suggested in past review comments.

Apply this diff to improve the path construction:

-            string schemaFilesPath = Path.Combine(ModelFolderPath, schemaFilesPattern);
-            IEnumerable<string> schemaFiles;
-
-            try
-            {
-                schemaFiles = FindFiles(new[] { schemaFilesPath });
-            }
+            IEnumerable<string> schemaFiles;
+            try
+            {
+                schemaFiles = FindFiles(new[] { Path.Combine(ModelFolderPath, schemaFilesPattern) });
+            }

@Konrad-Simso Konrad-Simso merged commit 9b93ad0 into main Feb 13, 2025
19 checks passed
@Konrad-Simso Konrad-Simso deleted the limit-datamodel-search-to-models-dir branch February 13, 2025 13:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backend quality/testing Tests that are missing, needs to be created or could be improved. skip-documentation Issues where updating documentation is not relevant solution/studio/designer Issues related to the Altinn Studio Designer solution. team/studio-domain1
Projects
Status: ✅ Done
Development

Successfully merging this pull request may close these issues.

Studio generates models for XSD files located outside the Models folder
3 participants