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 an environment variable to set minimum voting period allowed #271

Merged
merged 1 commit into from
Feb 13, 2025

Conversation

hansl
Copy link
Contributor

@hansl hansl commented Feb 12, 2025

This can use any human readable string for defining the voting period. By default it will be 30m (same as before this PR).

Fixed #268

Summary by CodeRabbit

  • New Features

    • Added a configurable minimum voting period for votes.
    • Enhanced validation errors to clearly display the required minimum time in a user-friendly format.
  • Chores

    • Introduced a new dependency to enable flexible duration parsing.

@hansl hansl requested a review from chalabi2 February 12, 2025 23:36
Copy link
Contributor

coderabbitai bot commented Feb 12, 2025

Walkthrough

This update introduces a new environment variable for setting the minimum voting period in the configuration, along with enhancements to the voting period validation in two components. The minimum duration is now defined dynamically based on an environment variable rather than a hardcoded value. In addition, a new utility function (parseDuration) and the corresponding dependency (parse-duration) have been added to process duration strings, enabling both the configuration and validation to work cohesively.

Changes

Files Change Summary
.env.test, config/.../env.ts, package.json Added new environment variable NEXT_PUBLIC_MINIMUM_VOTING_PERIOD=3m, introduced parseDuration function in env configuration, and added the parse-duration dependency.
components/.../GroupPolicyForm.tsx, components/.../updateGroupModal.tsx Updated voting period validation logic to use a dynamic error message with secondsToHumanReadable and a configurable minimum period from the environment; updated respective import statements.

Sequence Diagram(s)

sequenceDiagram
    participant App as Application Startup
    participant Env as Env Configuration
    participant Parser as parse-duration

    App->>Env: Read NEXT_PUBLIC_MINIMUM_VOTING_PERIOD
    Env->>Parser: parseDuration(duration, default=1800)
    Parser-->>Env: Return duration in seconds
    Env-->>App: Set minimumVotingPeriod
Loading
sequenceDiagram
    participant User
    participant Form as Voting Period Form
    participant Validator as Validation Logic
    participant Util as secondsToHumanReadable

    User->>Form: Enter voting period
    Form->>Validator: Validate against env.minimumVotingPeriod
    Validator->>Util: Convert min seconds to human-readable format
    Util-->>Validator: Return formatted minimum period
    Validator-->>Form: Return result/error message
    Form-->>User: Display validation feedback
Loading

Possibly related PRs

Suggested labels

render

Suggested reviewers

  • chalabi2
  • fmorency

Poem

I'm a little rabbit, hopping through the code,
Found a new voting twist on my winding road.
With dynamic checks and durations so neat,
The minimum period now can't be beat.
Hop along with me—let's celebrate this mode!
🐰✨

✨ Finishing Touches
  • 📝 Generate Docstrings (Beta)

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.

This can use any human readable string for defining the voting period. By
default it will be 30m (same as before this PR).

Fixed liftedinit#268
Copy link

codecov bot commented Feb 12, 2025

Codecov Report

Attention: Patch coverage is 96.96970% with 1 line in your changes missing coverage. Please review.

Project coverage is 54.52%. Comparing base (d549e82) to head (368890d).
Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
config/env.ts 87.50% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #271      +/-   ##
==========================================
+ Coverage   54.48%   54.52%   +0.03%     
==========================================
  Files         207      207              
  Lines       17727    17743      +16     
==========================================
+ Hits         9659     9674      +15     
- Misses       8068     8069       +1     

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

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)
config/env.ts (1)

3-10: Add unit tests for the parseDuration function.

The function is not covered by tests according to the static analysis hints. Since this is a critical function for parsing user input, it should be thoroughly tested with various input scenarios.

Would you like me to generate unit tests for the parseDuration function? The tests should cover:

  • Valid duration strings (e.g., "30m", "1h", "2d")
  • Invalid duration strings
  • Undefined input
  • Edge cases
🧰 Tools
🪛 GitHub Check: codecov/patch

[warning] 6-6: config/env.ts#L6
Added line #L6 was not covered by tests

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between d549e82 and 368890d.

⛔ Files ignored due to path filters (1)
  • bun.lock is excluded by !**/*.lock
📒 Files selected for processing (5)
  • .env.test (1 hunks)
  • components/groups/forms/groups/GroupPolicyForm.tsx (2 hunks)
  • components/groups/modals/updateGroupModal.tsx (2 hunks)
  • config/env.ts (2 hunks)
  • package.json (1 hunks)
✅ Files skipped from review due to trivial changes (1)
  • .env.test
🧰 Additional context used
🧠 Learnings (1)
components/groups/forms/groups/GroupPolicyForm.tsx (1)
Learnt from: chalabi2
PR: liftedinit/manifest-app#161
File: components/groups/forms/groups/GroupPolicyForm.tsx:213-215
Timestamp: 2025-01-07T01:21:52.501Z
Learning: In the GroupPolicyForm component, the voting period validation only needs to handle the minimum 30-minute period error at the object level, which produces a string error message. Individual field validations for days, hours, minutes, and seconds don't produce error messages.
🪛 GitHub Check: codecov/patch
config/env.ts

[warning] 6-6: config/env.ts#L6
Added line #L6 was not covered by tests

⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: build
🔇 Additional comments (4)
config/env.ts (1)

52-52: LGTM! The implementation aligns with the PR objectives.

The minimumVotingPeriod property correctly uses the new environment variable with a default of 30 minutes, maintaining backward compatibility.

components/groups/forms/groups/GroupPolicyForm.tsx (1)

19-28: LGTM! The validation schema changes align with the PR objectives and past learnings.

The implementation correctly:

  • Uses the configurable minimum voting period from environment variables
  • Provides human-readable error messages
  • Maintains field-level validations without error messages as per past learnings
components/groups/modals/updateGroupModal.tsx (1)

259-274: LGTM! The validation schema changes include a smart optimization.

The implementation correctly:

  • Uses the configurable minimum voting period
  • Provides human-readable error messages
  • Smartly skips validation if voting period is not being updated (all values are 0)
package.json (1)

74-74:

✅ Verification successful

Verify the latest version of parse-duration for security updates.

Let's check if version ^2.1.3 is the latest secure version.


🌐 Web query:

What is the latest version of parse-duration npm package? Are there any known security vulnerabilities?

💡 Result:

The latest version of the parse-duration npm package is 2.1.3, published 14 hours ago (as of February 12, 2025) [4][10].

Regarding security vulnerabilities:

  • No direct vulnerabilities have been reported for parse-duration in Snyk's vulnerability database [5][8]
  • The package appears safe based on current security scans
  • General npm vulnerabilities like supply chain attacks remain a theoretical risk for all packages [2], but no specific issues are documented for this particular utility

For optimal security:

npm install parse-duration@latest

This ensures you get the most recent patched version with any potential security fixes[4]. Always verify dependencies using tools like npm audit or Snyk[6] to monitor for future vulnerabilities[2][5].

Citations:


Parse-Duration Dependency Verified

The latest version of the parse-duration package is indeed 2.1.3, and no known security vulnerabilities have been reported. The dependency is up-to-date, so no changes are needed. Remember to periodically run tools like npm audit or Snyk for ongoing security checks.

Copy link
Contributor

@fmorency fmorency left a comment

Choose a reason for hiding this comment

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

utACK

@fmorency fmorency merged commit a90c398 into liftedinit:main Feb 13, 2025
5 checks passed
@hansl hansl deleted the fix-268 branch February 13, 2025 16:48
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.

Add an .env variable for voting period
2 participants