Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
119 changes: 57 additions & 62 deletions pkg/github/actions.go

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions pkg/github/code_scanning.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down Expand Up @@ -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 {
Expand Down
11 changes: 11 additions & 0 deletions pkg/github/constants.go
Original file line number Diff line number Diff line change
@@ -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://"
)
16 changes: 8 additions & 8 deletions pkg/github/discussions.go
Original file line number Diff line number Diff line change
Expand Up @@ -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."),
Expand Down Expand Up @@ -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(),
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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)"),
Expand Down
34 changes: 17 additions & 17 deletions pkg/github/issues.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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(),
Expand Down Expand Up @@ -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 {
Expand All @@ -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
Expand Down Expand Up @@ -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(),
Expand Down Expand Up @@ -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 {
Expand All @@ -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
Expand All @@ -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"),
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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(),
Expand Down Expand Up @@ -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 {
Expand All @@ -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
Expand All @@ -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(),
Expand Down Expand Up @@ -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 {
Expand All @@ -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
Expand Down Expand Up @@ -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(),
Expand All @@ -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.
Expand Down
20 changes: 10 additions & 10 deletions pkg/github/notifications.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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
Expand All @@ -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")
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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
}
Expand Down
Loading