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(inputs): Validate that always-comment recive acceptable values #80

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

MaxymVlasov
Copy link
Owner

@MaxymVlasov MaxymVlasov commented Mar 1, 2025

quickly done on phone, need to revisit, espetially if

Also, TODO: check are other inputs are validated as strixtly as possible.
And these validation & inputs code can be moved to separate function, and covered by unit tests

Summary by CodeRabbit

  • New Features
    • Introduced a new input option for auto-commenting that now requires a valid boolean value ("true" or "false").
    • Enhanced error messaging provides clear guidance when an invalid value is entered, ensuring a more robust configuration experience.
  • Bug Fixes
    • Improved validation for the always-comment input to prevent improper values from being processed.

Copy link

coderabbitai bot commented Mar 1, 2025

📝 Walkthrough

Walkthrough

The changes add a new input parameter, always-comment, to the action. Its value is now retrieved once and validated to be either "true" or "false". If an incorrect value is provided, an error message is produced. Additionally, the boolean conversion now relies on a variable (alwaysCommentInput), and previously present inline comments have been removed. The control flow remains the same except for the added validation step that improves error handling.

Changes

File(s) Change Summary
src/main.ts Introduced a new always-comment input parameter. Added validation ensuring the value is "true" or "false", with an error message on failure. Updated boolean conversion using a new variable (alwaysCommentInput) and removed redundant comments.

Sequence Diagram(s)

sequenceDiagram
    participant Action as GitHub Action
    participant Main as main.ts
    participant Validator as Validation Logic

    Action->>Main: Provide `always-comment` input
    Main->>Validator: Validate input ("true"/"false")
    alt Valid Input
        Validator-->>Main: Return parsed boolean (alwaysCommentInput)
        Main->>Main: Continue with execution
    else Invalid Input
        Validator-->>Main: Return error message
        Main->>Main: Abort execution with error
    end
Loading

📜 Recent review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 03fc676 and 963e4c8.

⛔ Files ignored due to path filters (2)
  • dist/index.js is excluded by !**/dist/**
  • dist/index.js.map is excluded by !**/dist/**, !**/*.map
📒 Files selected for processing (1)
  • src/main.ts (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/main.ts

🪧 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.
  • @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.

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.

@MaxymVlasov MaxymVlasov changed the title fix: Validate that always-comment recive acceptable values fix(inputs): Validate that always-comment recive acceptable values Mar 1, 2025
Copy link

@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 comments (1)
src/main.ts (1)

214-220: ⚠️ Potential issue

Fix the try-catch block syntax error.

The pipeline failures indicate there are issues with the try-catch block structure. According to the errors, there might be a missing closing brace or improper nesting. While the code excerpt appears correctly structured, the compiler is detecting syntax errors.

Ensure that all opening and closing braces are properly matched. Double-check if there are any invisible characters or formatting issues that might be affecting the syntax.

The specific errors point to line 214-220, suggesting issues with:

  • Missing 'try' expected (line 214-214)
  • Missing 'catch' or 'finally' expected (line 219-219)
  • Missing '}' expected (line 220-220)

This could indicate that there might be an unclosed block or a syntax error in how the try-catch is constructed.

🧰 Tools
🪛 Biome (1.9.4)

[error] 214-214: Expected a statement but instead found 'catch (e)'.

Expected a statement here.

(parse)


[error] 218-219: Expected a catch clause but instead found 'run'.

Expected a catch clause here.

(parse)


[error] 219-219: expected } but instead the file ends

the file ends here

(parse)


[error] 214-216: This block statement doesn't serve any purpose and can be safely removed.

Standalone block statements without any block-level declarations are redundant in JavaScript and can be removed to simplify the code.
Safe fix: Remove redundant block.

(lint/complexity/noUselessLoneBlockStatements)

🪛 GitHub Check: check-dist

[failure] 214-214:
'try' expected.


[failure] 219-219:
'catch' or 'finally' expected.


[failure] 220-220:
'}' expected.

🪛 GitHub Actions: Check `dist/`

[error] 214-214: TypeScript error TS1005: 'try' expected.

🪛 GitHub Actions: Tests

[error] 214-220: 'try' expected.


[error] 219-219: 'catch' or 'finally' expected.


[error] 220-220: '}' expected.

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 0d6246a and 3d723e5.

📒 Files selected for processing (1)
  • src/main.ts (1 hunks)
🧰 Additional context used
🪛 GitHub Actions: Check `dist/`
src/main.ts

[error] 214-214: TypeScript error TS1005: 'try' expected.

🪛 GitHub Actions: Tests
src/main.ts

[error] 214-220: 'try' expected.


[error] 219-219: 'catch' or 'finally' expected.


[error] 220-220: '}' expected.

⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: automerge

src/main.ts Outdated
Comment on lines 115 to 119
const alwaysCommentInput = core.getInput('always-comment')
if (alwaysCommentInput.toLowerCase() !== 'true' || alwaysCommentInput.toLowerCase() !== 'false') {
error(`"always-comment" can contain "true" or "false", given "${alwaysCommentInput}"`)
// Convert always-comment input to boolean value.
// All values other than 'true' are considered false.
const alwaysComment =
core.getInput('always-comment').toLowerCase() === 'true'
const alwaysComment = alwaysCommentInput.toLowerCase() === 'true'
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

Fix logical error in the validation condition.

The current validation condition will always evaluate to true regardless of the input, causing the action to always fail. This is because the condition is checking if the input is not "true" OR not "false", which is always true for any value. This needs to be fixed using the && operator instead.

const alwaysCommentInput = core.getInput('always-comment')
-if (alwaysCommentInput.toLowerCase() !== 'true' || alwaysCommentInput.toLowerCase() !== 'false') {
+if (alwaysCommentInput.toLowerCase() !== 'true' && alwaysCommentInput.toLowerCase() !== 'false') {
  error(`"always-comment" can contain "true" or "false", given "${alwaysCommentInput}"`)
}

Alternatively, you could use a more explicit approach:

const alwaysCommentInput = core.getInput('always-comment')
+const normalizedInput = alwaysCommentInput.toLowerCase()
+if (normalizedInput !== 'true' && normalizedInput !== 'false') {
  error(`"always-comment" can contain "true" or "false", given "${alwaysCommentInput}"`)
}
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
const alwaysCommentInput = core.getInput('always-comment')
if (alwaysCommentInput.toLowerCase() !== 'true' || alwaysCommentInput.toLowerCase() !== 'false') {
error(`"always-comment" can contain "true" or "false", given "${alwaysCommentInput}"`)
// Convert always-comment input to boolean value.
// All values other than 'true' are considered false.
const alwaysComment =
core.getInput('always-comment').toLowerCase() === 'true'
const alwaysComment = alwaysCommentInput.toLowerCase() === 'true'
const alwaysCommentInput = core.getInput('always-comment')
if (alwaysCommentInput.toLowerCase() !== 'true' && alwaysCommentInput.toLowerCase() !== 'false') {
error(`"always-comment" can contain "true" or "false", given "${alwaysCommentInput}"`)
}
// Convert always-comment input to boolean value.
const alwaysComment = alwaysCommentInput.toLowerCase() === 'true'

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