Skip to content

Conversation

@oycyc
Copy link
Contributor

@oycyc oycyc commented Jan 24, 2025

image
I'm doing a cron expression for 0 */6 * * *
This condition is failing if cron expression contains */{number}.

It's this escape character. Could fix it via the second statement where it's escaped.

But thinking that this condition is too strict, wondering if it can just be to check if it has 5 expressions.

Or if we even need this validator? since validating cron expressions looks messy.

Summary by CodeRabbit

  • Bug Fixes
    • Updated drift detection schedule validation to support more flexible cron schedule formats.
    • Improved input validation for scheduling configurations with enhanced regex pattern.
  • Style
    • Adjusted whitespace and alignment for variable assignments and conditions in test files for improved readability.

@oycyc oycyc requested a review from a team as a code owner January 24, 2025 17:25
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jan 24, 2025

Warning

Rate limit exceeded

@oycyc has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 13 minutes and 23 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📥 Commits

Reviewing files that changed from the base of the PR and between d766748 and a808834.

📒 Files selected for processing (2)
  • main.tf (1 hunks)
  • tests/main.tftest.hcl (14 hunks)

Walkthrough

The pull request modifies the regex pattern in the precondition block of the spacelift_drift_detection resource within the main.tf file. The new regex pattern broadens the accepted format for the drift_detection_schedule by allowing the use of the forward slash / character, in addition to the previously accepted characters. The associated error message remains unchanged, ensuring consistent feedback for validation failures. Additionally, whitespace adjustments were made in the tests/main.tftest.hcl and tests/single-instance.tftest.hcl files to improve alignment and readability without altering functionality.

Changes

File Change Summary
main.tf Updated regex pattern in precondition block for spacelift_drift_detection to allow / in drift_detection_schedule
tests/main.tftest.hcl Adjusted whitespace for variable assignments and conditions for consistency
tests/single-instance.tftest.hcl Adjusted whitespace for variable assignments and conditions for consistency

Poem

🕰️ Cron schedules dance, regex refined
Whitespace now welcome, patterns redesigned
Flexible validation, a code ballet
Drift detection sways in a new, lenient way
Terraform's rhythm, now more kind 🌟


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.

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.

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

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 28c4217 and 52a9c18.

📒 Files selected for processing (1)
  • main.tf (1 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
main.tf (1)

Pattern **/*.tf: You're a Terraform expert who has thoroughly studied all the documentation from Hashicorp https://developer.hashicorp.com/terraform/docs and OpenTofu https://opentofu.org/docs/.
You have a strong grasp of Terraform syntax and prioritize providing accurate and insightful code suggestions.
As a fan of the Cloud Posse / SweetOps ecosystem, you incorporate many of their best practices https://docs.cloudposse.com/best-practices/terraform/ while balancing them with general Terraform guidelines.

@oycyc
Copy link
Contributor Author

oycyc commented Jan 24, 2025

Coderabbit is suggesting the regex fix in the pic with the escape character. Could consider that. But I'm leaning more to just remove this validation in the first place. Terraform/Spacelift provider will error out anyways if not correct.

Copy link
Member

@gberenice gberenice left a comment

Choose a reason for hiding this comment

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

I think it's good to have this one. I agree that this is barely readable, but we can provide more examples on what is allowed by this precondition.

@oycyc oycyc changed the title fix: less strict regex validator for cron fix: cron validator regex escape characters Jan 28, 2025
@oycyc
Copy link
Contributor Author

oycyc commented Jan 28, 2025

I think it's good to have this one. I agree that this is barely readable, but we can provide more examples on what is allowed by this precondition.

Updated to only address the whitespace.

@oycyc
Copy link
Contributor Author

oycyc commented Jan 28, 2025

Some residue from tofu fmt --recursive as well

lifecycle {
precondition {
condition = alltrue([for schedule in try(local.stack_configs[each.key].drift_detection_schedule, var.drift_detection_schedule) : can(regex("^([0-9,\\-\\*]+\\s+){4}[0-9,\\-\\*]+$", schedule))])
condition = alltrue([for schedule in try(local.stack_configs[each.key].drift_detection_schedule, var.drift_detection_schedule) : can(regex("^([0-9,\\-*/]+\\s+){4}[0-9,\\-*/]+$", schedule))])
Copy link
Member

Choose a reason for hiding this comment

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

We should add a test to check that this works as expected with the / so we know this works as expected! Mind adding it?

Copy link
Member

Choose a reason for hiding this comment

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

@oycyc let's get this merged without this test, but let's follow up with one!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sounds good, put thi s on my todo list

Copy link
Member

@Gowiem Gowiem left a comment

Choose a reason for hiding this comment

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

:shipit:

@oycyc oycyc enabled auto-merge (squash) January 30, 2025 19:20
@oycyc oycyc merged commit 81a386b into main Jan 30, 2025
4 checks passed
@oycyc oycyc deleted the fix/cron-validator branch January 30, 2025 19:21
Gowiem added a commit that referenced this pull request Feb 4, 2025
🤖 I have created a release *beep* *boop*
---


##
[1.0.0](v0.7.0...v1.0.0)
(2025-02-04)


### ⚠ BREAKING CHANGES

* TF Version pinning has been updated to require terraform v1.9+ and
OpenTofu v1.7+. Please update the consuming root module accordingly.
(#43)
* Scopes `tfvars` + `default_tf_workspace_enabled` settings under
`automation_settings` object in StackConfig schema. [See
README](https://github.com/masterpointio/terraform-spacelift-automation?tab=readme-ov-file#what-goes-in-a-stack-config-file-eg-stacksdevyaml-stackscommonyaml-stackyaml-and-similar)
for example of StackConfig schema. (#42)

### Features

* adds support for description as a templatestring
([#43](#43))
([1bbb74f](1bbb74f))
* adds the runtime_overrides variable + tests
([#44](#44))
([6030f94](6030f94))
* feat: allow specifying `space_name` that maps to space_id #46
* **schema:** adds initial JSON schema + StackConfig changes
([#42](#42))
([f247b5e](f247b5e))


### Bug Fixes

* cron validator regex escape characters
([#45](#45))
([81a386b](81a386b))
* dont clobber static config with overrides
([#50](#50))
([b352674](b352674))
* external space changed so update test data
([#51](#51))
([569d8d4](569d8d4))

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).

---------

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: Matt Gowie <[email protected]>
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.

4 participants