A TypeScript library for extracting and analyzing GitLab merge request data, including code diffs and changes.
tsx
npm install gitlab-mr-extractor
tsx
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 });
Main class for interacting with GitLab merge requests.
tsx
constructor(config: GitLabConfig)
Parameters:
config
: Configuration object containing:
baseUrl
: GitLab instance URLprivateToken
: GitLab API tokenprojectId
: Target project IDtsx
async extractMergeRequests(options?: FetchOptions): Promise<MergeRequestData[]>
Parameters:
options
: Optional configuration
authorId
: Filter by author IDmaxResults
: Limit number of resultsReturns: Array of merge request data
Utility class for parsing Git diffs.
tsx
static parse(rawDiff: string): DiffChange[]
tsx
interface MergeRequestData { id: number; iid: number; title: string; description: string; state: string; merged_at: string; author: { id: number; name: string; username: string; }; changes: CodeDiff[]; }
tsx
interface CodeDiff { old_path: string; new_path: string; diff: string; changes: DiffChange[]; }
tsx
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`); }
tsx
// 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);
tsx
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); } }
To contribute:
git checkout -b feature/new-feature
)git commit -m 'Add new feature'
)git push origin feature/new-feature
)Requirements:
This project is licensed under the MIT License - see the LICENSE file for details.
For support:
Created by Bhargav