Skip to content

Add branch workflow and selectable SQL dialects - #2

Merged
enumura1 merged 19 commits into
mainfrom
docs/branching-strategy
May 24, 2026
Merged

enumura1 merged 19 commits into
mainfrom
docs/branching-strategy

Conversation

@enumura1

@enumura1 enumura1 commented May 23, 2026 •

Copy link
Copy Markdown
Owner

Summary

  • Document the repository branch workflow and branch naming examples.
  • Add explicit dialect selection with --dialect / -d and a dialects command.
  • Default formatting to SQLGlot's generic dialect; currently enable only generic, mysql, postgres, and redshift.
  • Organize tests by responsibility and document the test layout.
  • Add CodeRabbit repository configuration and contribution notes.
  • Add a small AGENTS.md project map for progressive disclosure.

Validation

  • scripts/check passed locally via the pre-push hook.

Notes

  • CodeRabbit config is included in .coderabbit.yaml; the GitHub App is installed and reviewing this PR.

Summary by CodeRabbit

  • New Features

    • SQL dialects now default to generic; added a command to list supported dialects (generic, mysql, postgres, redshift)
    • Commands (format/check/extract) accept an explicit --dialect/-d and preserve dialect-specific constructs (e.g., Redshift COPY)
  • Bug Fixes / UX

    • CLI validates dialect/backend choices, prints clear error messages and proper exit codes on invalid inputs or unsupported dialects
  • Documentation

    • Updated README, docs, contributing, and guides for dialect usage, branching workflow, and automated review tooling
  • Tests

    • Added coverage for dialect behavior, CLI commands, detection, and error cases

Review Change Stack

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 2124402227

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".


def normalize_dialect(dialect: str) -> str:
normalized = dialect.strip().lower()
if normalized not in SUPPORTED_DIALECTS:

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Accept valid SQLGlot dialect specifiers

Relax this membership check because it rejects dialect strings that SQLGlot itself accepts, such as configured dialect specifiers ("dialect, key=value") and plugin-provided dialect names loaded at runtime. Before this commit those values were passed through to sqlglot.parse, but now format/check/extract fail early with unsupported SQL dialect, which is a functional regression for users relying on SQLGlot’s documented dialect parsing behavior.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

Addressed in f00c240.

normalize_dialect() now delegates validation to SQLGlot's Dialect.get_or_raise() instead of requiring an exact match against the built-in dialect list. I also added coverage for a configured dialect string such as postgres, normalization_strategy=case_sensitive.

@coderabbitai

coderabbitai Bot commented May 23, 2026 •

Copy link
Copy Markdown

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

Adds SQL dialect normalization/validation in the formatter, exposes supported dialects, updates CLI defaults/validation with error handling and a dialects command, expands tests for dialect behavior and errors, and updates README, website docs, branching and contributing guidance, and repository review config.

Changes

Dialect Support Feature

Layer / File(s) Summary
Formatter dialect validation and defaults
py_sql_cleaner/adapters/sqlglot_formatter.py, py_sql_cleaner/domain/config.py
Adds normalize_dialect() and SUPPORTED_DIALECTS, maps generic to SQLGlot's empty dialect, validates dialect strings (including comma-separated settings), short-circuits redshift-preserve commands, and updates format_sql defaults to DEFAULT_DIALECT/DEFAULT_BACKEND.
Application result handling
py_sql_cleaner/application/format_source.py
FormatSourceResult now includes errors: list[str]; format_source collects FormatterError instances into errors as well as warnings.
CLI defaults, validation, and commands
py_sql_cleaner/cli/app.py
format, check, and extract now default --dialect/--backend to constants, validate via _validate_formatter_options, wrap formatter/extract calls to catch FormatterError and exit with status 1, and add a dialects subcommand that prints supported dialects.
Adapter and CLI tests
tests/adapters/test_sqlglot_formatter.py, tests/cli/*
Adds adapter tests for generic/Postgres/MySQL/Redshift behaviors and unsupported-dialect errors; adds CLI tests for format (long/short flags, dry-run, jinja skip), check failures, extract with explicit dialect, unknown-dialect rejection, and dialects listing.
User docs & README updates
README.md, website/docs/*, website/docs/reference/commands.md
README and website docs updated to state SQLGlot’s generic dialect is the default, document --dialect usage and dialects command, add Quick Start dialect examples, and adjust project status/scope text.
Branching, contributing, and review tooling
docs/development/branching.md, AGENTS.md, .coderabbit.yaml, tests/README.md, CONTRIBUTING.md, website/docs/project/contributing.md
Adds GitHub Flow branching docs, updates AGENTS.md and tests README, configures automated reviews in .coderabbit.yaml, and documents CodeRabbit tooling and contribution rules (including no direct pushes to main).

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰 I hopped through dialects, tidy and spry,
Generic by default, but Postgres waves hi.
A dialects list, and tests on parade,
Docs and CLI polished — a neat little trade.
Hooray — formatters hum as rabbits rejoice.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 2.08% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main changes: adding branch workflow documentation and implementing selectable SQL dialects, matching the core objectives of the PR.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch docs/branching-strategy

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Owner Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented May 23, 2026

Copy link
Copy Markdown
✅ 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
Copy Markdown
Owner Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented May 23, 2026

Copy link
Copy Markdown
✅ 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
Copy Markdown
Owner Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented May 23, 2026

Copy link
Copy Markdown
✅ 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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@py_sql_cleaner/adapters/sqlglot_formatter.py`:
- Around line 69-77: The current functions
_has_redshift_explicit_dialect_keyword and _starts_with_command use naive
substring/prefix checks which misclassify identifiers/literals containing words
like COPY or ENCODE; replace these with token-aware matching by running the SQL
through sqlglot's tokenizer/lexer and inspecting token types/values so you only
match standalone keywords (e.g., TokenType.KEYWORD) and not parts of identifiers
or string literals. Specifically, in _has_redshift_explicit_dialect_keyword
tokenize sql and return True if any token value (normalized/uppercased) equals
one of REDSHIFT_EXPLICIT_DIALECT_KEYWORDS and the token type is a
keyword/identifier appropriate for matching; in _starts_with_command tokenize
and check the first non-whitespace/comment token exactly equals one of the
provided commands (by token value/type) rather than using startswith on raw
text. Ensure tokens from comments/strings are ignored and preserve current
return semantics.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: edf34ea3-9e80-4d7e-8ca8-57df1203cb9a

📥 Commits

Reviewing files that changed from the base of the PR and between 32f7222 and 23010d8.

📒 Files selected for processing (9)
  • README.md
  • py_sql_cleaner/adapters/sqlglot_formatter.py
  • py_sql_cleaner/application/format_source.py
  • py_sql_cleaner/cli/app.py
  • tests/adapters/test_sqlglot_formatter.py
  • tests/cli/test_format_command.py
  • tests/core/test_detector.py
  • website/docs/intro.md
  • website/docs/reference/commands.md
✅ Files skipped from review due to trivial changes (3)
  • README.md
  • website/docs/intro.md
  • website/docs/reference/commands.md

Comment thread py_sql_cleaner/adapters/sqlglot_formatter.py
@enumura1
enumura1 merged commit caaf4b1 into main May 24, 2026
2 checks passed
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