Home/Install the GitHub Action

Install the GitHub Action. A second reviewer for every pull request.

The MegaLens GitHub Action reads each pull request and leaves its notes right on the lines it is talking about. The review runs in GitHub Actions in your repository.

Faster setup: GitHub App

Skip workflow YAML and repository secrets with the MegaLens GitHub App

Use the GitHub App to connect a repository directly from GitHub. Reviews run on MegaLens's review machine and remove the working repository copy when each review ends. See our Privacy Policy for result storage and AI provider retention. Keep reading below if you prefer to run inside your own GitHub Actions runner.

GitHub App pull request checks

Each full Standard pull request review from the GitHub App ends with a Review result line and sets the GitHub check conclusion based on findings, review completeness, and a built-in sensitive path policy (authentication, permissions, cryptography, payments, billing, database migrations, public API contracts, CI workflows, and files excluded from automated review). The GitHub Action workflow is unchanged.

  • success: the review completed with full coverage, reported no P0 or P1 findings, and no sensitive path matched the policy.
  • neutral: P0 or P1 findings were reported (including in existing code outside the change), a sensitive path matched the policy, or review coverage was incomplete (for example a failed or too large review).

GitHub branch protection accepts neutral on a required status check without blocking merges. Repositories using external auto-merge rules that require an exact success conclusion will hold pull requests that receive neutral for human review.

Start free with GitHub

By clicking Start free with GitHub, you agree to the Terms of Service and Privacy Policy, and acknowledge: For each review, MegaLens copies the reviewed commits to its review machine and removes that working copy when the review finishes. Review results (which may include short code snippets) are kept for 24 hours, or longer if you turn on history. Code sent to OpenAI (or Google, when enabled) is subject to each provider's API retention terms, including OpenAI abuse-monitoring logs kept for up to 30 days. See the Privacy Policy for details.

What it does

  • It gives every pull request a second reviewer.
  • A Standard review starts by itself when a pull request is opened or updated.
  • Add the comment workflow to request a Deep review from a pull request.
  • The automatic workflow skips pull requests from forks, which are copies of your repository.

Install in three steps

  1. 1

    Make an Action token

    Open your MegaLens setup page. Under Review every pull request, choose Create Action token, then copy it. You will only see it once. The Editor token on that page is a different token, for your editor. Do not use it here.

  2. 2

    Save it as a secret in your repository

    In GitHub, open your repository, then Settings, then Secrets and variables, then Actions. Choose New repository secret. Use the name MEGALENS_TOKEN. For the value, paste in what you copied.

  3. 3

    Add the workflow file

    Make a file called .github/workflows/megalens-review.yml in your repository and paste this in. It starts a Standard review on every pull request.

    This version has three jobs (create, review and publish). They keep your secret, the pull request's code and the comment writing apart. It reviews pull requests from branches in your own repository. For Deep reviews and pull requests from forks, add the comment workflow.

    Automatic review workflow
    name: MegaLens Review
    
    on:
      pull_request:
        types: [opened, synchronize, reopened]
    
    permissions: {}
    
    # A new push cancels the review still running for an older commit.
    concurrency:
      group: megalens-${{ github.event.pull_request.number }}
      cancel-in-progress: true
    
    jobs:
      create:
        runs-on: ubuntu-latest
        permissions: {}
        outputs:
          review_id: ${{ steps.create.outputs.review_id }}
          review_key: ${{ steps.create.outputs.review_key }}
          head_sha: ${{ steps.create.outputs.head_sha }}
          base_sha: ${{ steps.create.outputs.base_sha }}
        steps:
          - id: create
            uses: megalens/review-action@3adef5e41760c99d9d52f96a7b3c0decdea24a5f # v1.3.1
            with:
              mode: create
              tier: standard
              megalens-token: ${{ secrets.MEGALENS_TOKEN }}
    
      review:
        needs: create
        if: ${{ needs.create.outputs.review_id != '' }}
        runs-on: ubuntu-latest
        permissions:
          contents: read
        steps:
          - name: Mask review key
            env:
              REVIEW_KEY: ${{ needs.create.outputs.review_key }}
            run: echo "::add-mask::$REVIEW_KEY"
    
          - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
            with:
              fetch-depth: 0
              persist-credentials: false
    
          - uses: megalens/review-action@3adef5e41760c99d9d52f96a7b3c0decdea24a5f # v1.3.1
            env:
              MEGALENS_REVIEW_ID: ${{ needs.create.outputs.review_id }}
              MEGALENS_REVIEW_KEY: ${{ needs.create.outputs.review_key }}
            with:
              mode: review
              tier: standard
              head-sha: ${{ needs.create.outputs.head_sha }}
              base-sha: ${{ needs.create.outputs.base_sha }}
              artifact-name: megalens-findings
              findings-path: ${{ runner.temp }}/findings.json
    
          - uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
            if: always()
            with:
              name: megalens-findings
              path: ${{ runner.temp }}/findings.json
              if-no-files-found: ignore
    
      publish:
        needs: [create, review]
        if: always() && needs.review.result != 'skipped'
        runs-on: ubuntu-latest
        permissions:
          contents: read
          pull-requests: write
        steps:
          - uses: actions/download-artifact@d3f86a106a0bac45b974a628896c90dbdf5c8093 # v4.3.0
            with:
              name: megalens-findings
              path: ${{ runner.temp }}
    
          - uses: megalens/review-action@3adef5e41760c99d9d52f96a7b3c0decdea24a5f # v1.3.1
            with:
              mode: publish
              tier: standard
              head-sha: ${{ needs.create.outputs.head_sha }}
              artifact-name: megalens-findings
              findings-path: ${{ runner.temp }}/findings.json
              inline: true
              fail-on: none

    The action is pinned to the v1.3.1 release commit.

Run /megalens deep with a comment (and review fork pull requests)

GitHub does not give your MegaLens secret to a workflow that runs for a fork's pull request, so the first workflow above skips forks. A maintainer starts the review instead: look at the fork's change first, then write a comment on the pull request. The comment workflow below runs in your own repository, where the secret is available.

Write one of these as a comment on a pull request:

  • /megalens deep starts a Deep review.
  • /megalens review starts a Standard review.

Only people with write, maintain or admin access to the repository can use the command. To turn the command on, add this second workflow file, for example .github/workflows/megalens-comment-review.yml.

Comment review workflow
name: MegaLens Comment Review

on:
  issue_comment:
    types: [created]

permissions: {}

concurrency:
  group: megalens-${{ github.event.issue.number }}
  cancel-in-progress: true

jobs:
  create:
    if: >-
      github.event.issue.pull_request &&
      (contains(github.event.comment.body, '/megalens deep') ||
       contains(github.event.comment.body, '/megalens review'))
    runs-on: ubuntu-latest
    permissions:
      contents: read
      pull-requests: read
    outputs:
      review_id: ${{ steps.create.outputs.review_id }}
      review_key: ${{ steps.create.outputs.review_key }}
      head_sha: ${{ steps.create.outputs.head_sha }}
      base_sha: ${{ steps.create.outputs.base_sha }}
    steps:
      - id: create
        uses: megalens/review-action@3adef5e41760c99d9d52f96a7b3c0decdea24a5f # v1.3.1
        with:
          mode: create
          tier: standard
          megalens-token: ${{ secrets.MEGALENS_TOKEN }}

  review:
    needs: create
    if: ${{ needs.create.outputs.review_id != '' }}
    runs-on: ubuntu-latest
    permissions:
      contents: read
    steps:
      - name: Mask review key
        env:
          REVIEW_KEY: ${{ needs.create.outputs.review_key }}
        run: echo "::add-mask::$REVIEW_KEY"

      - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
        with:
          ref: ${{ needs.create.outputs.head_sha }}
          fetch-depth: 0
          persist-credentials: false

      - uses: megalens/review-action@3adef5e41760c99d9d52f96a7b3c0decdea24a5f # v1.3.1
        env:
          MEGALENS_REVIEW_ID: ${{ needs.create.outputs.review_id }}
          MEGALENS_REVIEW_KEY: ${{ needs.create.outputs.review_key }}
        with:
          mode: review
          tier: standard
          head-sha: ${{ needs.create.outputs.head_sha }}
          base-sha: ${{ needs.create.outputs.base_sha }}
          artifact-name: megalens-findings
          findings-path: ${{ runner.temp }}/findings.json

      - uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
        if: always()
        with:
          name: megalens-findings
          path: ${{ runner.temp }}/findings.json
          if-no-files-found: ignore

  publish:
    needs: [create, review]
    if: always() && needs.review.result != 'skipped'
    runs-on: ubuntu-latest
    permissions:
      contents: read
      pull-requests: write
    steps:
      - uses: actions/download-artifact@d3f86a106a0bac45b974a628896c90dbdf5c8093 # v4.3.0
        with:
          name: megalens-findings
          path: ${{ runner.temp }}

      - uses: megalens/review-action@3adef5e41760c99d9d52f96a7b3c0decdea24a5f # v1.3.1
        with:
          mode: publish
          tier: standard
          head-sha: ${{ needs.create.outputs.head_sha }}
          artifact-name: megalens-findings
          findings-path: ${{ runner.temp }}/findings.json
          inline: true
          fail-on: none

Never run install steps, builds or tests from an untrusted pull request in a job that holds a secret. The workflows above keep the secret, the code and the comment writing in three separate jobs for this reason. Please keep them separate.

Run the review engine locally

The same engine can review changes on your computer. See the local setup and system requirements.

What it costs

A Standard review uses 1 credit and a Deep review uses 8. 3 reviews free, no card. Applies to Standard reviews. If a review fails because of us, it costs 0 credits.

  • Pay as you go: $1.25 a credit, from $5.
  • Plus: $19 a month, 20 credits
  • Pro: $69 a month, 80 credits
  • Max: $199 a month, 250 credits

Plan credits are used first, then pay as you go credits. See pricing for the full details.

Your code and your data

The GitHub Action runs on your own GitHub runner. We do not copy your whole repository to our servers. To review a change, the reviewer reads the change and the parts of your code around it. Those parts, and our review instructions, go over an encrypted connection to the MegaLens review service, which passes them to the AI model provider that writes the review. We try to spot passwords and keys and blank them out before anything is sent, and again on our side. No filter is perfect, so please do not keep secrets in your code.

Read more in our privacy policy.