npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

gitlab-mr-extractor

v1.0.0

Published

A TypeScript library for extracting and analyzing GitLab merge request data with code diffs

Readme

GitLab Merge Request Extractor

A TypeScript library for extracting and analyzing GitLab merge request data, including code diffs and changes.

Features

  • Extract merge request data from GitLab repositories
  • Parse and analyze code diffs
  • Export data in multiple formats (JSON, CSV, MDX)
  • Save code changes and diffs to files
  • TypeScript support with type definitions
  • Error handling
  • Simple API

Installation

npm install gitlab-mr-extractor

Quick Start

import { GitLabMergeRequestExtractor } from 'gitlab-mr-extractor';

// Initialize the extractor
const extractor = new GitLabMergeRequestExtractor({
  baseUrl: 'https://gitlab.com',
  privateToken: 'your-gitlab-token',
  projectId: 'your-project-id'
});

// Extract merge requests
const mergeRequests = await extractor.extractMergeRequests({
  maxResults: 5 // Optional: limit results
});

API Reference

GitLabMergeRequestExtractor

Main class for interacting with GitLab merge requests.

Constructor

constructor(config: GitLabConfig)

Parameters:

  • config: Configuration object containing:
    • baseUrl: GitLab instance URL
    • privateToken: GitLab API token
    • projectId: Target project ID

Methods

extractMergeRequests
async extractMergeRequests(options?: FetchOptions): Promise<MergeRequestData[]>

Parameters:

  • options: Optional configuration
    • authorId: Filter by author ID
    • maxResults: Limit number of results

Returns: Array of merge request data

DiffParser

Utility class for parsing Git diffs.

static parse(rawDiff: string): DiffChange[]

Data Structures

MergeRequestData

interface MergeRequestData {
  id: number;
  iid: number;
  title: string;
  description: string;
  state: string;
  merged_at: string;
  author: {
    id: number;
    name: string;
    username: string;
  };
  changes: CodeDiff[];
}

CodeDiff

interface CodeDiff {
  old_path: string;
  new_path: string;
  diff: string;
  changes: DiffChange[];
}

Examples

Basic Usage

import { GitLabMergeRequestExtractor } from 'gitlab-mr-extractor';

async function main() {
  const extractor = new GitLabMergeRequestExtractor({
    baseUrl: 'https://gitlab.com',
    privateToken: process.env.GITLAB_TOKEN,
    projectId: process.env.GITLAB_PROJECT_ID
  });

  const mergeRequests = await extractor.extractMergeRequests();
  console.log(`Found ${mergeRequests.length} merge requests`);
}

Saving Results

// Save as JSON
fs.writeFileSync('results.json', JSON.stringify(mergeRequests, null, 2));

// Save as CSV
import * as json2csv from 'json2csv';
const csv = json2csv.parse(mergeRequests);
fs.writeFileSync('results.csv', csv);

// Save as MDX
const mdxContent = generateMdxContent(mergeRequests);
fs.writeFileSync('results.mdx', mdxContent);

Error Handling

try {
  const mergeRequests = await extractor.extractMergeRequests();
} catch (error) {
  if (error instanceof GitLabApiError) {
    console.error('GitLab API Error:', error.message);
    console.error('Status:', error.status);
  } else if (error instanceof InvalidConfigError) {
    console.error('Configuration Error:', error.message);
  }
}

Contributing

To contribute:

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/new-feature)
  3. Commit your changes (git commit -m 'Add new feature')
  4. Push to the branch (git push origin feature/new-feature)
  5. Open a Pull Request

Requirements:

  • Write tests for new features
  • Update documentation as needed
  • Follow the existing code style
  • Write clear commit messages

License

This project is licensed under the MIT License - see the LICENSE file for details.

Support

For support:

  1. Check the documentation here
  2. Search existing issues here
  3. Create a new issue here

Acknowledgments

  • GitLab API Team
  • Contributors

Created by Bhargav