diff --git a/pkg/github/actions.go b/pkg/github/actions.go index 8c7b08a85..cdfa1d072 100644 --- a/pkg/github/actions.go +++ b/pkg/github/actions.go @@ -16,11 +16,6 @@ import ( "github.com/mark3labs/mcp-go/server" ) -const ( - DescriptionRepositoryOwner = "Repository owner" - DescriptionRepositoryName = "Repository name" -) - // ListWorkflows creates a tool to list workflows in a repository func ListWorkflows(getClient GetClientFn, t translations.TranslationHelperFunc) (tool mcp.Tool, handler server.ToolHandlerFunc) { return mcp.NewTool("list_workflows", @@ -31,11 +26,11 @@ func ListWorkflows(getClient GetClientFn, t translations.TranslationHelperFunc) }), mcp.WithString("owner", mcp.Required(), - mcp.Description(DescriptionRepositoryOwner), + mcp.Description(DescRepositoryOwner), ), mcp.WithString("repo", mcp.Required(), - mcp.Description(DescriptionRepositoryName), + mcp.Description(DescRepositoryName), ), mcp.WithNumber("per_page", mcp.Description("The number of results per page (max 100)"), @@ -66,7 +61,7 @@ func ListWorkflows(getClient GetClientFn, t translations.TranslationHelperFunc) client, err := getClient(ctx) if err != nil { - return nil, fmt.Errorf("failed to get GitHub client: %w", err) + return nil, fmt.Errorf(ErrFailedToGetGitHubClient, err) } // Set up list options @@ -83,7 +78,7 @@ func ListWorkflows(getClient GetClientFn, t translations.TranslationHelperFunc) r, err := json.Marshal(workflows) if err != nil { - return nil, fmt.Errorf("failed to marshal response: %w", err) + return nil, fmt.Errorf(ErrFailedToMarshalResponse, err) } return mcp.NewToolResultText(string(r)), nil @@ -100,11 +95,11 @@ func ListWorkflowRuns(getClient GetClientFn, t translations.TranslationHelperFun }), mcp.WithString("owner", mcp.Required(), - mcp.Description(DescriptionRepositoryOwner), + mcp.Description(DescRepositoryOwner), ), mcp.WithString("repo", mcp.Required(), - mcp.Description(DescriptionRepositoryName), + mcp.Description(DescRepositoryName), ), mcp.WithString("workflow_id", mcp.Required(), @@ -208,7 +203,7 @@ func ListWorkflowRuns(getClient GetClientFn, t translations.TranslationHelperFun client, err := getClient(ctx) if err != nil { - return nil, fmt.Errorf("failed to get GitHub client: %w", err) + return nil, fmt.Errorf(ErrFailedToGetGitHubClient, err) } // Set up list options @@ -231,7 +226,7 @@ func ListWorkflowRuns(getClient GetClientFn, t translations.TranslationHelperFun r, err := json.Marshal(workflowRuns) if err != nil { - return nil, fmt.Errorf("failed to marshal response: %w", err) + return nil, fmt.Errorf(ErrFailedToMarshalResponse, err) } return mcp.NewToolResultText(string(r)), nil @@ -248,11 +243,11 @@ func RunWorkflow(getClient GetClientFn, t translations.TranslationHelperFunc) (t }), mcp.WithString("owner", mcp.Required(), - mcp.Description(DescriptionRepositoryOwner), + mcp.Description(DescRepositoryOwner), ), mcp.WithString("repo", mcp.Required(), - mcp.Description(DescriptionRepositoryName), + mcp.Description(DescRepositoryName), ), mcp.WithString("workflow_id", mcp.Required(), @@ -294,7 +289,7 @@ func RunWorkflow(getClient GetClientFn, t translations.TranslationHelperFunc) (t client, err := getClient(ctx) if err != nil { - return nil, fmt.Errorf("failed to get GitHub client: %w", err) + return nil, fmt.Errorf(ErrFailedToGetGitHubClient, err) } event := github.CreateWorkflowDispatchEventRequest{ @@ -330,7 +325,7 @@ func RunWorkflow(getClient GetClientFn, t translations.TranslationHelperFunc) (t r, err := json.Marshal(result) if err != nil { - return nil, fmt.Errorf("failed to marshal response: %w", err) + return nil, fmt.Errorf(ErrFailedToMarshalResponse, err) } return mcp.NewToolResultText(string(r)), nil @@ -347,11 +342,11 @@ func GetWorkflowRun(getClient GetClientFn, t translations.TranslationHelperFunc) }), mcp.WithString("owner", mcp.Required(), - mcp.Description(DescriptionRepositoryOwner), + mcp.Description(DescRepositoryOwner), ), mcp.WithString("repo", mcp.Required(), - mcp.Description(DescriptionRepositoryName), + mcp.Description(DescRepositoryName), ), mcp.WithNumber("run_id", mcp.Required(), @@ -375,7 +370,7 @@ func GetWorkflowRun(getClient GetClientFn, t translations.TranslationHelperFunc) client, err := getClient(ctx) if err != nil { - return nil, fmt.Errorf("failed to get GitHub client: %w", err) + return nil, fmt.Errorf(ErrFailedToGetGitHubClient, err) } workflowRun, resp, err := client.Actions.GetWorkflowRunByID(ctx, owner, repo, runID) @@ -386,7 +381,7 @@ func GetWorkflowRun(getClient GetClientFn, t translations.TranslationHelperFunc) r, err := json.Marshal(workflowRun) if err != nil { - return nil, fmt.Errorf("failed to marshal response: %w", err) + return nil, fmt.Errorf(ErrFailedToMarshalResponse, err) } return mcp.NewToolResultText(string(r)), nil @@ -403,11 +398,11 @@ func GetWorkflowRunLogs(getClient GetClientFn, t translations.TranslationHelperF }), mcp.WithString("owner", mcp.Required(), - mcp.Description(DescriptionRepositoryOwner), + mcp.Description(DescRepositoryOwner), ), mcp.WithString("repo", mcp.Required(), - mcp.Description(DescriptionRepositoryName), + mcp.Description(DescRepositoryName), ), mcp.WithNumber("run_id", mcp.Required(), @@ -431,7 +426,7 @@ func GetWorkflowRunLogs(getClient GetClientFn, t translations.TranslationHelperF client, err := getClient(ctx) if err != nil { - return nil, fmt.Errorf("failed to get GitHub client: %w", err) + return nil, fmt.Errorf(ErrFailedToGetGitHubClient, err) } // Get the download URL for the logs @@ -452,7 +447,7 @@ func GetWorkflowRunLogs(getClient GetClientFn, t translations.TranslationHelperF r, err := json.Marshal(result) if err != nil { - return nil, fmt.Errorf("failed to marshal response: %w", err) + return nil, fmt.Errorf(ErrFailedToMarshalResponse, err) } return mcp.NewToolResultText(string(r)), nil @@ -469,11 +464,11 @@ func ListWorkflowJobs(getClient GetClientFn, t translations.TranslationHelperFun }), mcp.WithString("owner", mcp.Required(), - mcp.Description(DescriptionRepositoryOwner), + mcp.Description(DescRepositoryOwner), ), mcp.WithString("repo", mcp.Required(), - mcp.Description(DescriptionRepositoryName), + mcp.Description(DescRepositoryName), ), mcp.WithNumber("run_id", mcp.Required(), @@ -523,7 +518,7 @@ func ListWorkflowJobs(getClient GetClientFn, t translations.TranslationHelperFun client, err := getClient(ctx) if err != nil { - return nil, fmt.Errorf("failed to get GitHub client: %w", err) + return nil, fmt.Errorf(ErrFailedToGetGitHubClient, err) } // Set up list options @@ -549,7 +544,7 @@ func ListWorkflowJobs(getClient GetClientFn, t translations.TranslationHelperFun r, err := json.Marshal(response) if err != nil { - return nil, fmt.Errorf("failed to marshal response: %w", err) + return nil, fmt.Errorf(ErrFailedToMarshalResponse, err) } return mcp.NewToolResultText(string(r)), nil @@ -566,11 +561,11 @@ func GetJobLogs(getClient GetClientFn, t translations.TranslationHelperFunc) (to }), mcp.WithString("owner", mcp.Required(), - mcp.Description(DescriptionRepositoryOwner), + mcp.Description(DescRepositoryOwner), ), mcp.WithString("repo", mcp.Required(), - mcp.Description(DescriptionRepositoryName), + mcp.Description(DescRepositoryName), ), mcp.WithNumber("job_id", mcp.Description("The unique identifier of the workflow job (required for single job logs)"), @@ -627,7 +622,7 @@ func GetJobLogs(getClient GetClientFn, t translations.TranslationHelperFunc) (to client, err := getClient(ctx) if err != nil { - return nil, fmt.Errorf("failed to get GitHub client: %w", err) + return nil, fmt.Errorf(ErrFailedToGetGitHubClient, err) } // Validate parameters @@ -709,7 +704,7 @@ func handleFailedJobLogs(ctx context.Context, client *github.Client, owner, repo r, err := json.Marshal(result) if err != nil { - return nil, fmt.Errorf("failed to marshal response: %w", err) + return nil, fmt.Errorf(ErrFailedToMarshalResponse, err) } return mcp.NewToolResultText(string(r)), nil @@ -724,7 +719,7 @@ func handleSingleJobLogs(ctx context.Context, client *github.Client, owner, repo r, err := json.Marshal(jobResult) if err != nil { - return nil, fmt.Errorf("failed to marshal response: %w", err) + return nil, fmt.Errorf(ErrFailedToMarshalResponse, err) } return mcp.NewToolResultText(string(r)), nil @@ -823,11 +818,11 @@ func RerunWorkflowRun(getClient GetClientFn, t translations.TranslationHelperFun }), mcp.WithString("owner", mcp.Required(), - mcp.Description(DescriptionRepositoryOwner), + mcp.Description(DescRepositoryOwner), ), mcp.WithString("repo", mcp.Required(), - mcp.Description(DescriptionRepositoryName), + mcp.Description(DescRepositoryName), ), mcp.WithNumber("run_id", mcp.Required(), @@ -851,7 +846,7 @@ func RerunWorkflowRun(getClient GetClientFn, t translations.TranslationHelperFun client, err := getClient(ctx) if err != nil { - return nil, fmt.Errorf("failed to get GitHub client: %w", err) + return nil, fmt.Errorf(ErrFailedToGetGitHubClient, err) } resp, err := client.Actions.RerunWorkflowByID(ctx, owner, repo, runID) @@ -869,7 +864,7 @@ func RerunWorkflowRun(getClient GetClientFn, t translations.TranslationHelperFun r, err := json.Marshal(result) if err != nil { - return nil, fmt.Errorf("failed to marshal response: %w", err) + return nil, fmt.Errorf(ErrFailedToMarshalResponse, err) } return mcp.NewToolResultText(string(r)), nil @@ -886,11 +881,11 @@ func RerunFailedJobs(getClient GetClientFn, t translations.TranslationHelperFunc }), mcp.WithString("owner", mcp.Required(), - mcp.Description(DescriptionRepositoryOwner), + mcp.Description(DescRepositoryOwner), ), mcp.WithString("repo", mcp.Required(), - mcp.Description(DescriptionRepositoryName), + mcp.Description(DescRepositoryName), ), mcp.WithNumber("run_id", mcp.Required(), @@ -914,7 +909,7 @@ func RerunFailedJobs(getClient GetClientFn, t translations.TranslationHelperFunc client, err := getClient(ctx) if err != nil { - return nil, fmt.Errorf("failed to get GitHub client: %w", err) + return nil, fmt.Errorf(ErrFailedToGetGitHubClient, err) } resp, err := client.Actions.RerunFailedJobsByID(ctx, owner, repo, runID) @@ -932,7 +927,7 @@ func RerunFailedJobs(getClient GetClientFn, t translations.TranslationHelperFunc r, err := json.Marshal(result) if err != nil { - return nil, fmt.Errorf("failed to marshal response: %w", err) + return nil, fmt.Errorf(ErrFailedToMarshalResponse, err) } return mcp.NewToolResultText(string(r)), nil @@ -949,11 +944,11 @@ func CancelWorkflowRun(getClient GetClientFn, t translations.TranslationHelperFu }), mcp.WithString("owner", mcp.Required(), - mcp.Description(DescriptionRepositoryOwner), + mcp.Description(DescRepositoryOwner), ), mcp.WithString("repo", mcp.Required(), - mcp.Description(DescriptionRepositoryName), + mcp.Description(DescRepositoryName), ), mcp.WithNumber("run_id", mcp.Required(), @@ -977,7 +972,7 @@ func CancelWorkflowRun(getClient GetClientFn, t translations.TranslationHelperFu client, err := getClient(ctx) if err != nil { - return nil, fmt.Errorf("failed to get GitHub client: %w", err) + return nil, fmt.Errorf(ErrFailedToGetGitHubClient, err) } resp, err := client.Actions.CancelWorkflowRunByID(ctx, owner, repo, runID) @@ -995,7 +990,7 @@ func CancelWorkflowRun(getClient GetClientFn, t translations.TranslationHelperFu r, err := json.Marshal(result) if err != nil { - return nil, fmt.Errorf("failed to marshal response: %w", err) + return nil, fmt.Errorf(ErrFailedToMarshalResponse, err) } return mcp.NewToolResultText(string(r)), nil @@ -1012,11 +1007,11 @@ func ListWorkflowRunArtifacts(getClient GetClientFn, t translations.TranslationH }), mcp.WithString("owner", mcp.Required(), - mcp.Description(DescriptionRepositoryOwner), + mcp.Description(DescRepositoryOwner), ), mcp.WithString("repo", mcp.Required(), - mcp.Description(DescriptionRepositoryName), + mcp.Description(DescRepositoryName), ), mcp.WithNumber("run_id", mcp.Required(), @@ -1056,7 +1051,7 @@ func ListWorkflowRunArtifacts(getClient GetClientFn, t translations.TranslationH client, err := getClient(ctx) if err != nil { - return nil, fmt.Errorf("failed to get GitHub client: %w", err) + return nil, fmt.Errorf(ErrFailedToGetGitHubClient, err) } // Set up list options @@ -1073,7 +1068,7 @@ func ListWorkflowRunArtifacts(getClient GetClientFn, t translations.TranslationH r, err := json.Marshal(artifacts) if err != nil { - return nil, fmt.Errorf("failed to marshal response: %w", err) + return nil, fmt.Errorf(ErrFailedToMarshalResponse, err) } return mcp.NewToolResultText(string(r)), nil @@ -1090,11 +1085,11 @@ func DownloadWorkflowRunArtifact(getClient GetClientFn, t translations.Translati }), mcp.WithString("owner", mcp.Required(), - mcp.Description(DescriptionRepositoryOwner), + mcp.Description(DescRepositoryOwner), ), mcp.WithString("repo", mcp.Required(), - mcp.Description(DescriptionRepositoryName), + mcp.Description(DescRepositoryName), ), mcp.WithNumber("artifact_id", mcp.Required(), @@ -1118,7 +1113,7 @@ func DownloadWorkflowRunArtifact(getClient GetClientFn, t translations.Translati client, err := getClient(ctx) if err != nil { - return nil, fmt.Errorf("failed to get GitHub client: %w", err) + return nil, fmt.Errorf(ErrFailedToGetGitHubClient, err) } // Get the download URL for the artifact @@ -1138,7 +1133,7 @@ func DownloadWorkflowRunArtifact(getClient GetClientFn, t translations.Translati r, err := json.Marshal(result) if err != nil { - return nil, fmt.Errorf("failed to marshal response: %w", err) + return nil, fmt.Errorf(ErrFailedToMarshalResponse, err) } return mcp.NewToolResultText(string(r)), nil @@ -1156,11 +1151,11 @@ func DeleteWorkflowRunLogs(getClient GetClientFn, t translations.TranslationHelp }), mcp.WithString("owner", mcp.Required(), - mcp.Description(DescriptionRepositoryOwner), + mcp.Description(DescRepositoryOwner), ), mcp.WithString("repo", mcp.Required(), - mcp.Description(DescriptionRepositoryName), + mcp.Description(DescRepositoryName), ), mcp.WithNumber("run_id", mcp.Required(), @@ -1184,7 +1179,7 @@ func DeleteWorkflowRunLogs(getClient GetClientFn, t translations.TranslationHelp client, err := getClient(ctx) if err != nil { - return nil, fmt.Errorf("failed to get GitHub client: %w", err) + return nil, fmt.Errorf(ErrFailedToGetGitHubClient, err) } resp, err := client.Actions.DeleteWorkflowRunLogs(ctx, owner, repo, runID) @@ -1202,7 +1197,7 @@ func DeleteWorkflowRunLogs(getClient GetClientFn, t translations.TranslationHelp r, err := json.Marshal(result) if err != nil { - return nil, fmt.Errorf("failed to marshal response: %w", err) + return nil, fmt.Errorf(ErrFailedToMarshalResponse, err) } return mcp.NewToolResultText(string(r)), nil @@ -1219,11 +1214,11 @@ func GetWorkflowRunUsage(getClient GetClientFn, t translations.TranslationHelper }), mcp.WithString("owner", mcp.Required(), - mcp.Description(DescriptionRepositoryOwner), + mcp.Description(DescRepositoryOwner), ), mcp.WithString("repo", mcp.Required(), - mcp.Description(DescriptionRepositoryName), + mcp.Description(DescRepositoryName), ), mcp.WithNumber("run_id", mcp.Required(), @@ -1247,7 +1242,7 @@ func GetWorkflowRunUsage(getClient GetClientFn, t translations.TranslationHelper client, err := getClient(ctx) if err != nil { - return nil, fmt.Errorf("failed to get GitHub client: %w", err) + return nil, fmt.Errorf(ErrFailedToGetGitHubClient, err) } usage, resp, err := client.Actions.GetWorkflowRunUsageByID(ctx, owner, repo, runID) @@ -1258,7 +1253,7 @@ func GetWorkflowRunUsage(getClient GetClientFn, t translations.TranslationHelper r, err := json.Marshal(usage) if err != nil { - return nil, fmt.Errorf("failed to marshal response: %w", err) + return nil, fmt.Errorf(ErrFailedToMarshalResponse, err) } return mcp.NewToolResultText(string(r)), nil diff --git a/pkg/github/code_scanning.go b/pkg/github/code_scanning.go index 3b07692c0..580c816ee 100644 --- a/pkg/github/code_scanning.go +++ b/pkg/github/code_scanning.go @@ -50,7 +50,7 @@ func GetCodeScanningAlert(getClient GetClientFn, t translations.TranslationHelpe client, err := getClient(ctx) if err != nil { - return nil, fmt.Errorf("failed to get GitHub client: %w", err) + return nil, fmt.Errorf(ErrFailedToGetGitHubClient, err) } alert, resp, err := client.CodeScanning.GetAlert(ctx, owner, repo, int64(alertNumber)) @@ -139,7 +139,7 @@ func ListCodeScanningAlerts(getClient GetClientFn, t translations.TranslationHel client, err := getClient(ctx) if err != nil { - return nil, fmt.Errorf("failed to get GitHub client: %w", err) + return nil, fmt.Errorf(ErrFailedToGetGitHubClient, err) } alerts, resp, err := client.CodeScanning.ListAlertsForRepo(ctx, owner, repo, &github.AlertListOptions{Ref: ref, State: state, Severity: severity, ToolName: toolName}) if err != nil { diff --git a/pkg/github/constants.go b/pkg/github/constants.go new file mode 100644 index 000000000..30e7a543d --- /dev/null +++ b/pkg/github/constants.go @@ -0,0 +1,11 @@ +package github + +const ( + ErrFailedToGetGitHubClient = "failed to get GitHub client: %w" + ErrFailedToMarshalResponse = "failed to marshal response: %w" + + DescRepositoryOwner = "Repository owner" + DescRepositoryName = "Repository name" + + RepoURIPrefix = "repo://" +) diff --git a/pkg/github/discussions.go b/pkg/github/discussions.go index a7ec8e20f..b943a77ac 100644 --- a/pkg/github/discussions.go +++ b/pkg/github/discussions.go @@ -22,11 +22,11 @@ func ListDiscussions(getGQLClient GetGQLClientFn, t translations.TranslationHelp }), mcp.WithString("owner", mcp.Required(), - mcp.Description("Repository owner"), + mcp.Description(DescRepositoryOwner), ), mcp.WithString("repo", mcp.Required(), - mcp.Description("Repository name"), + mcp.Description(DescRepositoryName), ), mcp.WithString("category", mcp.Description("Optional filter by discussion category ID. If provided, only discussions with this category are listed."), @@ -164,11 +164,11 @@ func GetDiscussion(getGQLClient GetGQLClientFn, t translations.TranslationHelper }), mcp.WithString("owner", mcp.Required(), - mcp.Description("Repository owner"), + mcp.Description(DescRepositoryOwner), ), mcp.WithString("repo", mcp.Required(), - mcp.Description("Repository name"), + mcp.Description(DescRepositoryName), ), mcp.WithNumber("discussionNumber", mcp.Required(), @@ -241,8 +241,8 @@ func GetDiscussionComments(getGQLClient GetGQLClientFn, t translations.Translati Title: t("TOOL_GET_DISCUSSION_COMMENTS_USER_TITLE", "Get discussion comments"), ReadOnlyHint: ToBoolPtr(true), }), - mcp.WithString("owner", mcp.Required(), mcp.Description("Repository owner")), - mcp.WithString("repo", mcp.Required(), mcp.Description("Repository name")), + mcp.WithString("owner", mcp.Required(), mcp.Description(DescRepositoryOwner)), + mcp.WithString("repo", mcp.Required(), mcp.Description(DescRepositoryName)), mcp.WithNumber("discussionNumber", mcp.Required(), mcp.Description("Discussion Number")), ), func(ctx context.Context, request mcp.CallToolRequest) (*mcp.CallToolResult, error) { @@ -303,11 +303,11 @@ func ListDiscussionCategories(getGQLClient GetGQLClientFn, t translations.Transl }), mcp.WithString("owner", mcp.Required(), - mcp.Description("Repository owner"), + mcp.Description(DescRepositoryOwner), ), mcp.WithString("repo", mcp.Required(), - mcp.Description("Repository name"), + mcp.Description(DescRepositoryName), ), mcp.WithNumber("first", mcp.Description("Number of categories to return per page (min 1, max 100)"), diff --git a/pkg/github/issues.go b/pkg/github/issues.go index 6121786d2..000a8f700 100644 --- a/pkg/github/issues.go +++ b/pkg/github/issues.go @@ -54,7 +54,7 @@ func GetIssue(getClient GetClientFn, t translations.TranslationHelperFunc) (tool client, err := getClient(ctx) if err != nil { - return nil, fmt.Errorf("failed to get GitHub client: %w", err) + return nil, fmt.Errorf(ErrFailedToGetGitHubClient, err) } issue, resp, err := client.Issues.Get(ctx, owner, repo, issueNumber) if err != nil { @@ -93,7 +93,7 @@ func AddIssueComment(getClient GetClientFn, t translations.TranslationHelperFunc ), mcp.WithString("repo", mcp.Required(), - mcp.Description("Repository name"), + mcp.Description(DescRepositoryName), ), mcp.WithNumber("issue_number", mcp.Required(), @@ -128,7 +128,7 @@ func AddIssueComment(getClient GetClientFn, t translations.TranslationHelperFunc client, err := getClient(ctx) if err != nil { - return nil, fmt.Errorf("failed to get GitHub client: %w", err) + return nil, fmt.Errorf(ErrFailedToGetGitHubClient, err) } createdComment, resp, err := client.Issues.CreateComment(ctx, owner, repo, issueNumber, comment) if err != nil { @@ -146,7 +146,7 @@ func AddIssueComment(getClient GetClientFn, t translations.TranslationHelperFunc r, err := json.Marshal(createdComment) if err != nil { - return nil, fmt.Errorf("failed to marshal response: %w", err) + return nil, fmt.Errorf(ErrFailedToMarshalResponse, err) } return mcp.NewToolResultText(string(r)), nil @@ -212,7 +212,7 @@ func CreateIssue(getClient GetClientFn, t translations.TranslationHelperFunc) (t ), mcp.WithString("repo", mcp.Required(), - mcp.Description("Repository name"), + mcp.Description(DescRepositoryName), ), mcp.WithString("title", mcp.Required(), @@ -295,7 +295,7 @@ func CreateIssue(getClient GetClientFn, t translations.TranslationHelperFunc) (t client, err := getClient(ctx) if err != nil { - return nil, fmt.Errorf("failed to get GitHub client: %w", err) + return nil, fmt.Errorf(ErrFailedToGetGitHubClient, err) } issue, resp, err := client.Issues.Create(ctx, owner, repo, issueRequest) if err != nil { @@ -313,7 +313,7 @@ func CreateIssue(getClient GetClientFn, t translations.TranslationHelperFunc) (t r, err := json.Marshal(issue) if err != nil { - return nil, fmt.Errorf("failed to marshal response: %w", err) + return nil, fmt.Errorf(ErrFailedToMarshalResponse, err) } return mcp.NewToolResultText(string(r)), nil @@ -334,7 +334,7 @@ func ListIssues(getClient GetClientFn, t translations.TranslationHelperFunc) (to ), mcp.WithString("repo", mcp.Required(), - mcp.Description("Repository name"), + mcp.Description(DescRepositoryName), ), mcp.WithString("state", mcp.Description("Filter by state"), @@ -417,7 +417,7 @@ func ListIssues(getClient GetClientFn, t translations.TranslationHelperFunc) (to client, err := getClient(ctx) if err != nil { - return nil, fmt.Errorf("failed to get GitHub client: %w", err) + return nil, fmt.Errorf(ErrFailedToGetGitHubClient, err) } issues, resp, err := client.Issues.ListByRepo(ctx, owner, repo, opts) if err != nil { @@ -456,7 +456,7 @@ func UpdateIssue(getClient GetClientFn, t translations.TranslationHelperFunc) (t ), mcp.WithString("repo", mcp.Required(), - mcp.Description("Repository name"), + mcp.Description(DescRepositoryName), ), mcp.WithNumber("issue_number", mcp.Required(), @@ -563,7 +563,7 @@ func UpdateIssue(getClient GetClientFn, t translations.TranslationHelperFunc) (t client, err := getClient(ctx) if err != nil { - return nil, fmt.Errorf("failed to get GitHub client: %w", err) + return nil, fmt.Errorf(ErrFailedToGetGitHubClient, err) } updatedIssue, resp, err := client.Issues.Edit(ctx, owner, repo, issueNumber, issueRequest) if err != nil { @@ -581,7 +581,7 @@ func UpdateIssue(getClient GetClientFn, t translations.TranslationHelperFunc) (t r, err := json.Marshal(updatedIssue) if err != nil { - return nil, fmt.Errorf("failed to marshal response: %w", err) + return nil, fmt.Errorf(ErrFailedToMarshalResponse, err) } return mcp.NewToolResultText(string(r)), nil @@ -602,7 +602,7 @@ func GetIssueComments(getClient GetClientFn, t translations.TranslationHelperFun ), mcp.WithString("repo", mcp.Required(), - mcp.Description("Repository name"), + mcp.Description(DescRepositoryName), ), mcp.WithNumber("issue_number", mcp.Required(), @@ -646,7 +646,7 @@ func GetIssueComments(getClient GetClientFn, t translations.TranslationHelperFun client, err := getClient(ctx) if err != nil { - return nil, fmt.Errorf("failed to get GitHub client: %w", err) + return nil, fmt.Errorf(ErrFailedToGetGitHubClient, err) } comments, resp, err := client.Issues.ListComments(ctx, owner, repo, issueNumber, opts) if err != nil { @@ -664,7 +664,7 @@ func GetIssueComments(getClient GetClientFn, t translations.TranslationHelperFun r, err := json.Marshal(comments) if err != nil { - return nil, fmt.Errorf("failed to marshal response: %w", err) + return nil, fmt.Errorf(ErrFailedToMarshalResponse, err) } return mcp.NewToolResultText(string(r)), nil @@ -725,7 +725,7 @@ func AssignCopilotToIssue(getGQLClient GetGQLClientFn, t translations.Translatio ), mcp.WithString("repo", mcp.Required(), - mcp.Description("Repository name"), + mcp.Description(DescRepositoryName), ), mcp.WithNumber("issueNumber", mcp.Required(), @@ -744,7 +744,7 @@ func AssignCopilotToIssue(getGQLClient GetGQLClientFn, t translations.Translatio client, err := getGQLClient(ctx) if err != nil { - return nil, fmt.Errorf("failed to get GitHub client: %w", err) + return nil, fmt.Errorf(ErrFailedToGetGitHubClient, err) } // Firstly, we try to find the copilot bot in the suggested actors for the repository. diff --git a/pkg/github/notifications.go b/pkg/github/notifications.go index b6b6bfd79..b3ce97080 100644 --- a/pkg/github/notifications.go +++ b/pkg/github/notifications.go @@ -51,7 +51,7 @@ func ListNotifications(getClient GetClientFn, t translations.TranslationHelperFu func(ctx context.Context, request mcp.CallToolRequest) (*mcp.CallToolResult, error) { client, err := getClient(ctx) if err != nil { - return nil, fmt.Errorf("failed to get GitHub client: %w", err) + return nil, fmt.Errorf(ErrFailedToGetGitHubClient, err) } filter, err := OptionalParam[string](request, "filter") @@ -138,7 +138,7 @@ func ListNotifications(getClient GetClientFn, t translations.TranslationHelperFu // Marshal response to JSON r, err := json.Marshal(notifications) if err != nil { - return nil, fmt.Errorf("failed to marshal response: %w", err) + return nil, fmt.Errorf(ErrFailedToMarshalResponse, err) } return mcp.NewToolResultText(string(r)), nil @@ -162,7 +162,7 @@ func DismissNotification(getclient GetClientFn, t translations.TranslationHelper func(ctx context.Context, request mcp.CallToolRequest) (*mcp.CallToolResult, error) { client, err := getclient(ctx) if err != nil { - return nil, fmt.Errorf("failed to get GitHub client: %w", err) + return nil, fmt.Errorf(ErrFailedToGetGitHubClient, err) } threadID, err := RequiredParam[string](request, "threadID") @@ -233,7 +233,7 @@ func MarkAllNotificationsRead(getClient GetClientFn, t translations.TranslationH func(ctx context.Context, request mcp.CallToolRequest) (*mcp.CallToolResult, error) { client, err := getClient(ctx) if err != nil { - return nil, fmt.Errorf("failed to get GitHub client: %w", err) + return nil, fmt.Errorf(ErrFailedToGetGitHubClient, err) } lastReadAt, err := OptionalParam[string](request, "lastReadAt") @@ -307,7 +307,7 @@ func GetNotificationDetails(getClient GetClientFn, t translations.TranslationHel func(ctx context.Context, request mcp.CallToolRequest) (*mcp.CallToolResult, error) { client, err := getClient(ctx) if err != nil { - return nil, fmt.Errorf("failed to get GitHub client: %w", err) + return nil, fmt.Errorf(ErrFailedToGetGitHubClient, err) } notificationID, err := RequiredParam[string](request, "notificationID") @@ -335,7 +335,7 @@ func GetNotificationDetails(getClient GetClientFn, t translations.TranslationHel r, err := json.Marshal(thread) if err != nil { - return nil, fmt.Errorf("failed to marshal response: %w", err) + return nil, fmt.Errorf(ErrFailedToMarshalResponse, err) } return mcp.NewToolResultText(string(r)), nil @@ -370,7 +370,7 @@ func ManageNotificationSubscription(getClient GetClientFn, t translations.Transl func(ctx context.Context, request mcp.CallToolRequest) (*mcp.CallToolResult, error) { client, err := getClient(ctx) if err != nil { - return nil, fmt.Errorf("failed to get GitHub client: %w", err) + return nil, fmt.Errorf(ErrFailedToGetGitHubClient, err) } notificationID, err := RequiredParam[string](request, "notificationID") @@ -422,7 +422,7 @@ func ManageNotificationSubscription(getClient GetClientFn, t translations.Transl r, err := json.Marshal(result) if err != nil { - return nil, fmt.Errorf("failed to marshal response: %w", err) + return nil, fmt.Errorf(ErrFailedToMarshalResponse, err) } return mcp.NewToolResultText(string(r)), nil } @@ -459,7 +459,7 @@ func ManageRepositoryNotificationSubscription(getClient GetClientFn, t translati func(ctx context.Context, request mcp.CallToolRequest) (*mcp.CallToolResult, error) { client, err := getClient(ctx) if err != nil { - return nil, fmt.Errorf("failed to get GitHub client: %w", err) + return nil, fmt.Errorf(ErrFailedToGetGitHubClient, err) } owner, err := RequiredParam[string](request, "owner") @@ -518,7 +518,7 @@ func ManageRepositoryNotificationSubscription(getClient GetClientFn, t translati r, err := json.Marshal(result) if err != nil { - return nil, fmt.Errorf("failed to marshal response: %w", err) + return nil, fmt.Errorf(ErrFailedToMarshalResponse, err) } return mcp.NewToolResultText(string(r)), nil } diff --git a/pkg/github/pullrequests.go b/pkg/github/pullrequests.go index bad822b13..02d24bd79 100644 --- a/pkg/github/pullrequests.go +++ b/pkg/github/pullrequests.go @@ -27,11 +27,11 @@ func GetPullRequest(getClient GetClientFn, t translations.TranslationHelperFunc) }), mcp.WithString("owner", mcp.Required(), - mcp.Description("Repository owner"), + mcp.Description(DescRepositoryOwner), ), mcp.WithString("repo", mcp.Required(), - mcp.Description("Repository name"), + mcp.Description(DescRepositoryName), ), mcp.WithNumber("pullNumber", mcp.Required(), @@ -54,7 +54,7 @@ func GetPullRequest(getClient GetClientFn, t translations.TranslationHelperFunc) client, err := getClient(ctx) if err != nil { - return nil, fmt.Errorf("failed to get GitHub client: %w", err) + return nil, fmt.Errorf(ErrFailedToGetGitHubClient, err) } pr, resp, err := client.PullRequests.Get(ctx, owner, repo, pullNumber) if err != nil { @@ -76,7 +76,7 @@ func GetPullRequest(getClient GetClientFn, t translations.TranslationHelperFunc) r, err := json.Marshal(pr) if err != nil { - return nil, fmt.Errorf("failed to marshal response: %w", err) + return nil, fmt.Errorf(ErrFailedToMarshalResponse, err) } return mcp.NewToolResultText(string(r)), nil @@ -93,11 +93,11 @@ func CreatePullRequest(getClient GetClientFn, t translations.TranslationHelperFu }), mcp.WithString("owner", mcp.Required(), - mcp.Description("Repository owner"), + mcp.Description(DescRepositoryOwner), ), mcp.WithString("repo", mcp.Required(), - mcp.Description("Repository name"), + mcp.Description(DescRepositoryName), ), mcp.WithString("title", mcp.Required(), @@ -173,7 +173,7 @@ func CreatePullRequest(getClient GetClientFn, t translations.TranslationHelperFu client, err := getClient(ctx) if err != nil { - return nil, fmt.Errorf("failed to get GitHub client: %w", err) + return nil, fmt.Errorf(ErrFailedToGetGitHubClient, err) } pr, resp, err := client.PullRequests.Create(ctx, owner, repo, newPR) if err != nil { @@ -195,7 +195,7 @@ func CreatePullRequest(getClient GetClientFn, t translations.TranslationHelperFu r, err := json.Marshal(pr) if err != nil { - return nil, fmt.Errorf("failed to marshal response: %w", err) + return nil, fmt.Errorf(ErrFailedToMarshalResponse, err) } return mcp.NewToolResultText(string(r)), nil @@ -212,11 +212,11 @@ func UpdatePullRequest(getClient GetClientFn, t translations.TranslationHelperFu }), mcp.WithString("owner", mcp.Required(), - mcp.Description("Repository owner"), + mcp.Description(DescRepositoryOwner), ), mcp.WithString("repo", mcp.Required(), - mcp.Description("Repository name"), + mcp.Description(DescRepositoryName), ), mcp.WithNumber("pullNumber", mcp.Required(), @@ -298,7 +298,7 @@ func UpdatePullRequest(getClient GetClientFn, t translations.TranslationHelperFu client, err := getClient(ctx) if err != nil { - return nil, fmt.Errorf("failed to get GitHub client: %w", err) + return nil, fmt.Errorf(ErrFailedToGetGitHubClient, err) } pr, resp, err := client.PullRequests.Edit(ctx, owner, repo, pullNumber, update) if err != nil { @@ -320,7 +320,7 @@ func UpdatePullRequest(getClient GetClientFn, t translations.TranslationHelperFu r, err := json.Marshal(pr) if err != nil { - return nil, fmt.Errorf("failed to marshal response: %w", err) + return nil, fmt.Errorf(ErrFailedToMarshalResponse, err) } return mcp.NewToolResultText(string(r)), nil @@ -337,11 +337,11 @@ func ListPullRequests(getClient GetClientFn, t translations.TranslationHelperFun }), mcp.WithString("owner", mcp.Required(), - mcp.Description("Repository owner"), + mcp.Description(DescRepositoryOwner), ), mcp.WithString("repo", mcp.Required(), - mcp.Description("Repository name"), + mcp.Description(DescRepositoryName), ), mcp.WithString("state", mcp.Description("Filter by state"), @@ -411,7 +411,7 @@ func ListPullRequests(getClient GetClientFn, t translations.TranslationHelperFun client, err := getClient(ctx) if err != nil { - return nil, fmt.Errorf("failed to get GitHub client: %w", err) + return nil, fmt.Errorf(ErrFailedToGetGitHubClient, err) } prs, resp, err := client.PullRequests.List(ctx, owner, repo, opts) if err != nil { @@ -433,7 +433,7 @@ func ListPullRequests(getClient GetClientFn, t translations.TranslationHelperFun r, err := json.Marshal(prs) if err != nil { - return nil, fmt.Errorf("failed to marshal response: %w", err) + return nil, fmt.Errorf(ErrFailedToMarshalResponse, err) } return mcp.NewToolResultText(string(r)), nil @@ -450,11 +450,11 @@ func MergePullRequest(getClient GetClientFn, t translations.TranslationHelperFun }), mcp.WithString("owner", mcp.Required(), - mcp.Description("Repository owner"), + mcp.Description(DescRepositoryOwner), ), mcp.WithString("repo", mcp.Required(), - mcp.Description("Repository name"), + mcp.Description(DescRepositoryName), ), mcp.WithNumber("pullNumber", mcp.Required(), @@ -504,7 +504,7 @@ func MergePullRequest(getClient GetClientFn, t translations.TranslationHelperFun client, err := getClient(ctx) if err != nil { - return nil, fmt.Errorf("failed to get GitHub client: %w", err) + return nil, fmt.Errorf(ErrFailedToGetGitHubClient, err) } result, resp, err := client.PullRequests.Merge(ctx, owner, repo, pullNumber, commitMessage, options) if err != nil { @@ -526,7 +526,7 @@ func MergePullRequest(getClient GetClientFn, t translations.TranslationHelperFun r, err := json.Marshal(result) if err != nil { - return nil, fmt.Errorf("failed to marshal response: %w", err) + return nil, fmt.Errorf(ErrFailedToMarshalResponse, err) } return mcp.NewToolResultText(string(r)), nil @@ -588,11 +588,11 @@ func GetPullRequestFiles(getClient GetClientFn, t translations.TranslationHelper }), mcp.WithString("owner", mcp.Required(), - mcp.Description("Repository owner"), + mcp.Description(DescRepositoryOwner), ), mcp.WithString("repo", mcp.Required(), - mcp.Description("Repository name"), + mcp.Description(DescRepositoryName), ), mcp.WithNumber("pullNumber", mcp.Required(), @@ -620,7 +620,7 @@ func GetPullRequestFiles(getClient GetClientFn, t translations.TranslationHelper client, err := getClient(ctx) if err != nil { - return nil, fmt.Errorf("failed to get GitHub client: %w", err) + return nil, fmt.Errorf(ErrFailedToGetGitHubClient, err) } opts := &github.ListOptions{ PerPage: pagination.perPage, @@ -646,7 +646,7 @@ func GetPullRequestFiles(getClient GetClientFn, t translations.TranslationHelper r, err := json.Marshal(files) if err != nil { - return nil, fmt.Errorf("failed to marshal response: %w", err) + return nil, fmt.Errorf(ErrFailedToMarshalResponse, err) } return mcp.NewToolResultText(string(r)), nil @@ -663,11 +663,11 @@ func GetPullRequestStatus(getClient GetClientFn, t translations.TranslationHelpe }), mcp.WithString("owner", mcp.Required(), - mcp.Description("Repository owner"), + mcp.Description(DescRepositoryOwner), ), mcp.WithString("repo", mcp.Required(), - mcp.Description("Repository name"), + mcp.Description(DescRepositoryName), ), mcp.WithNumber("pullNumber", mcp.Required(), @@ -690,7 +690,7 @@ func GetPullRequestStatus(getClient GetClientFn, t translations.TranslationHelpe // First get the PR to find the head SHA client, err := getClient(ctx) if err != nil { - return nil, fmt.Errorf("failed to get GitHub client: %w", err) + return nil, fmt.Errorf(ErrFailedToGetGitHubClient, err) } pr, resp, err := client.PullRequests.Get(ctx, owner, repo, pullNumber) if err != nil { @@ -731,7 +731,7 @@ func GetPullRequestStatus(getClient GetClientFn, t translations.TranslationHelpe r, err := json.Marshal(status) if err != nil { - return nil, fmt.Errorf("failed to marshal response: %w", err) + return nil, fmt.Errorf(ErrFailedToMarshalResponse, err) } return mcp.NewToolResultText(string(r)), nil @@ -748,11 +748,11 @@ func UpdatePullRequestBranch(getClient GetClientFn, t translations.TranslationHe }), mcp.WithString("owner", mcp.Required(), - mcp.Description("Repository owner"), + mcp.Description(DescRepositoryOwner), ), mcp.WithString("repo", mcp.Required(), - mcp.Description("Repository name"), + mcp.Description(DescRepositoryName), ), mcp.WithNumber("pullNumber", mcp.Required(), @@ -786,7 +786,7 @@ func UpdatePullRequestBranch(getClient GetClientFn, t translations.TranslationHe client, err := getClient(ctx) if err != nil { - return nil, fmt.Errorf("failed to get GitHub client: %w", err) + return nil, fmt.Errorf(ErrFailedToGetGitHubClient, err) } result, resp, err := client.PullRequests.UpdateBranch(ctx, owner, repo, pullNumber, opts) if err != nil { @@ -813,7 +813,7 @@ func UpdatePullRequestBranch(getClient GetClientFn, t translations.TranslationHe r, err := json.Marshal(result) if err != nil { - return nil, fmt.Errorf("failed to marshal response: %w", err) + return nil, fmt.Errorf(ErrFailedToMarshalResponse, err) } return mcp.NewToolResultText(string(r)), nil @@ -830,11 +830,11 @@ func GetPullRequestComments(getClient GetClientFn, t translations.TranslationHel }), mcp.WithString("owner", mcp.Required(), - mcp.Description("Repository owner"), + mcp.Description(DescRepositoryOwner), ), mcp.WithString("repo", mcp.Required(), - mcp.Description("Repository name"), + mcp.Description(DescRepositoryName), ), mcp.WithNumber("pullNumber", mcp.Required(), @@ -863,7 +863,7 @@ func GetPullRequestComments(getClient GetClientFn, t translations.TranslationHel client, err := getClient(ctx) if err != nil { - return nil, fmt.Errorf("failed to get GitHub client: %w", err) + return nil, fmt.Errorf(ErrFailedToGetGitHubClient, err) } comments, resp, err := client.PullRequests.ListComments(ctx, owner, repo, pullNumber, opts) if err != nil { @@ -885,7 +885,7 @@ func GetPullRequestComments(getClient GetClientFn, t translations.TranslationHel r, err := json.Marshal(comments) if err != nil { - return nil, fmt.Errorf("failed to marshal response: %w", err) + return nil, fmt.Errorf(ErrFailedToMarshalResponse, err) } return mcp.NewToolResultText(string(r)), nil @@ -902,11 +902,11 @@ func GetPullRequestReviews(getClient GetClientFn, t translations.TranslationHelp }), mcp.WithString("owner", mcp.Required(), - mcp.Description("Repository owner"), + mcp.Description(DescRepositoryOwner), ), mcp.WithString("repo", mcp.Required(), - mcp.Description("Repository name"), + mcp.Description(DescRepositoryName), ), mcp.WithNumber("pullNumber", mcp.Required(), @@ -929,7 +929,7 @@ func GetPullRequestReviews(getClient GetClientFn, t translations.TranslationHelp client, err := getClient(ctx) if err != nil { - return nil, fmt.Errorf("failed to get GitHub client: %w", err) + return nil, fmt.Errorf(ErrFailedToGetGitHubClient, err) } reviews, resp, err := client.PullRequests.ListReviews(ctx, owner, repo, pullNumber, nil) if err != nil { @@ -951,7 +951,7 @@ func GetPullRequestReviews(getClient GetClientFn, t translations.TranslationHelp r, err := json.Marshal(reviews) if err != nil { - return nil, fmt.Errorf("failed to marshal response: %w", err) + return nil, fmt.Errorf(ErrFailedToMarshalResponse, err) } return mcp.NewToolResultText(string(r)), nil @@ -970,11 +970,11 @@ func CreateAndSubmitPullRequestReview(getGQLClient GetGQLClientFn, t translation // internally for now. mcp.WithString("owner", mcp.Required(), - mcp.Description("Repository owner"), + mcp.Description(DescRepositoryOwner), ), mcp.WithString("repo", mcp.Required(), - mcp.Description("Repository name"), + mcp.Description(DescRepositoryName), ), mcp.WithNumber("pullNumber", mcp.Required(), @@ -1073,11 +1073,11 @@ func CreatePendingPullRequestReview(getGQLClient GetGQLClientFn, t translations. // internally for now. mcp.WithString("owner", mcp.Required(), - mcp.Description("Repository owner"), + mcp.Description(DescRepositoryOwner), ), mcp.WithString("repo", mcp.Required(), - mcp.Description("Repository name"), + mcp.Description(DescRepositoryName), ), mcp.WithNumber("pullNumber", mcp.Required(), @@ -1171,11 +1171,11 @@ func AddPullRequestReviewCommentToPendingReview(getGQLClient GetGQLClientFn, t t // ), mcp.WithString("owner", mcp.Required(), - mcp.Description("Repository owner"), + mcp.Description(DescRepositoryOwner), ), mcp.WithString("repo", mcp.Required(), - mcp.Description("Repository name"), + mcp.Description(DescRepositoryName), ), mcp.WithNumber("pullNumber", mcp.Required(), @@ -1332,11 +1332,11 @@ func SubmitPendingPullRequestReview(getGQLClient GetGQLClientFn, t translations. // the latest review from a user, since only one can be active at a time. mcp.WithString("owner", mcp.Required(), - mcp.Description("Repository owner"), + mcp.Description(DescRepositoryOwner), ), mcp.WithString("repo", mcp.Required(), - mcp.Description("Repository name"), + mcp.Description(DescRepositoryName), ), mcp.WithNumber("pullNumber", mcp.Required(), @@ -1466,11 +1466,11 @@ func DeletePendingPullRequestReview(getGQLClient GetGQLClientFn, t translations. // the latest pending review from a user, since only one can be active at a time. mcp.WithString("owner", mcp.Required(), - mcp.Description("Repository owner"), + mcp.Description(DescRepositoryOwner), ), mcp.WithString("repo", mcp.Required(), - mcp.Description("Repository name"), + mcp.Description(DescRepositoryName), ), mcp.WithNumber("pullNumber", mcp.Required(), @@ -1581,11 +1581,11 @@ func GetPullRequestDiff(getClient GetClientFn, t translations.TranslationHelperF }), mcp.WithString("owner", mcp.Required(), - mcp.Description("Repository owner"), + mcp.Description(DescRepositoryOwner), ), mcp.WithString("repo", mcp.Required(), - mcp.Description("Repository name"), + mcp.Description(DescRepositoryName), ), mcp.WithNumber("pullNumber", mcp.Required(), @@ -1649,11 +1649,11 @@ func RequestCopilotReview(getClient GetClientFn, t translations.TranslationHelpe }), mcp.WithString("owner", mcp.Required(), - mcp.Description("Repository owner"), + mcp.Description(DescRepositoryOwner), ), mcp.WithString("repo", mcp.Required(), - mcp.Description("Repository name"), + mcp.Description(DescRepositoryName), ), mcp.WithNumber("pullNumber", mcp.Required(), diff --git a/pkg/github/repositories.go b/pkg/github/repositories.go index 29f776a05..9030923d6 100644 --- a/pkg/github/repositories.go +++ b/pkg/github/repositories.go @@ -32,7 +32,7 @@ func GetCommit(getClient GetClientFn, t translations.TranslationHelperFunc) (too ), mcp.WithString("repo", mcp.Required(), - mcp.Description("Repository name"), + mcp.Description(DescRepositoryName), ), mcp.WithString("sha", mcp.Required(), @@ -65,7 +65,7 @@ func GetCommit(getClient GetClientFn, t translations.TranslationHelperFunc) (too client, err := getClient(ctx) if err != nil { - return nil, fmt.Errorf("failed to get GitHub client: %w", err) + return nil, fmt.Errorf(ErrFailedToGetGitHubClient, err) } commit, resp, err := client.Repositories.GetCommit(ctx, owner, repo, sha, opts) if err != nil { @@ -87,7 +87,7 @@ func GetCommit(getClient GetClientFn, t translations.TranslationHelperFunc) (too r, err := json.Marshal(commit) if err != nil { - return nil, fmt.Errorf("failed to marshal response: %w", err) + return nil, fmt.Errorf(ErrFailedToMarshalResponse, err) } return mcp.NewToolResultText(string(r)), nil @@ -108,7 +108,7 @@ func ListCommits(getClient GetClientFn, t translations.TranslationHelperFunc) (t ), mcp.WithString("repo", mcp.Required(), - mcp.Description("Repository name"), + mcp.Description(DescRepositoryName), ), mcp.WithString("sha", mcp.Description("The commit SHA, branch name, or tag name to list commits from. If not specified, defaults to the repository's default branch."), @@ -155,7 +155,7 @@ func ListCommits(getClient GetClientFn, t translations.TranslationHelperFunc) (t client, err := getClient(ctx) if err != nil { - return nil, fmt.Errorf("failed to get GitHub client: %w", err) + return nil, fmt.Errorf(ErrFailedToGetGitHubClient, err) } commits, resp, err := client.Repositories.ListCommits(ctx, owner, repo, opts) if err != nil { @@ -177,7 +177,7 @@ func ListCommits(getClient GetClientFn, t translations.TranslationHelperFunc) (t r, err := json.Marshal(commits) if err != nil { - return nil, fmt.Errorf("failed to marshal response: %w", err) + return nil, fmt.Errorf(ErrFailedToMarshalResponse, err) } return mcp.NewToolResultText(string(r)), nil @@ -198,7 +198,7 @@ func ListBranches(getClient GetClientFn, t translations.TranslationHelperFunc) ( ), mcp.WithString("repo", mcp.Required(), - mcp.Description("Repository name"), + mcp.Description(DescRepositoryName), ), WithPagination(), ), @@ -225,7 +225,7 @@ func ListBranches(getClient GetClientFn, t translations.TranslationHelperFunc) ( client, err := getClient(ctx) if err != nil { - return nil, fmt.Errorf("failed to get GitHub client: %w", err) + return nil, fmt.Errorf(ErrFailedToGetGitHubClient, err) } branches, resp, err := client.Repositories.ListBranches(ctx, owner, repo, opts) @@ -248,7 +248,7 @@ func ListBranches(getClient GetClientFn, t translations.TranslationHelperFunc) ( r, err := json.Marshal(branches) if err != nil { - return nil, fmt.Errorf("failed to marshal response: %w", err) + return nil, fmt.Errorf(ErrFailedToMarshalResponse, err) } return mcp.NewToolResultText(string(r)), nil @@ -269,7 +269,7 @@ func CreateOrUpdateFile(getClient GetClientFn, t translations.TranslationHelperF ), mcp.WithString("repo", mcp.Required(), - mcp.Description("Repository name"), + mcp.Description(DescRepositoryName), ), mcp.WithString("path", mcp.Required(), @@ -339,7 +339,7 @@ func CreateOrUpdateFile(getClient GetClientFn, t translations.TranslationHelperF // Create or update the file client, err := getClient(ctx) if err != nil { - return nil, fmt.Errorf("failed to get GitHub client: %w", err) + return nil, fmt.Errorf(ErrFailedToGetGitHubClient, err) } fileContent, resp, err := client.Repositories.CreateFile(ctx, owner, repo, path, opts) if err != nil { @@ -361,7 +361,7 @@ func CreateOrUpdateFile(getClient GetClientFn, t translations.TranslationHelperF r, err := json.Marshal(fileContent) if err != nil { - return nil, fmt.Errorf("failed to marshal response: %w", err) + return nil, fmt.Errorf(ErrFailedToMarshalResponse, err) } return mcp.NewToolResultText(string(r)), nil @@ -378,7 +378,7 @@ func CreateRepository(getClient GetClientFn, t translations.TranslationHelperFun }), mcp.WithString("name", mcp.Required(), - mcp.Description("Repository name"), + mcp.Description(DescRepositoryName), ), mcp.WithString("description", mcp.Description("Repository description"), @@ -417,7 +417,7 @@ func CreateRepository(getClient GetClientFn, t translations.TranslationHelperFun client, err := getClient(ctx) if err != nil { - return nil, fmt.Errorf("failed to get GitHub client: %w", err) + return nil, fmt.Errorf(ErrFailedToGetGitHubClient, err) } createdRepo, resp, err := client.Repositories.Create(ctx, "", repo) if err != nil { @@ -439,13 +439,187 @@ func CreateRepository(getClient GetClientFn, t translations.TranslationHelperFun r, err := json.Marshal(createdRepo) if err != nil { - return nil, fmt.Errorf("failed to marshal response: %w", err) + return nil, fmt.Errorf(ErrFailedToMarshalResponse, err) } return mcp.NewToolResultText(string(r)), nil } } +type FileContentParams struct { + owner string + repo string + path string + ref string + sha string +} + +func extractFileContentParams(request mcp.CallToolRequest) (*FileContentParams, error) { + owner, err := RequiredParam[string](request, "owner") + if err != nil { + return nil, err + } + repo, err := RequiredParam[string](request, "repo") + if err != nil { + return nil, err + } + path, err := RequiredParam[string](request, "path") + if err != nil { + return nil, err + } + ref, err := OptionalParam[string](request, "ref") + if err != nil { + return nil, err + } + sha, err := OptionalParam[string](request, "sha") + if err != nil { + return nil, err + } + + return &FileContentParams{ + owner: owner, + repo: repo, + path: path, + ref: ref, + sha: sha, + }, nil +} + +func resolvePullRequestRef(ctx context.Context, getClient GetClientFn, params *FileContentParams) (string, string, error) { + sha := params.sha + ref := params.ref + + if strings.HasPrefix(ref, "refs/pull/") { + prNumber := strings.TrimSuffix(strings.TrimPrefix(ref, "refs/pull/"), "/head") + if len(prNumber) > 0 { + githubClient, err := getClient(ctx) + if err != nil { + return "", "", fmt.Errorf(ErrFailedToGetGitHubClient, err) + } + prNum, err := strconv.Atoi(prNumber) + if err != nil { + return "", "", fmt.Errorf("invalid pull request number: %w", err) + } + pr, _, err := githubClient.PullRequests.Get(ctx, params.owner, params.repo, prNum) + if err != nil { + return "", "", fmt.Errorf("failed to get pull request: %w", err) + } + sha = pr.GetHead().GetSHA() + ref = "" + } + } + + return sha, ref, nil +} + +func createResourceURI(owner, repo, path, sha, ref string) (string, error) { + switch { + case sha != "": + return url.JoinPath(RepoURIPrefix, owner, repo, "sha", sha, "contents", path) + case ref != "": + return url.JoinPath(RepoURIPrefix, owner, repo, ref, "contents", path) + default: + return url.JoinPath(RepoURIPrefix, owner, repo, "contents", path) + } +} + +func tryGetRawContent(ctx context.Context, getRawClient raw.GetRawClientFn, owner, repo, path, sha, ref string) (*mcp.CallToolResult, error) { + rawClient, err := getRawClient(ctx) + if err != nil { + return mcp.NewToolResultError("failed to get GitHub raw content client"), nil + } + + rawOpts := &raw.ContentOpts{ + SHA: sha, + Ref: ref, + } + + resp, err := rawClient.GetRawContent(ctx, owner, repo, path, rawOpts) + if err != nil { + return mcp.NewToolResultError("failed to get raw repository content"), nil + } + defer func() { + _ = resp.Body.Close() + }() + + if resp.StatusCode != http.StatusOK { + return nil, fmt.Errorf("raw content not found") + } + + body, err := io.ReadAll(resp.Body) + if err != nil { + return mcp.NewToolResultError("failed to read response body"), nil + } + + resourceURI, err := createResourceURI(owner, repo, path, sha, ref) + if err != nil { + return nil, fmt.Errorf("failed to create resource URI: %w", err) + } + + contentType := resp.Header.Get("Content-Type") + if strings.HasPrefix(contentType, "application") || strings.HasPrefix(contentType, "text") { + return mcp.NewToolResultResource("successfully downloaded text file", mcp.TextResourceContents{ + URI: resourceURI, + Text: string(body), + MIMEType: contentType, + }), nil + } + return mcp.NewToolResultResource("successfully downloaded binary file", mcp.BlobResourceContents{ + URI: resourceURI, + Blob: base64.StdEncoding.EncodeToString(body), + MIMEType: contentType, + }), nil +} + +func getContentViaAPI(ctx context.Context, getClient GetClientFn, params *FileContentParams, sha, ref string) (*mcp.CallToolResult, error) { + client, err := getClient(ctx) + if err != nil { + return nil, fmt.Errorf(ErrFailedToGetGitHubClient, err) + } + + opts := &github.RepositoryContentGetOptions{} + if sha != "" { + opts.Ref = sha + } else if ref != "" { + opts.Ref = ref + } + + fileContent, directoryContent, resp, err := client.Repositories.GetContents(ctx, params.owner, params.repo, params.path, opts) + if err != nil { + return ghErrors.NewGitHubAPIErrorResponse(ctx, + "failed to get repository content", + resp, + err, + ), nil + } + defer func() { _ = resp.Body.Close() }() + + if fileContent != nil { + content, err := fileContent.GetContent() + if err != nil { + return mcp.NewToolResultError("failed to decode file content"), nil + } + + resourceURI, err := createResourceURI(params.owner, params.repo, params.path, sha, ref) + if err != nil { + return nil, fmt.Errorf("failed to create resource URI: %w", err) + } + + return mcp.NewToolResultResource("successfully retrieved file content", mcp.TextResourceContents{ + URI: resourceURI, + Text: content, + }), nil + } else if directoryContent != nil { + r, err := json.Marshal(directoryContent) + if err != nil { + return nil, fmt.Errorf(ErrFailedToMarshalResponse, err) + } + return mcp.NewToolResultText(string(r)), nil + } + + return mcp.NewToolResultError("no content found"), nil +} + // GetFileContents creates a tool to get the contents of a file or directory from a GitHub repository. func GetFileContents(getClient GetClientFn, getRawClient raw.GetRawClientFn, t translations.TranslationHelperFunc) (tool mcp.Tool, handler server.ToolHandlerFunc) { return mcp.NewTool("get_file_contents", @@ -460,7 +634,7 @@ func GetFileContents(getClient GetClientFn, getRawClient raw.GetRawClientFn, t t ), mcp.WithString("repo", mcp.Required(), - mcp.Description("Repository name"), + mcp.Description(DescRepositoryName), ), mcp.WithString("path", mcp.Required(), @@ -474,143 +648,24 @@ func GetFileContents(getClient GetClientFn, getRawClient raw.GetRawClientFn, t t ), ), func(ctx context.Context, request mcp.CallToolRequest) (*mcp.CallToolResult, error) { - owner, err := RequiredParam[string](request, "owner") - if err != nil { - return mcp.NewToolResultError(err.Error()), nil - } - repo, err := RequiredParam[string](request, "repo") - if err != nil { - return mcp.NewToolResultError(err.Error()), nil - } - path, err := RequiredParam[string](request, "path") - if err != nil { - return mcp.NewToolResultError(err.Error()), nil - } - ref, err := OptionalParam[string](request, "ref") - if err != nil { - return mcp.NewToolResultError(err.Error()), nil - } - sha, err := OptionalParam[string](request, "sha") + params, err := extractFileContentParams(request) if err != nil { return mcp.NewToolResultError(err.Error()), nil } - rawOpts := &raw.ContentOpts{} - - if strings.HasPrefix(ref, "refs/pull/") { - prNumber := strings.TrimSuffix(strings.TrimPrefix(ref, "refs/pull/"), "/head") - if len(prNumber) > 0 { - // fetch the PR from the API to get the latest commit and use SHA - githubClient, err := getClient(ctx) - if err != nil { - return nil, fmt.Errorf("failed to get GitHub client: %w", err) - } - prNum, err := strconv.Atoi(prNumber) - if err != nil { - return nil, fmt.Errorf("invalid pull request number: %w", err) - } - pr, _, err := githubClient.PullRequests.Get(ctx, owner, repo, prNum) - if err != nil { - return nil, fmt.Errorf("failed to get pull request: %w", err) - } - sha = pr.GetHead().GetSHA() - ref = "" - } - } - - rawOpts.SHA = sha - rawOpts.Ref = ref - - // If the path is (most likely) not to be a directory, we will first try to get the raw content from the GitHub raw content API. - if path != "" && !strings.HasSuffix(path, "/") { - - rawClient, err := getRawClient(ctx) - if err != nil { - return mcp.NewToolResultError("failed to get GitHub raw content client"), nil - } - resp, err := rawClient.GetRawContent(ctx, owner, repo, path, rawOpts) - if err != nil { - return mcp.NewToolResultError("failed to get raw repository content"), nil - } - defer func() { - _ = resp.Body.Close() - }() - - if resp.StatusCode == http.StatusOK { - // If the raw content is found, return it directly - body, err := io.ReadAll(resp.Body) - if err != nil { - return mcp.NewToolResultError("failed to read response body"), nil - } - contentType := resp.Header.Get("Content-Type") - - var resourceURI string - switch { - case sha != "": - resourceURI, err = url.JoinPath("repo://", owner, repo, "sha", sha, "contents", path) - if err != nil { - return nil, fmt.Errorf("failed to create resource URI: %w", err) - } - case ref != "": - resourceURI, err = url.JoinPath("repo://", owner, repo, ref, "contents", path) - if err != nil { - return nil, fmt.Errorf("failed to create resource URI: %w", err) - } - default: - resourceURI, err = url.JoinPath("repo://", owner, repo, "contents", path) - if err != nil { - return nil, fmt.Errorf("failed to create resource URI: %w", err) - } - } - - if strings.HasPrefix(contentType, "application") || strings.HasPrefix(contentType, "text") { - return mcp.NewToolResultResource("successfully downloaded text file", mcp.TextResourceContents{ - URI: resourceURI, - Text: string(body), - MIMEType: contentType, - }), nil - } - - return mcp.NewToolResultResource("successfully downloaded binary file", mcp.BlobResourceContents{ - URI: resourceURI, - Blob: base64.StdEncoding.EncodeToString(body), - MIMEType: contentType, - }), nil - - } - } - - client, err := getClient(ctx) + sha, ref, err := resolvePullRequestRef(ctx, getClient, params) if err != nil { - return mcp.NewToolResultError("failed to get GitHub client"), nil - } - - if sha != "" { - ref = sha + return nil, err } - if strings.HasSuffix(path, "/") { - opts := &github.RepositoryContentGetOptions{Ref: ref} - _, dirContent, resp, err := client.Repositories.GetContents(ctx, owner, repo, path, opts) - if err != nil { - return mcp.NewToolResultError("failed to get file contents"), nil - } - defer func() { _ = resp.Body.Close() }() - if resp.StatusCode != 200 { - body, err := io.ReadAll(resp.Body) - if err != nil { - return mcp.NewToolResultError("failed to read response body"), nil - } - return mcp.NewToolResultError(fmt.Sprintf("failed to get file contents: %s", string(body))), nil + if params.path != "" && !strings.HasSuffix(params.path, "/") { + result, err := tryGetRawContent(ctx, getRawClient, params.owner, params.repo, params.path, sha, ref) + if err == nil { + return result, nil } - - r, err := json.Marshal(dirContent) - if err != nil { - return mcp.NewToolResultError("failed to marshal response"), nil - } - return mcp.NewToolResultText(string(r)), nil } - return mcp.NewToolResultError("Failed to get file contents. The path does not point to a file or directory, or the file does not exist in the repository."), nil + + return getContentViaAPI(ctx, getClient, params, sha, ref) } } @@ -628,7 +683,7 @@ func ForkRepository(getClient GetClientFn, t translations.TranslationHelperFunc) ), mcp.WithString("repo", mcp.Required(), - mcp.Description("Repository name"), + mcp.Description(DescRepositoryName), ), mcp.WithString("organization", mcp.Description("Organization to fork to"), @@ -655,7 +710,7 @@ func ForkRepository(getClient GetClientFn, t translations.TranslationHelperFunc) client, err := getClient(ctx) if err != nil { - return nil, fmt.Errorf("failed to get GitHub client: %w", err) + return nil, fmt.Errorf(ErrFailedToGetGitHubClient, err) } forkedRepo, resp, err := client.Repositories.CreateFork(ctx, owner, repo, opts) if err != nil { @@ -682,7 +737,7 @@ func ForkRepository(getClient GetClientFn, t translations.TranslationHelperFunc) r, err := json.Marshal(forkedRepo) if err != nil { - return nil, fmt.Errorf("failed to marshal response: %w", err) + return nil, fmt.Errorf(ErrFailedToMarshalResponse, err) } return mcp.NewToolResultText(string(r)), nil @@ -709,7 +764,7 @@ func DeleteFile(getClient GetClientFn, t translations.TranslationHelperFunc) (to ), mcp.WithString("repo", mcp.Required(), - mcp.Description("Repository name"), + mcp.Description(DescRepositoryName), ), mcp.WithString("path", mcp.Required(), @@ -748,7 +803,7 @@ func DeleteFile(getClient GetClientFn, t translations.TranslationHelperFunc) (to client, err := getClient(ctx) if err != nil { - return nil, fmt.Errorf("failed to get GitHub client: %w", err) + return nil, fmt.Errorf(ErrFailedToGetGitHubClient, err) } // Get the reference for the branch @@ -858,7 +913,7 @@ func DeleteFile(getClient GetClientFn, t translations.TranslationHelperFunc) (to r, err := json.Marshal(response) if err != nil { - return nil, fmt.Errorf("failed to marshal response: %w", err) + return nil, fmt.Errorf(ErrFailedToMarshalResponse, err) } return mcp.NewToolResultText(string(r)), nil @@ -879,7 +934,7 @@ func CreateBranch(getClient GetClientFn, t translations.TranslationHelperFunc) ( ), mcp.WithString("repo", mcp.Required(), - mcp.Description("Repository name"), + mcp.Description(DescRepositoryName), ), mcp.WithString("branch", mcp.Required(), @@ -909,7 +964,7 @@ func CreateBranch(getClient GetClientFn, t translations.TranslationHelperFunc) ( client, err := getClient(ctx) if err != nil { - return nil, fmt.Errorf("failed to get GitHub client: %w", err) + return nil, fmt.Errorf(ErrFailedToGetGitHubClient, err) } // Get the source branch SHA @@ -959,7 +1014,7 @@ func CreateBranch(getClient GetClientFn, t translations.TranslationHelperFunc) ( r, err := json.Marshal(createdRef) if err != nil { - return nil, fmt.Errorf("failed to marshal response: %w", err) + return nil, fmt.Errorf(ErrFailedToMarshalResponse, err) } return mcp.NewToolResultText(string(r)), nil @@ -980,7 +1035,7 @@ func PushFiles(getClient GetClientFn, t translations.TranslationHelperFunc) (too ), mcp.WithString("repo", mcp.Required(), - mcp.Description("Repository name"), + mcp.Description(DescRepositoryName), ), mcp.WithString("branch", mcp.Required(), @@ -1037,7 +1092,7 @@ func PushFiles(getClient GetClientFn, t translations.TranslationHelperFunc) (too client, err := getClient(ctx) if err != nil { - return nil, fmt.Errorf("failed to get GitHub client: %w", err) + return nil, fmt.Errorf(ErrFailedToGetGitHubClient, err) } // Get the reference for the branch @@ -1131,7 +1186,7 @@ func PushFiles(getClient GetClientFn, t translations.TranslationHelperFunc) (too r, err := json.Marshal(updatedRef) if err != nil { - return nil, fmt.Errorf("failed to marshal response: %w", err) + return nil, fmt.Errorf(ErrFailedToMarshalResponse, err) } return mcp.NewToolResultText(string(r)), nil @@ -1152,7 +1207,7 @@ func ListTags(getClient GetClientFn, t translations.TranslationHelperFunc) (tool ), mcp.WithString("repo", mcp.Required(), - mcp.Description("Repository name"), + mcp.Description(DescRepositoryName), ), WithPagination(), ), @@ -1177,7 +1232,7 @@ func ListTags(getClient GetClientFn, t translations.TranslationHelperFunc) (tool client, err := getClient(ctx) if err != nil { - return nil, fmt.Errorf("failed to get GitHub client: %w", err) + return nil, fmt.Errorf(ErrFailedToGetGitHubClient, err) } tags, resp, err := client.Repositories.ListTags(ctx, owner, repo, opts) @@ -1200,7 +1255,7 @@ func ListTags(getClient GetClientFn, t translations.TranslationHelperFunc) (tool r, err := json.Marshal(tags) if err != nil { - return nil, fmt.Errorf("failed to marshal response: %w", err) + return nil, fmt.Errorf(ErrFailedToMarshalResponse, err) } return mcp.NewToolResultText(string(r)), nil @@ -1221,7 +1276,7 @@ func GetTag(getClient GetClientFn, t translations.TranslationHelperFunc) (tool m ), mcp.WithString("repo", mcp.Required(), - mcp.Description("Repository name"), + mcp.Description(DescRepositoryName), ), mcp.WithString("tag", mcp.Required(), @@ -1244,7 +1299,7 @@ func GetTag(getClient GetClientFn, t translations.TranslationHelperFunc) (tool m client, err := getClient(ctx) if err != nil { - return nil, fmt.Errorf("failed to get GitHub client: %w", err) + return nil, fmt.Errorf(ErrFailedToGetGitHubClient, err) } // First get the tag reference @@ -1287,7 +1342,7 @@ func GetTag(getClient GetClientFn, t translations.TranslationHelperFunc) (tool m r, err := json.Marshal(tagObj) if err != nil { - return nil, fmt.Errorf("failed to marshal response: %w", err) + return nil, fmt.Errorf(ErrFailedToMarshalResponse, err) } return mcp.NewToolResultText(string(r)), nil diff --git a/pkg/github/repository_resource.go b/pkg/github/repository_resource.go index a454db630..2f7a452c0 100644 --- a/pkg/github/repository_resource.go +++ b/pkg/github/repository_resource.go @@ -22,7 +22,7 @@ import ( // GetRepositoryResourceContent defines the resource template and handler for getting repository content. func GetRepositoryResourceContent(getClient GetClientFn, getRawClient raw.GetRawClientFn, t translations.TranslationHelperFunc) (mcp.ResourceTemplate, server.ResourceTemplateHandlerFunc) { return mcp.NewResourceTemplate( - "repo://{owner}/{repo}/contents{/path*}", // Resource template + RepoURIPrefix+"{owner}/{repo}/contents{/path*}", // Resource template t("RESOURCE_REPOSITORY_CONTENT_DESCRIPTION", "Repository Content"), ), RepositoryResourceContentsHandler(getClient, getRawClient) @@ -31,7 +31,7 @@ func GetRepositoryResourceContent(getClient GetClientFn, getRawClient raw.GetRaw // GetRepositoryResourceBranchContent defines the resource template and handler for getting repository content for a branch. func GetRepositoryResourceBranchContent(getClient GetClientFn, getRawClient raw.GetRawClientFn, t translations.TranslationHelperFunc) (mcp.ResourceTemplate, server.ResourceTemplateHandlerFunc) { return mcp.NewResourceTemplate( - "repo://{owner}/{repo}/refs/heads/{branch}/contents{/path*}", // Resource template + RepoURIPrefix+"{owner}/{repo}/refs/heads/{branch}/contents{/path*}", // Resource template t("RESOURCE_REPOSITORY_CONTENT_BRANCH_DESCRIPTION", "Repository Content for specific branch"), ), RepositoryResourceContentsHandler(getClient, getRawClient) @@ -40,7 +40,7 @@ func GetRepositoryResourceBranchContent(getClient GetClientFn, getRawClient raw. // GetRepositoryResourceCommitContent defines the resource template and handler for getting repository content for a commit. func GetRepositoryResourceCommitContent(getClient GetClientFn, getRawClient raw.GetRawClientFn, t translations.TranslationHelperFunc) (mcp.ResourceTemplate, server.ResourceTemplateHandlerFunc) { return mcp.NewResourceTemplate( - "repo://{owner}/{repo}/sha/{sha}/contents{/path*}", // Resource template + RepoURIPrefix+"{owner}/{repo}/sha/{sha}/contents{/path*}", // Resource template t("RESOURCE_REPOSITORY_CONTENT_COMMIT_DESCRIPTION", "Repository Content for specific commit"), ), RepositoryResourceContentsHandler(getClient, getRawClient) @@ -49,7 +49,7 @@ func GetRepositoryResourceCommitContent(getClient GetClientFn, getRawClient raw. // GetRepositoryResourceTagContent defines the resource template and handler for getting repository content for a tag. func GetRepositoryResourceTagContent(getClient GetClientFn, getRawClient raw.GetRawClientFn, t translations.TranslationHelperFunc) (mcp.ResourceTemplate, server.ResourceTemplateHandlerFunc) { return mcp.NewResourceTemplate( - "repo://{owner}/{repo}/refs/tags/{tag}/contents{/path*}", // Resource template + RepoURIPrefix+"{owner}/{repo}/refs/tags/{tag}/contents{/path*}", // Resource template t("RESOURCE_REPOSITORY_CONTENT_TAG_DESCRIPTION", "Repository Content for specific tag"), ), RepositoryResourceContentsHandler(getClient, getRawClient) @@ -58,7 +58,7 @@ func GetRepositoryResourceTagContent(getClient GetClientFn, getRawClient raw.Get // GetRepositoryResourcePrContent defines the resource template and handler for getting repository content for a pull request. func GetRepositoryResourcePrContent(getClient GetClientFn, getRawClient raw.GetRawClientFn, t translations.TranslationHelperFunc) (mcp.ResourceTemplate, server.ResourceTemplateHandlerFunc) { return mcp.NewResourceTemplate( - "repo://{owner}/{repo}/refs/pull/{prNumber}/head/contents{/path*}", // Resource template + RepoURIPrefix+"{owner}/{repo}/refs/pull/{prNumber}/head/contents{/path*}", // Resource template t("RESOURCE_REPOSITORY_CONTENT_PR_DESCRIPTION", "Repository Content for specific pull request"), ), RepositoryResourceContentsHandler(getClient, getRawClient) @@ -113,7 +113,7 @@ func RepositoryResourceContentsHandler(getClient GetClientFn, getRawClient raw.G // fetch the PR from the API to get the latest commit and use SHA githubClient, err := getClient(ctx) if err != nil { - return nil, fmt.Errorf("failed to get GitHub client: %w", err) + return nil, fmt.Errorf(ErrFailedToGetGitHubClient, err) } prNum, err := strconv.Atoi(prNumber[0]) if err != nil { diff --git a/pkg/github/search.go b/pkg/github/search.go index 5106b84d8..91a42cb79 100644 --- a/pkg/github/search.go +++ b/pkg/github/search.go @@ -46,7 +46,7 @@ func SearchRepositories(getClient GetClientFn, t translations.TranslationHelperF client, err := getClient(ctx) if err != nil { - return nil, fmt.Errorf("failed to get GitHub client: %w", err) + return nil, fmt.Errorf(ErrFailedToGetGitHubClient, err) } result, resp, err := client.Search.Repositories(ctx, query, opts) if err != nil { @@ -68,7 +68,7 @@ func SearchRepositories(getClient GetClientFn, t translations.TranslationHelperF r, err := json.Marshal(result) if err != nil { - return nil, fmt.Errorf("failed to marshal response: %w", err) + return nil, fmt.Errorf(ErrFailedToMarshalResponse, err) } return mcp.NewToolResultText(string(r)), nil @@ -125,7 +125,7 @@ func SearchCode(getClient GetClientFn, t translations.TranslationHelperFunc) (to client, err := getClient(ctx) if err != nil { - return nil, fmt.Errorf("failed to get GitHub client: %w", err) + return nil, fmt.Errorf(ErrFailedToGetGitHubClient, err) } result, resp, err := client.Search.Code(ctx, query, opts) @@ -148,7 +148,7 @@ func SearchCode(getClient GetClientFn, t translations.TranslationHelperFunc) (to r, err := json.Marshal(result) if err != nil { - return nil, fmt.Errorf("failed to marshal response: %w", err) + return nil, fmt.Errorf(ErrFailedToMarshalResponse, err) } return mcp.NewToolResultText(string(r)), nil @@ -198,7 +198,7 @@ func userOrOrgHandler(accountType string, getClient GetClientFn) server.ToolHand client, err := getClient(ctx) if err != nil { - return nil, fmt.Errorf("failed to get GitHub client: %w", err) + return nil, fmt.Errorf(ErrFailedToGetGitHubClient, err) } searchQuery := "type:" + accountType + " " + query @@ -251,7 +251,7 @@ func userOrOrgHandler(accountType string, getClient GetClientFn) server.ToolHand r, err := json.Marshal(minimalResp) if err != nil { - return nil, fmt.Errorf("failed to marshal response: %w", err) + return nil, fmt.Errorf(ErrFailedToMarshalResponse, err) } return mcp.NewToolResultText(string(r)), nil } diff --git a/pkg/github/secret_scanning.go b/pkg/github/secret_scanning.go index bea6df2ae..eb5e6a1b2 100644 --- a/pkg/github/secret_scanning.go +++ b/pkg/github/secret_scanning.go @@ -51,7 +51,7 @@ func GetSecretScanningAlert(getClient GetClientFn, t translations.TranslationHel client, err := getClient(ctx) if err != nil { - return nil, fmt.Errorf("failed to get GitHub client: %w", err) + return nil, fmt.Errorf(ErrFailedToGetGitHubClient, err) } alert, resp, err := client.SecretScanning.GetAlert(ctx, owner, repo, int64(alertNumber)) @@ -133,7 +133,7 @@ func ListSecretScanningAlerts(getClient GetClientFn, t translations.TranslationH client, err := getClient(ctx) if err != nil { - return nil, fmt.Errorf("failed to get GitHub client: %w", err) + return nil, fmt.Errorf(ErrFailedToGetGitHubClient, err) } alerts, resp, err := client.SecretScanning.ListAlertsForRepo(ctx, owner, repo, &github.SecretScanningAlertListOptions{State: state, SecretType: secretType, Resolution: resolution}) if err != nil {