Skip to content

Add pre-commit config for repo hygiene and secret detection - #334

Open
Harshaada wants to merge 3 commits into
redhat-data-and-ai:mainfrom
Harshaada:pre-commit-config
Open

Add pre-commit config for repo hygiene and secret detection#334
Harshaada wants to merge 3 commits into
redhat-data-and-ai:mainfrom
Harshaada:pre-commit-config

Conversation

@Harshaada

Copy link
Copy Markdown

Changes

📝 Description

What changed?

  • Added .pre-commit-config.yaml with hygiene hooks (trailing-whitespace, end-of-file-fixer, check-yaml, detect-private-key, check-merge-conflict) and gitleaks for secret detection.
  • Updated CONTRIBUTING.md with steps to install and enable pre-commit locally.

Why is this change needed?

Contributors currently have no shared local checks for common file issues and accidental secret commits. Pre-commit gives a consistent gate before code reaches GitHub (where secret scanning / push protection can add defense in depth).

Dependencies

Local: pip install pre-commit (Go >= 1.23.8 for the gitleaks hook)


🧪 Testing

Test Coverage

  • Verified config and contribution docs locally.
  • After install, run: pre-commit run --all-files

Performance Impact

  • N/A

🚀 Deployment

Deploy Steps

  1. N/A

Prerequisites

  • N/A

Post-Deployment Monitoring

  • N/A

Rollback Plan

Revert this PR / remove .pre-commit-config.yaml if needed


⚠️ Breaking Changes

  • This PR contains breaking changes
  • Migration guide provided (if applicable)

Details:

  • N/A

⚙️ Configuration Changes

  • N/A

✅ Developer Checklist

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have added positive and negative tests that prove my fix is effective or that my feature works
  • Relevant documentation (README, tech specs, etc.) has been added or updated
  • All CI/CD checks are passing

@coderabbitai

coderabbitai Bot commented Aug 10, 2026

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

@Harshaada, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 27 minutes

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 20b7df21-84ac-4b87-a0b1-ea71baf923c9

📥 Commits

Reviewing files that changed from the base of the PR and between 8f26782 and 5bcdcdd.

📒 Files selected for processing (1)
  • .pre-commit-config.yaml
📝 Walkthrough

Summary by CodeRabbit

  • Chores

    • Added automated checks for formatting, YAML validity, merge conflicts, exposed private keys, and leaked secrets before commits.
    • Added instructions for installing and running the checks manually.
  • Documentation

    • Updated contribution guidance to include pre-commit setup and usage.

Walkthrough

The repository now includes a pre-commit configuration with validation and secret-scanning hooks. CONTRIBUTING.md documents pre-commit setup and updates the contribution step numbering.

Changes

Pre-commit adoption

Layer / File(s) Summary
Pre-commit checks and contributor instructions
.pre-commit-config.yaml, CONTRIBUTING.md
The repository adds hygiene, YAML, private-key, merge-conflict, and Gitleaks hooks. Contribution instructions add pre-commit installation and usage steps.

Estimated code review effort: 2 (Simple) | ~10 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the addition of repository hygiene and secret-detection pre-commit checks.
Description check ✅ Passed The description covers the changes, rationale, dependencies, testing, deployment, rollback, and breaking-change status.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
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.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

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

🤖 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 @.pre-commit-config.yaml:
- Around line 10-14: Preserve the existing project checks by updating the
pre-commit configuration around the hooks list to run the equivalent of
scripts/check-secrets.sh and make lint test, or ensure the legacy
scripts/pre-commit chain remains invoked alongside the configured hooks. Keep
both the pre-commit hook checks and the project-specific checks active.
- Around line 23-27: Add a separate full-repository Gitleaks scan alongside the
existing gitleaks hook, using a command such as gitleaks detect --source .; keep
the current staged-change hook unchanged and ensure the new scan runs against
the entire repository rather than passed filenames.
🪄 Autofix

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: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: d3e22625-e81c-41bb-8ad9-87b18e3dcd2a

📥 Commits

Reviewing files that changed from the base of the PR and between edf1baa and 8f26782.

📒 Files selected for processing (2)
  • .pre-commit-config.yaml
  • CONTRIBUTING.md

Comment thread .pre-commit-config.yaml
Comment on lines +10 to +14
repos:
# Generic file and repo hygiene (pre-commit/pre-commit-hooks)
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v6.0.0
hooks:

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🗄️ Data Integrity & Integration | 🟠 Major | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "== files =="
git ls-files | rg '(^|\.)pre-commit|^scripts/pre-commit|^Makefile|check-secrets' || true

echo
echo "== .pre-commit-config.yaml =="
cat -n .pre-commit-config.yaml

echo
echo "== scripts/pre-commit =="
cat -n scripts/pre-commit

echo
echo "== Makefile relevant lines =="
sed -n '180,210p' Makefile | cat -n

echo
echo "== scripts/check-secrets related =="
if [ -x scripts/check-secrets.sh ]; then cat -n scripts/check-secrets.sh; fi

echo
echo "== pre-commit install references =="
rg -n "pre-commit install|scripts/pre-commit|\.git/hooks/pre-commit|make lint test|check-secrets" Makefile .pre-commit-config.yaml scripts || true

Repository: redhat-data-and-ai/usernaut

Length of output: 15586


Preserve the existing project checks.

.pre-commit.config.yaml installs hooks via pre-commit install, but Makefile installs .git/hooks/pre-commit from scripts/pre-commit, which runs scripts/check-secrets.sh and make lint test. That make lint test step is not replaced by the added pre-commit hooks. Add an equivalent local hook, or make the legacy hook chain both pre-commit and the project checks.

🤖 Prompt for 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.

In @.pre-commit-config.yaml around lines 10 - 14, Preserve the existing project
checks by updating the pre-commit configuration around the hooks list to run the
equivalent of scripts/check-secrets.sh and make lint test, or ensure the legacy
scripts/pre-commit chain remains invoked alongside the configured hooks. Keep
both the pre-commit hook checks and the project-specific checks active.

Source: Path instructions

Comment thread .pre-commit-config.yaml
Comment on lines +23 to +27
# Secret detection (requires Go >= 1.23.8; run: brew upgrade go)
- repo: https://github.com/gitleaks/gitleaks
rev: v8.28.0
hooks:
- id: gitleaks

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🔒 Security & Privacy | 🟠 Major | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/usr/bin/env bash
set -euo pipefail

curl -fsSL \
  https://raw.githubusercontent.com/gitleaks/gitleaks/v8.28.0/.pre-commit-hooks.yaml |
  grep -A8 'id: gitleaks'

Repository: redhat-data-and-ai/usernaut

Length of output: 800


🏁 Script executed:

#!/usr/bin/env bash
set -euo pipefail

python3 - <<'PY'
from pathlib import Path
p = Path(".pre-commit-config.yaml")
print("exists:", p.exists())
if p.exists():
    lines = p.read_text(encoding="utf-8").splitlines()
    for i, line in enumerate(lines, start=1):
        if 19 <= i <= 30:
            print(f"{i:4}: {line}")
PY

Repository: redhat-data-and-ai/usernaut

Length of output: 503


Provide a full-repository Gitleaks scan path.

The Gitleaks pre-commit hook runs gitleaks git --pre-commit --redact --staged --verbose with pass_filenames: false, so staged hook execution only scans staged changes. Add a separate full-repository scan, such as a new pre-commit hook with gitleaks detect --source . or gitleaks git --staged-only, or document the required command.

🤖 Prompt for 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.

In @.pre-commit-config.yaml around lines 23 - 27, Add a separate full-repository
Gitleaks scan alongside the existing gitleaks hook, using a command such as
gitleaks detect --source .; keep the current staged-change hook unchanged and
ensure the new scan runs against the entire repository rather than passed
filenames.

Source: Path instructions

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