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(style): Add Markdown output style #87

Merged
merged 1 commit into from
Sep 28, 2024
Merged

Conversation

yamadashy
Copy link
Owner

@yamadashy yamadashy commented Sep 28, 2024

This PR introduces a new Markdown output style for Repopack, providing users with an additional option for formatting their repository content.

related: #86

Summary by CodeRabbit

  • New Features

    • Introduced a new Markdown output format for the Repopack tool, enhancing the versatility of output options.
    • Updated command line options to support the new Markdown style.
  • Documentation

    • Updated the README to include instructions for generating Markdown output and detailed the new command line options.
  • Tests

    • Added a test suite for validating the functionality of the new Markdown output generation.

Copy link
Contributor

coderabbitai bot commented Sep 28, 2024

Walkthrough

The changes introduce a new output format, Markdown, to the Repopack tool, enhancing its functionality. A new .gitignore entry is added for Markdown output files, and the README.md is updated to include instructions for generating Markdown output. The command-line interface and configuration types are modified to accommodate the new output style. Additionally, a new file for generating Markdown output is created, and tests are added to ensure its functionality.

Changes

File Change Summary
.gitignore Added repopack-output.md to the list of ignored files.
README.md Introduced a section for Markdown output format and updated command line options to include markdown.
src/cli/cliRunner.ts Updated --style option description to include markdown.
src/config/configTypes.ts Expanded RepopackOutputStyle type to include markdown.
src/core/output/markdownStyleGenerator.ts Added generateMarkdownStyle function for generating Markdown output.
src/core/output/outputGenerator.ts Modified generateOutput to include a case for markdown output, calling generateMarkdownStyle.
src/core/output/plainStyleGenerator.ts Repositioned PLAIN_SEPARATOR and PLAIN_LONG_SEPARATOR constants and updated their usage in the render context.
src/core/output/xmlStyleGenerator.ts Altered xmlTemplate to use a tagged template literal.
tests/core/output/markdownStyleGenerator.test.ts Added tests for the generateMarkdownStyle function to validate output structure.

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 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.

@yamadashy yamadashy force-pushed the feature/markdown-style branch 3 times, most recently from 1e95de8 to 9a2caf1 Compare September 28, 2024 10:07
@yamadashy yamadashy force-pushed the feature/markdown-style branch from 9a2caf1 to cd16787 Compare September 28, 2024 10:11
@yamadashy
Copy link
Owner Author

@coderabbitai review

Copy link
Contributor

coderabbitai bot commented Sep 28, 2024

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

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: 1

🧹 Outside diff range and nitpick comments (8)
src/config/configTypes.ts (1)

1-1: LGTM! Consider using an enum for better type safety.

The addition of 'markdown' to the RepopackOutputStyle type is correct and aligns with the PR objective. This change successfully introduces Markdown as a new output style option.

For better type safety and easier future additions, consider refactoring this type to an enum:

export enum RepopackOutputStyle {
  Plain = 'plain',
  XML = 'xml',
  Markdown = 'markdown'
}

This approach would provide better autocomplete support and make it easier to add new styles in the future.

tests/core/output/markdownStyleGenerator.test.ts (1)

14-27: LGTM: Test case setup is comprehensive.

The test case is well-structured with a detailed mock configuration. Using createMockConfig is a good practice for creating consistent test configurations.

Consider adding a comment explaining the purpose of each configuration option in the mock config. This would improve the readability and maintainability of the test. For example:

const mockConfig = createMockConfig({
  output: {
    filePath: 'output.md', // Specify output file path
    style: 'markdown', // Set output style to markdown
    headerText: 'Custom header text', // Test custom header text
    topFilesLength: 2, // Limit top files list to 2 entries
    showLineNumbers: false, // Disable line numbers in output
    removeComments: false, // Keep comments in output
    removeEmptyLines: false, // Keep empty lines in output
  },
});
src/core/output/outputGenerator.ts (1)

25-27: LGTM: New case for Markdown style output.

The new case for 'markdown' is correctly implemented and follows the existing pattern in the switch statement. It appropriately calls the generateMarkdownStyle function with the outputGeneratorContext.

For consistency with the 'xml' case, consider adding a comment above the 'markdown' case:

    case 'xml':
      output = generateXmlStyle(outputGeneratorContext);
      break;
+   // Markdown style
    case 'markdown':
      output = generateMarkdownStyle(outputGeneratorContext);
      break;
src/core/output/markdownStyleGenerator.ts (2)

12-32: LGTM: Well-structured function with a minor suggestion.

The generateMarkdownStyle function is well-implemented, following the single responsibility principle and promoting code reuse through utility functions. The renderContext object is comprehensive, covering all necessary aspects of the output.

Consider adding a return type annotation to the function for improved readability and type safety:

- export const generateMarkdownStyle = (outputGeneratorContext: OutputGeneratorContext) => {
+ export const generateMarkdownStyle = (outputGeneratorContext: OutputGeneratorContext): string => {

34-81: LGTM: Well-structured Markdown template with a suggestion for improvement.

The Markdown template is comprehensive and well-organized, covering all necessary sections for the output. The use of Handlebars syntax for dynamic content and conditional rendering is appropriate.

Consider moving the markdownTemplate to a separate file (e.g., markdownTemplate.ts) to improve code organization and maintainability. This separation of concerns would make the main file cleaner and the template easier to manage independently. You could then import it like this:

import { markdownTemplate } from './markdownTemplate.js';

This approach would also make it easier to add different templates in the future if needed.

src/core/output/plainStyleGenerator.ts (2)

40-40: Approved: Improved template string usage

The change from Handlebars syntax to string interpolation for separators is a good improvement. It simplifies the template and makes it more readable by directly using the constants.

Consider using template literals for multi-line strings consistently throughout the file. For example, you could rewrite the plainTemplate declaration as:

const plainTemplate = `
{{{generationHeader}}}

${PLAIN_LONG_SEPARATOR}
File Summary
${PLAIN_LONG_SEPARATOR}

// ... rest of the template ...
`;

This would make the code style more consistent and potentially more readable.

Also applies to: 42-42, 76-76, 78-78, 83-83, 86-86, 88-88, 94-94, 96-96


Line range hint 1-96: Overall changes look good with a minor suggestion

The refactoring improves code organization by moving constants to the file level and simplifying the template usage. These changes maintain the existing functionality while making the code more readable and potentially more maintainable.

For consistency, consider using template literals for all string declarations in this file. For example:

const PLAIN_SEPARATOR = `${'='.repeat(16)}`;
const PLAIN_LONG_SEPARATOR = `${'='.repeat(64)}`;

This would make the string declarations consistent throughout the file, although the current implementation is also perfectly valid.

README.md (1)

226-264: LGTM: Markdown Format section added successfully

The new Markdown Format section is well-structured and provides clear, accurate information about the new output format. The example command, format description, and code block effectively illustrate how to use and understand the Markdown output.

For consistency with the XML Format section, consider adding a brief note about the potential benefits of using Markdown format with AI systems, similar to the XML section's mention of XML tags in AI contexts.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between bc4c744 and cd16787.

📒 Files selected for processing (9)
  • .gitignore (1 hunks)
  • README.md (2 hunks)
  • src/cli/cliRunner.ts (1 hunks)
  • src/config/configTypes.ts (1 hunks)
  • src/core/output/markdownStyleGenerator.ts (1 hunks)
  • src/core/output/outputGenerator.ts (2 hunks)
  • src/core/output/plainStyleGenerator.ts (2 hunks)
  • src/core/output/xmlStyleGenerator.ts (1 hunks)
  • tests/core/output/markdownStyleGenerator.test.ts (1 hunks)
🧰 Additional context used
🪛 LanguageTool
README.md

[uncategorized] ~267-~267: Loose punctuation mark.
Context: ... Command Line Options - -v, --version: Show tool version - `-o, --output <file...

(UNLIKELY_OPENING_PUNCTUATION)

🔇 Additional comments (15)
.gitignore (1)

27-27: LGTM: Appropriate addition to .gitignore

The addition of repopack-output.md to the .gitignore file is correct and consistent with the existing entries for other repopack output formats. This change ensures that the newly introduced Markdown output files are not tracked by Git, which is the desired behavior for generated files.

tests/core/output/markdownStyleGenerator.test.ts (3)

1-7: LGTM: Imports and mocks are well-structured.

The necessary imports for testing are present, and mocking fs/promises is a good practice to isolate the test from file system operations.


9-13: LGTM: Test suite setup is correct.

The test suite is properly defined, and the beforeEach hook ensures that all mocks are reset before each test, which is a good practice for test isolation.


1-34: Overall, good test structure with room for improvement.

The test file for the markdown style generator is well-structured and covers the basic functionality. However, there are opportunities to enhance the test coverage and improve its robustness:

  1. Add comments to explain the purpose of each configuration option in the mock config.
  2. Expand the assertions to verify more aspects of the generated output, including the custom header text and the structure of each section.
  3. Consider adding more test cases to cover different scenarios and edge cases.

These improvements will increase confidence in the correctness of the markdown style generator and make the tests more maintainable.

src/core/output/outputGenerator.ts (2)

7-7: LGTM: Import statement for Markdown style generator.

The import statement for generateMarkdownStyle is correctly placed and follows the existing conventions in the file. Good job on including the file extension, which is a best practice for ES modules.


Line range hint 13-31: Verify documentation and tests for the new Markdown style.

The changes to support the Markdown output style have been implemented cleanly. To ensure completeness:

  1. Verify that the project documentation (e.g., README, user guide) has been updated to mention the new Markdown output option.
  2. Ensure that appropriate tests have been added or updated to cover the Markdown output generation.

Run the following script to check for potential documentation and test updates:

src/core/output/xmlStyleGenerator.ts (1)

34-34: LGTM! Improved developer experience with XML tag.

The addition of the /* xml */ comment before the template string is a good practice. This tag is likely used for syntax highlighting in IDEs or potentially for XML-specific processing. It improves code readability and developer experience without affecting the runtime behavior.

src/core/output/markdownStyleGenerator.ts (2)

1-10: LGTM: Imports are well-structured and relevant.

The import statements are clean, following TypeScript best practices. All imported modules and functions appear to be used in the file, contributing to the Markdown style generation.


1-81: Great implementation of the Markdown output style generator!

This new file successfully implements the Markdown output style for the Repopack project, as outlined in the PR objectives. The code is well-structured, follows TypeScript best practices, and effectively uses the Handlebars templating engine to generate the desired output.

Key strengths:

  1. Clear separation of concerns between imports, main function, and template.
  2. Effective use of utility functions for generating various sections of the output.
  3. Well-organized Markdown template covering all required sections.

The implementation aligns well with the goal of introducing a new Markdown output style, providing users with an additional option for formatting their repository content. This enhancement will indeed improve the presentation of repository information by allowing Markdown formatting.

src/core/output/plainStyleGenerator.ts (1)

34-35: Good refactoring: Constants moved outside the function

Moving the PLAIN_SEPARATOR and PLAIN_LONG_SEPARATOR constants outside the function is a good practice. It improves code organization and potentially allows for reuse if needed in the future.

src/cli/cliRunner.ts (1)

42-42: LGTM! Verify related changes.

The addition of "markdown" to the --style option description is correct and aligns with the PR objective of adding a new Markdown output style.

To ensure full implementation, please verify the following:

  1. Check if the RepopackOutputStyle type has been updated:

  2. Check if other parts of the codebase support the new "markdown" style:

  3. Check if documentation has been updated:

README.md (4)

272-272: LGTM: Command line option updated correctly

The --style option has been correctly updated to include markdown as a valid choice, alongside plain and xml. This change accurately reflects the new Markdown output format feature.


332-332: LGTM: Configuration option updated correctly

The output.style option in the configuration table has been properly updated to include markdown as a valid choice, alongside plain and xml. This change is consistent with the new Markdown output format feature.


267-267: Ignore static analysis hint for punctuation

The static analysis tool flagged a potential issue with loose punctuation in the Command Line Options section. However, this appears to be a false positive. The current formatting is intentional and consistent with the style used throughout the list of options. Changing it would likely reduce readability and disrupt the document's consistency.

🧰 Tools
🪛 LanguageTool

[uncategorized] ~267-~267: Loose punctuation mark.
Context: ... Command Line Options - -v, --version: Show tool version - `-o, --output <file...

(UNLIKELY_OPENING_PUNCTUATION)


Line range hint 226-332: Overall: Excellent addition of Markdown output format documentation

The changes to the README.md file successfully introduce and document the new Markdown output format for Repopack. The updates are comprehensive, well-integrated, and maintain the document's overall consistency and clarity. The new Markdown Format section provides valuable information to users, and the command line and configuration options have been correctly updated to reflect this new feature.

Great job on enhancing the documentation to support this new functionality!

🧰 Tools
🪛 LanguageTool

[uncategorized] ~267-~267: Loose punctuation mark.
Context: ... Command Line Options - -v, --version: Show tool version - `-o, --output <file...

(UNLIKELY_OPENING_PUNCTUATION)

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.

1 participant