JSPM

gitlab-mr-ai

1.0.1
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 13
  • Score
    100M100P100Q45720F
  • License MIT

AI-powered GitLab Merge Request summarizer CLI tool

Package Exports

  • gitlab-mr-ai
  • gitlab-mr-ai/dist/main.js

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (gitlab-mr-ai) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

gitlab-mr-ai

npm version build status

AI-powered CLI tool to generate GitLab Merge Request summaries using Google Gemini.

Generate clear, structured summaries for your GitLab merge requests โ€” fully automated and CI/CD-friendly. This CLI tool analyzes diffs from your MR and uses Gemini to generate a concise description and key file changes.


๐Ÿ“š Table of Contents


๐Ÿš€ Installation

npm install -g gitlab-mr-ai
# or use npx without install
npx gitlab-mr-ai generate --mr 123

๐Ÿ’ป Usage (Local)

mr-ai generate --mr <merge-request-id> [options]

Example:

mr-ai generate --mr 927 --output console

To load environment variables locally, you can:

# using dotenv-cli (recommended for simplicity)
npm install -g dotenv-cli
dotenv -e .env -- mr-ai generate --mr 927

# or with native bash
source .env && mr-ai generate --mr 927

โš™๏ธ Usage (GitLab CI/CD)

๐Ÿ’ก You can configure GitLab CI/CD to run this tool automatically or manually on merge requests.

Example .gitlab-ci.yml job:

mr-summary:
  stage: quality-gate
  image: node:20
  script:
    - npx gitlab-mr-ai generate --mr "$CI_MERGE_REQUEST_IID" --output post
  rules:
    - if: $CI_PIPELINE_SOURCE == "merge_request_event"
      when: manual

๐Ÿงฉ CLI Parameters

Below is a list of CLI flags supported by mr-ai, including what they do and when to use them.

Flag Alias Required Description
--mr -m โœ… Yes Merge request IID to summarize
--template -t โŒ No Template name (standard, bug-fix, general) or file path to .md
--prompt -p โŒ No Custom prompt file path (.txt) for Gemini
--output -o โŒ No console, file, or post (default: console)

Flag Descriptions

  • --mr, -m (required)
    The Merge Request IID (internal ID visible in the GitLab URL, like /merge_requests/123). This is used to fetch the diff and identify which MR to summarize.

  • --template, -t
    Optional. Specifies which Markdown template to use. You can:

    • Pass a built-in template name: standard, bug-fix, or general
    • Or pass a file path to a custom template, e.g. ./my-template.md
  • --prompt, -p
    Optional. Specify a custom prompt file (.txt) to send to Gemini. If not provided, a default prompt will be used.

  • --output, -o
    Optional. Defines where the generated summary goes:

    • console (default): print to terminal
    • file: write to mr-summary-<mrId>.md
    • post: update the MR's description directly in GitLab
# Basic usage (console output)
mr-ai generate --mr 1010

# Use general template explicitly
mr-ai generate --mr 1010 --template general

# Use external template & prompt, write to file
mr-ai generate --mr 1010 --template ./my-template.md --prompt ./my-prompt.txt --output file

# Post directly to GitLab MR
mr-ai generate --mr 1010 --output post

๐Ÿง  Branch & Ticket Detection

If no --template is provided, the CLI tries to auto-detect based on your branch name:

  • fix/123-title โ†’ uses bug-fix.md
  • feat/PL-456-feature โ†’ uses standard.md
  • Otherwise โ†’ fallback to general.md

Ticket ID is also auto-detected and injected into the template:

  • #123 for numeric branches
  • PL-456 if prefixed

๐ŸŒ General Usage & Fallbacks

You do not need to follow any branch naming convention.

To disable smart detection and use the general fallback always:

mr-ai generate --mr 9001 --template general

Alternatively, if you prefer to keep smart detection off by default, you can:

  • Use a generic or unmatched branch name (e.g. feature/login-screen)
  • Pass the --template general flag explicitly in every usage (recommended for general use cases)

Fallbacks will:

  • Use the general.md template if format isn't recognized
  • Skip ticket injection if none detected
  • Still render valid output from Gemini

You can also:

  • Provide your own Markdown template (--template ./custom.md)
  • Provide your own prompt (--prompt ./custom.txt)

๐Ÿ” Environment Variables

โ— When running in GitLab CI/CD, these variables should be configured under Settings โ†’ CI/CD โ†’ Variables. You do not need to manually export them in the pipeline script.

Set via .env or CI variables:

Key Required Description
GEMINI_API_KEY โœ… Google Generative AI API key
GITLAB_TOKEN โœ… GitLab personal access token (project read/write)
GITLAB_PROJECT_ID โœ… GitLab project numeric ID
GITLAB_API_URL โŒ GitLab API URL (default: https://gitlab.com/api/v4)
GEMINI_MODEL โŒ Gemini model ID (default: gemini-1.5-flash)

๐Ÿงผ Troubleshooting

Missing required env variable:

โŒ Missing required .env variables: GEMINI_API_KEY, GITLAB_TOKEN

โžก๏ธ Check your .env or CI settings

Template not found:

โŒ Failed to read template at ./custom.md

โžก๏ธ Make sure the file path exists and is valid


๐Ÿ“ฆ License

MIT