mech.app
Automation

AI Code Review Across 240 Repos: Cron Orchestration, Secret Scanning, and Auto-Merge Plumbing

How one developer wired Z.AI GLM models into GitHub Actions for PR review, secret scanning, and auto-merge across 240 repositories using cron.

Source: dev.to
AI Code Review Across 240 Repos: Cron Orchestration, Secret Scanning, and Auto-Merge Plumbing

Running AI code review on one repository is a weekend project. Running it on 240 repositories without manual intervention is an orchestration problem. Sulthon Zainul Habib built a GitHub Action that fires five sequential jobs on every pull request: secret scan, AI review via Z.AI’s GLM models, quality gate, auto-merge, and auto-release. Then he built OpenClaw, a cron system that monitors workflow runs to keep the entire system alive.

The real problem is not code review quality. It is keeping dozens of jobs alive across 240 repos without manual intervention, rate-limit failures, secret leaks, or merge conflicts.

The Five-Job Pipeline

Each PR triggers a workflow with strict sequencing and concurrency control:

  1. Secret scan: diffs the changeset for API keys, passwords, private keys
  2. AI review: sends the diff to Z.AI’s GLM model, returns security/quality/style feedback
  3. Quality gate: runs linting, type checks, test thresholds
  4. Auto-merge: merges if AI approved AND quality passed
  5. Auto-release: on push to main, cuts a GitHub release with changelog

The workflow uses concurrency.group: review-${{ github.ref }} with cancel-in-progress: true to prevent duplicate runs when developers force-push during review.

concurrency:
  group: review-${{ github.ref }}
  cancel-in-progress: true

permissions:
  pull-requests: write
  contents: write
  checks: write
  statuses: write

Permissions are scoped to the minimum required for each job. The secret scan needs read access to the diff. The auto-merge needs write access to pull requests and contents. The auto-release needs write access to create tags and releases.

Secret Scanning as a Blocking Gate

The secret scan runs first and blocks the entire pipeline if it finds leaked credentials. It outputs a boolean secrets_found that downstream jobs check before proceeding.

- name: Scan diff for secrets
  id: scan
  uses: sulthonzh/code-reviewer@main
  with:
    command: secret-scan
    github-token: ${{ secrets.GITHUB_TOKEN }}

- name: Block if secrets found
  if: steps.scan.outputs.found == 'true'
  run: |
    echo "::error::Found potential secret(s) in the diff. Remove before merging."
    exit 1

This is a hard stop. If the scan finds a match, the workflow fails immediately and the PR cannot merge. The AI review never runs. The quality gate never runs. The developer gets an error annotation on the PR.

The scan uses pattern matching against known secret formats (AWS keys, GitHub tokens, private keys). It does not send code to an external API. It runs entirely within the GitHub Actions runner.

AI Review via Z.AI GLM Models

The AI review job sends the PR diff to Z.AI’s GLM model via their coding API endpoint at https://api.z.ai/api/coding/paas/v4/. The model returns structured feedback on security issues, code quality, and style violations.

The action posts the feedback as a PR comment and sets a check status. If the model flags critical issues, the check fails and blocks auto-merge.

The API call includes:

  • The full diff as a string
  • Repository context (language, framework, dependencies)
  • Review focus areas (security, performance, maintainability)

The response is JSON with severity levels, line numbers, and suggested fixes. The action parses this and formats it as a GitHub comment with code annotations.

Auto-Merge Logic and Safety Rails

Auto-merge only triggers if:

  1. Secret scan passed (no leaked credentials)
  2. AI review approved (no critical issues flagged)
  3. Quality gate passed (linting, type checks, tests)
  4. PR is not a draft
  5. PR has no merge conflicts

The action uses GitHub’s merge API with the squash strategy by default. It waits for all required status checks to complete before attempting the merge.

If any condition fails, the PR stays open and the developer gets a notification with the failure reason. The action does not retry. It waits for the next push event.

OpenClaw: The Cron System That Monitors Workflow Runs

Running 240 repositories means 240 potential workflow runs on every push. GitHub Actions has rate limits. Workflows can fail silently. Jobs can get stuck in pending state.

OpenClaw is a cron system that monitors active AI agent jobs and restarts them if they fail or hang. The author reports managing 56 jobs across different repositories and different agent types (code review, dependency updates, security scans, documentation generation).

The system queries the GitHub API for workflow run status across all monitored repositories. If a job is overdue, it triggers a repository dispatch event to restart the workflow. If a job fails repeatedly, the system alerts the developer.

Deploying to 240 Repositories: Centralized Action, Distributed Workflows

Deploying the code reviewer to 240 repositories requires a consistent workflow file in each repo’s .github/workflows/ directory. The action itself is centralized in a single repository (sulthonzh/code-reviewer) and versioned with tags.

Each repository references the action via:

uses: sulthonzh/code-reviewer@main

This means updates to the action logic propagate to all 240 repositories immediately. No need to update 240 workflow files. The trade-off is that a breaking change in the action breaks all repositories at once.

To mitigate this, the action uses semantic versioning and repositories can pin to specific versions:

uses: sulthonzh/code-reviewer@v1.2.3

The developer maintains a changelog and marks breaking changes clearly. Repositories can upgrade at their own pace.

Rate Limits and API Quotas

GitHub Actions has a rate limit of 1,000 API requests per hour per repository. The code reviewer makes approximately 5 API calls per PR (fetch diff, post comment, set check status, merge, create release).

With 240 repositories, a simultaneous push to all repos would trigger 1,200 API calls in a few seconds. This exceeds the rate limit.

The solution is staggered execution. The cron system tracks the last run time for each repository and spreads workflow triggers across a time window to keep the API call rate manageable.

The action includes exponential backoff and retry logic for API calls. If an API returns a rate-limit error, the action waits and retries up to 3 times.

Observability and Common Failure Modes

Each workflow run logs to GitHub Actions. The cron system aggregates these logs and tracks success rates, average review times, and API error rates across all repositories.

Common failure modes observed in this deployment include:

  • API timeouts requiring retry logic
  • Merge conflicts blocking auto-merge
  • Secret scan false positives requiring manual override
  • Quality gate flakiness from transient test failures
  • GitHub API rate limits requiring staggered execution

The action includes structured logging with trace IDs. Each PR review gets a unique ID that links the secret scan, AI review, quality gate, and merge attempt. This makes debugging easier when a workflow fails halfway through.

Security Boundaries

The code reviewer runs with elevated permissions (write access to pull requests and contents). This is necessary for auto-merge and auto-release, but it creates a security risk.

If an attacker compromises the action repository or the Z.AI API, they could inject malicious code into all 240 repositories.

Mitigations:

  • The action repository requires signed commits and branch protection
  • Z.AI API calls use a dedicated service account with scoped permissions
  • The secret scan runs before the AI review to catch leaked credentials early
  • Auto-merge only triggers if all checks pass (no way to bypass the quality gate)
  • The cron system monitors for unexpected workflow runs and alerts on anomalies

The action does not store secrets in the repository. It uses GitHub’s encrypted secrets feature and passes them as environment variables at runtime.

Technical Verdict

Use this pattern when:

  • You maintain dozens or hundreds of repositories with similar review requirements
  • You need consistent code quality enforcement without manual review overhead
  • You can tolerate occasional false positives in secret scanning or AI feedback
  • You have the infrastructure to run a monitoring system for job health

Avoid this pattern when:

  • You need human review for compliance or regulatory reasons
  • Your repositories have wildly different languages, frameworks, or quality standards
  • You cannot afford the risk of auto-merge introducing bugs
  • You do not have the bandwidth to monitor and tune the AI model’s feedback quality

The real value is not the AI review itself. It is the orchestration layer that makes AI review practical at scale. The secret scan, quality gate, and auto-merge logic turn the AI from a suggestion engine into a deployment gate. The cron system turns a collection of GitHub Actions into a reliable system.

If you are running AI agents in production, you need automated monitoring and recovery. The agents will fail. The APIs will rate-limit. The workflows will hang. Without a system to detect and restart failed jobs, you will spend your days restarting them manually.

Tags

agentic-ai orchestration infrastructure

Primary Source

dev.to