An AI-powered TypeScript npm library for automated code reviews during merge requests, designed for both free and premium use cases. It integrates with multiple SCM providers (e.g., GitHub, GitLab, Bitbucket) and supports dynamic AI models like OpenAI, Anthropic, and local models.
Create a TypeScript npm library that helps developers review code during merge requests using AI, with support for multiple providers and flexible AI model integrations. The library is designed for both Free and Premium versions, offering additional features for paying customers.
- AI-powered code review using OpenAI (e.g., GPT-4).
- Line-level code feedback.
- GitHub and GitLab integration.
- Basic automated labeling (e.g., "Review Passed", "Needs Adjustment").
- Simple token management via environment variables.
- Dynamic AI model support (OpenAI, Anthropic, Local Models like LLaMA, Custom APIs).
- Block-level and function-level feedback.
- Support for additional providers (Bitbucket, Azure DevOps, Jira).
- Customizable labeling and review thresholds.
- Enhanced security with OAuth, token rotation, and encrypted storage.
- Detailed analytics and usage insights (opt-in).
- Uses JWT for premium feature access.
- Central server or serverless function for key generation and verification.
- Future-proof design for time-limited trials and feature-specific access.
- Standalone npm library (primary)
- Dockerized CLI (optional)
- Track feature usage, performance, and error rates.
- Provide insights for continuous improvement.
- Respect user privacy with clear opt-in mechanisms.
npm install -g difflytic
Or as a dev dependency in your project:
npm install --save-dev difflytic
difflytic review gitlab <projectId> <mergeRequestIid> --mode=function
npx difflytic review gitlab <projectId> <mergeRequestIid> --mode=function
-
--mode
can befile
,block
, orfunction
(default:file
) - Example:
npx difflytic review gitlab 12345 42 --mode=block
import { GitLabProvider } from 'difflytic/dist/providers/GitLabProvider';
import { OpenAI } from 'difflytic/dist/ai/OpenAI';
const provider = new GitLabProvider();
const ai = new OpenAI();
const mrData = await provider.fetchMergeRequestData('yourProjectId', 'yourMergeRequestIid');
const changes = mrData.changes || [];
for (const file of changes) {
const diff = file.diff || '';
// ...process diff or use ai.analyzeCode(diff, 'function')
}
Set these as environment variables or in a .difflyticrc.json
or config.json
in your project root:
-
GITLAB_TOKEN
(required) -
OPENAI_API_KEY
(required) -
GITLAB_API_URL
(optional, for self-hosted GitLab)
Example .difflyticrc.json
:
{
"GITLAB_TOKEN": "your_token",
"OPENAI_API_KEY": "your_openai_key",
"GITLAB_API_URL": "your_custom_gitlab_domain"
}
To run difflytic automatically on every merge request, add a job to your .gitlab-ci.yml
.
Go to Settings > CI/CD > Variables in your GitLab project and add:
-
GITLAB_TOKEN
(withapi
scope, or at leastread_api
andread_repository
) -
OPENAI_API_KEY
(your OpenAI API key) -
GITLAB_API_URL
(e.g.,https://gitlab.com
or your self-hosted domain, without/api/v4
)
These variables will be available to your CI jobs as environment variables.
stages:
- ai_review
ai_code_review:
stage: ai_review
image: node:18
script:
- npm install difflytic
- npx difflytic review gitlab "$CI_PROJECT_ID" "$CI_MERGE_REQUEST_IID" --mode=function
only:
- merge_requests
variables:
GITLAB_TOKEN: "$GITLAB_TOKEN"
OPENAI_API_KEY: "$OPENAI_API_KEY"
GITLAB_API_URL: "$GITLAB_API_URL"
- This job will run on every merge request.
- It installs
difflytic
and runs the review command for the current MR. - The required tokens and API URL are securely provided via GitLab CI/CD variables.
- The job will:
- Run the AI review on the merge request changes
- Post comments and labels to the MR as configured
- In Settings > General > Merge request approvals or CI/CD > Pipelines, you can require this job to pass before merging.
MIT