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 the copy of your code is deleted when each review ends. Keep reading below if you prefer to run inside your own GitHub Actions runner.

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 of your repository to its own review machine and deletes the copy when the review ends. The diff and the code the reviewer reads go through MegaLens to OpenAI. MegaLens keeps no copy of your code.

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@38aae94fbc4f4bdb05964c249d106c1c13cb632c # v1.3.0
            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@38aae94fbc4f4bdb05964c249d106c1c13cb632c # v1.3.0
            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@38aae94fbc4f4bdb05964c249d106c1c13cb632c # v1.3.0
            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.0 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@38aae94fbc4f4bdb05964c249d106c1c13cb632c # v1.3.0
        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@38aae94fbc4f4bdb05964c249d106c1c13cb632c # v1.3.0
        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@38aae94fbc4f4bdb05964c249d106c1c13cb632c # v1.3.0
        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.