Skip to content

Task to remove pre-commit hooks#14

Merged
ejfine merged 5 commits intomainfrom
precommittask
Feb 22, 2026
Merged

Task to remove pre-commit hooks#14
ejfine merged 5 commits intomainfrom
precommittask

Conversation

@ejfine
Copy link
Contributor

@ejfine ejfine commented Feb 22, 2026

Why is this change necessary?

Pre-commit hooks for lambda graphql cause problems if there is no backend

How does this change address the issue?

Use a copier task to remove them if there is no backend

What side effects does this change have?

N/A

How is this change tested?

ejfine/rytermedia-com#14

Other

Showing preview on PR now in CI

Summary by CodeRabbit

  • Chores
    • Automatically remove GraphQL Lambda-related pre-commit hooks when the backend option is disabled during template initialization.
    • Enable preview comments for pull requests in CI/CD deployment workflows by setting the preview flag for PR events.

@ejfine ejfine self-assigned this Feb 22, 2026
@coderabbitai
Copy link

coderabbitai bot commented Feb 22, 2026

Warning

Rate limit exceeded

@ejfine has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 3 minutes and 43 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.

📝 Walkthrough

Walkthrough

Adds a conditional Copier task that removes graphql_lambda-related hooks from the pre-commit config when has_backend is false; supplies a Python utility to detect and remove those hooks; and sets SHOW_PREVIEW_COMMENT_ON_PR in the CI prod Pulumi step for pull_request events.

Changes

Cohort / File(s) Summary
Copier Configuration
copier.yml
Appends a new _tasks item guarded by when: "{{ not has_backend }}" that echoes a message and runs copier_tasks/remove_graphql_lambda_hooks.py against .pre-commit-config.yaml.
Hook Removal Utility
copier_tasks/remove_graphql_lambda_hooks.py
New script implementing _is_graphql_lambda_hook_block(block_lines: list[str]) -> bool, remove_graphql_lambda_hook_blocks(config_path: Path) -> int, and main() -> int; reads a YAML file, removes hook blocks containing graphql_lambda / graphql-lambda, rewrites file when changes occur, and prints a summary.
CI Workflow
template/.github/workflows/ci.yaml.jinja
Adds env var SHOW_PREVIEW_COMMENT_ON_PR: true to the prod Pulumi deployment block when the GitHub event is a pull_request.

Sequence Diagram(s)

mermaid
sequenceDiagram
participant Copier as Copier template
participant Task as Pre-commit cleanup task
participant Script as remove_graphql_lambda_hooks.py
participant File as .pre-commit-config.yaml

Copier->>Task: Evaluate when: "{{ not has_backend }}"
Task-->>Script: Run Python script with target file
Script->>File: Read content
Script-->>Script: Detect and remove graphql_lambda blocks
Script->>File: Rewrite file if blocks removed
Script->>Task: Print summary & exit 0

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title 'Task to remove pre-commit hooks' clearly and concisely summarizes the main change: adding a new task to remove pre-commit hooks when there is no backend.
Description check ✅ Passed The description covers all required template sections including justification, solution approach, side effects, testing reference, and additional notes about CI changes.

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


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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

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

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@copier_tasks/remove_graphql_lambda_hooks.py`:
- Around line 11-13: The helper _is_graphql_lambda_hook_block currently checks
the whole block text and can false-positive on args/files; change it to inspect
only the hook's id line: scan block_lines for the line that contains "id:" (trim
leading whitespace and any list marker like "-" or "- ") and then test whether
the id value contains "graphql_lambda" or "graphql-lambda" (case-sensitive as
currently used); return True only when the id line matches, otherwise False.
This keeps the check targeted to the hook id and avoids matching substrings in
args/files.
- Around line 24-60: The existing line-based removal (HOOK_ID_LINE,
_is_graphql_lambda_hook_block) can leave an empty "hooks:" key when all hooks
under a repo are removed; update remove_graphql_lambda_hooks.py so after
computing output_lines and before writing via config_path.write_text it either
(a) parses the YAML with PyYAML, removes any repo entries where the "hooks" key
is empty/null, and then dumps the cleaned structure back to text, or (b)
implements a post-pass over output_lines to detect and remove a "hooks:" key
that is followed only by whitespace/indentation and no list items for that repo;
ensure this change integrates with the existing removed_count logic and still
writes via config_path.write_text.

Comment on lines +24 to +60
while index < len(lines):
line = lines[index]
stripped = line.lstrip()
indentation = len(line) - len(stripped)

if HOOK_ID_LINE.match(stripped):
block_start = index
block_end = index + 1

while block_end < len(lines):
next_line = lines[block_end]
next_stripped = next_line.lstrip()
next_indentation = len(next_line) - len(next_stripped)
if HOOK_ID_LINE.match(next_stripped) and next_indentation == indentation:
break
if next_stripped and next_indentation < indentation:
break
block_end += 1

block_lines = lines[block_start:block_end]
if _is_graphql_lambda_hook_block(block_lines):
removed_count += 1
index = block_end
continue

output_lines.extend(block_lines)
index = block_end
continue

output_lines.append(line)
index += 1

if removed_count == 0:
return 0

trailing_newline = "\n" if text.endswith("\n") else ""
_ = config_path.write_text("\n".join(output_lines) + trailing_newline, encoding="utf-8")
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

🧩 Analysis chain

🏁 Script executed:

fd ".pre-commit-config.yaml" template/ --exec grep -n "graphql.lambda\|graphql_lambda" {}

Repository: LabAutomationAndScreening/copier-nuxt-static-aws

Length of output: 74


🏁 Script executed:

# First, let's understand the repository structure
ls -la

Repository: LabAutomationAndScreening/copier-nuxt-static-aws

Length of output: 2080


🏁 Script executed:

# Let's look at the actual file mentioned in the review
head -100 copier_tasks/remove_graphql_lambda_hooks.py

Repository: LabAutomationAndScreening/copier-nuxt-static-aws

Length of output: 2509


🏁 Script executed:

find template -name ".pre-commit-config.yaml" -o -name "*.pre-commit-config.yaml"

Repository: LabAutomationAndScreening/copier-nuxt-static-aws

Length of output: 124


🏁 Script executed:

ls -la template/

Repository: LabAutomationAndScreening/copier-nuxt-static-aws

Length of output: 1907


🏁 Script executed:

# Check if there's a template pre-commit config with any content
find template -type f -name "*pre-commit*" -o -name "*hook*"

Repository: LabAutomationAndScreening/copier-nuxt-static-aws

Length of output: 167


🏁 Script executed:

cat template/.pre-commit-config.yaml

Repository: LabAutomationAndScreening/copier-nuxt-static-aws

Length of output: 14297


🏁 Script executed:

# Check the graphql_lambda conditional directory
ls -la "template/{% if has_backend %}graphql_lambda{% endif %}" 2>/dev/null || echo "Directory name not literal"

Repository: LabAutomationAndScreening/copier-nuxt-static-aws

Length of output: 382


🏁 Script executed:

# Check what's in template with graphql in name
find template -type d | grep -i graphql

Repository: LabAutomationAndScreening/copier-nuxt-static-aws

Length of output: 146


Orphaned hooks: key left when all hooks in a repo block are removed.

The algorithm removes - id: … blocks but emits non-hook lines verbatim. If a repos: entry contains only graphql_lambda hooks (isolated in their own block), removing them leaves a hooks: key with no items—YAML treats that as hooks: null, and pre-commit fails to parse the result.

Minimal example:

repos:
  - repo: https://github.com/example/graphql-lambda-hooks
    rev: v1.0.0
    hooks:
      - id: graphql_lambda_check
        name: GraphQL Lambda Check

After running the script:

repos:
  - repo: https://github.com/example/graphql-lambda-hooks
    rev: v1.0.0
    hooks:

The current template does not have this issue since graphql_lambda hooks are mixed with other hooks in a shared local repo block. However, the algorithm should be made robust to this edge case. The safest fix is to use PyYAML (already available via pre-commit's dependency chain) to parse, filter, and rewrite the config. Alternatively, a post-pass can detect and strip repo entries whose hooks: key has become empty.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@copier_tasks/remove_graphql_lambda_hooks.py` around lines 24 - 60, The
existing line-based removal (HOOK_ID_LINE, _is_graphql_lambda_hook_block) can
leave an empty "hooks:" key when all hooks under a repo are removed; update
remove_graphql_lambda_hooks.py so after computing output_lines and before
writing via config_path.write_text it either (a) parses the YAML with PyYAML,
removes any repo entries where the "hooks" key is empty/null, and then dumps the
cleaned structure back to text, or (b) implements a post-pass over output_lines
to detect and remove a "hooks:" key that is followed only by
whitespace/indentation and no list items for that repo; ensure this change
integrates with the existing removed_count logic and still writes via
config_path.write_text.

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.

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Duplicate comments:
In `@copier_tasks/remove_graphql_lambda_hooks.py`:
- Around line 24-61: When removing graphql_lambda hook blocks in the loop that
builds output_lines, also detect and remove an orphaned "hooks:" key so a repo
block doesn’t end up with an empty hooks: entry; specifically, when you skip a
hook block (use the same block_start/block_end and block_lines logic and
_is_graphql_lambda_hook_block), check the line immediately before block_start in
output_lines (or the line at block_start-1 in lines) for a "hooks:" key with the
same indentation and remove that "hooks:" line as well if there are no remaining
"- id:" hook entries for that repo (i.e., the next non-empty/indented lines are
not list items); ensure this uses the existing
HOOK_ID_LINE/_is_graphql_lambda_hook_block logic and updates
output_lines/removed_count before writing via config_path.write_text.

@ejfine ejfine merged commit 6eb2eb7 into main Feb 22, 2026
7 checks passed
@ejfine ejfine deleted the precommittask branch February 22, 2026 21:22
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