@monsoft/mcp-github-project-manager
Version:
A Model Context Protocol GitHub Project Manager implementation
154 lines (153 loc) • 4.26 kB
JavaScript
import { Octokit } from '@octokit/rest';
import { handleGitHubError } from '../errors/index.js';
/**
* Service for managing GitHub issues
*/
export class GitHubIssueService {
/**
* Create a new GitHub Issue Service
* @param token GitHub API token
*/
constructor(token) {
this.octokit = new Octokit({
auth: token,
});
}
/**
* Create a new issue in a GitHub repository
* @param params Issue creation parameters
* @returns The created issue
*/
async createIssue(params) {
try {
const { owner, repo, title, body, labels, assignees, milestone } = params;
const response = await this.octokit.issues.create({
owner,
repo,
title,
body,
labels,
assignees,
milestone,
});
return response.data;
}
catch (error) {
throw handleGitHubError(error);
}
}
/**
* Update an existing issue in a GitHub repository
* @param params Issue update parameters
* @returns The updated issue
*/
async updateIssue(params) {
try {
const { owner, repo, issue_number, title, body, state, labels, assignees, milestone } = params;
const response = await this.octokit.issues.update({
owner,
repo,
issue_number,
title,
body,
state,
labels,
assignees,
milestone,
});
return response.data;
}
catch (error) {
throw handleGitHubError(error);
}
}
/**
* List issues in a GitHub repository
* @param params Issue listing parameters
* @returns List of issues
*/
async listIssues(params) {
try {
const { owner, repo, state, sort, direction, since, per_page, page, labels, assignee, creator, mentioned, milestone, } = params;
const response = await this.octokit.issues.listForRepo({
owner,
repo,
state,
sort,
direction,
since,
per_page,
page,
labels: labels?.join(','),
assignee,
creator,
mentioned,
milestone,
});
return response.data;
}
catch (error) {
throw handleGitHubError(error);
}
}
/**
* Get details of a specific issue
* @param params Get issue parameters
* @returns Issue details
*/
async getIssue(params) {
try {
const { owner, repo, issue_number } = params;
const response = await this.octokit.issues.get({
owner,
repo,
issue_number,
});
return response.data;
}
catch (error) {
throw handleGitHubError(error);
}
}
/**
* Add a comment to an issue
* @param params Issue comment parameters
* @returns The created comment
*/
async addIssueComment(params) {
try {
const { owner, repo, issue_number, body } = params;
const response = await this.octokit.issues.createComment({
owner,
repo,
issue_number,
body,
});
return response.data;
}
catch (error) {
throw handleGitHubError(error);
}
}
/**
* Close an issue
* @param owner Repository owner
* @param repo Repository name
* @param issue_number Issue number
* @returns The updated issue
*/
async closeIssue(owner, repo, issue_number) {
try {
const response = await this.octokit.issues.update({
owner,
repo,
issue_number,
state: 'closed',
});
return response.data;
}
catch (error) {
throw handleGitHubError(error);
}
}
}