- Notifications
You must be signed in to change notification settings - Fork2.7k
Repository security advisories#925
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Merged
Uh oh!
There was an error while loading.Please reload this page.
Merged
Changes fromall commits
Commits
Show all changes
2 commits Select commitHold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -182,6 +182,95 @@ func ListGlobalSecurityAdvisories(getClient GetClientFn, t translations.Translat | ||
} | ||
} | ||
func ListRepositorySecurityAdvisories(getClient GetClientFn, t translations.TranslationHelperFunc) (tool mcp.Tool, handler server.ToolHandlerFunc) { | ||
return mcp.NewTool("list_repository_security_advisories", | ||
mcp.WithDescription(t("TOOL_LIST_REPOSITORY_SECURITY_ADVISORIES_DESCRIPTION", "List repository security advisories for a GitHub repository.")), | ||
mcp.WithToolAnnotation(mcp.ToolAnnotation{ | ||
Title: t("TOOL_LIST_REPOSITORY_SECURITY_ADVISORIES_USER_TITLE", "List repository security advisories"), | ||
ReadOnlyHint: ToBoolPtr(true), | ||
}), | ||
mcp.WithString("owner", | ||
mcp.Required(), | ||
mcp.Description("The owner of the repository."), | ||
), | ||
mcp.WithString("repo", | ||
mcp.Required(), | ||
mcp.Description("The name of the repository."), | ||
), | ||
mcp.WithString("direction", | ||
mcp.Description("Sort direction."), | ||
mcp.Enum("asc", "desc"), | ||
), | ||
mcp.WithString("sort", | ||
mcp.Description("Sort field."), | ||
mcp.Enum("created", "updated", "published"), | ||
), | ||
mcp.WithString("state", | ||
mcp.Description("Filter by advisory state."), | ||
mcp.Enum("triage", "draft", "published", "closed"), | ||
), | ||
), 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 | ||
} | ||
direction, err := OptionalParam[string](request, "direction") | ||
if err != nil { | ||
return mcp.NewToolResultError(err.Error()), nil | ||
} | ||
sortField, err := OptionalParam[string](request, "sort") | ||
if err != nil { | ||
return mcp.NewToolResultError(err.Error()), nil | ||
} | ||
state, err := OptionalParam[string](request, "state") | ||
if err != nil { | ||
return mcp.NewToolResultError(err.Error()), nil | ||
} | ||
client, err := getClient(ctx) | ||
if err != nil { | ||
return nil, fmt.Errorf("failed to get GitHub client: %w", err) | ||
} | ||
opts := &github.ListRepositorySecurityAdvisoriesOptions{} | ||
if direction != "" { | ||
opts.Direction = direction | ||
} | ||
if sortField != "" { | ||
opts.Sort = sortField | ||
} | ||
if state != "" { | ||
opts.State = state | ||
} | ||
advisories, resp, err := client.SecurityAdvisories.ListRepositorySecurityAdvisories(ctx, owner, repo, opts) | ||
if err != nil { | ||
return nil, fmt.Errorf("failed to list repository security advisories: %w", err) | ||
} | ||
defer func() { _ = resp.Body.Close() }() | ||
if resp.StatusCode != http.StatusOK { | ||
body, err := io.ReadAll(resp.Body) | ||
if err != nil { | ||
return nil, fmt.Errorf("failed to read response body: %w", err) | ||
} | ||
return mcp.NewToolResultError(fmt.Sprintf("failed to list repository advisories: %s", string(body))), nil | ||
} | ||
r, err := json.Marshal(advisories) | ||
if err != nil { | ||
return nil, fmt.Errorf("failed to marshal advisories: %w", err) | ||
} | ||
return mcp.NewToolResultText(string(r)), nil | ||
} | ||
} | ||
func GetGlobalSecurityAdvisory(getClient GetClientFn, t translations.TranslationHelperFunc) (tool mcp.Tool, handler server.ToolHandlerFunc) { | ||
return mcp.NewTool("get_global_security_advisory", | ||
mcp.WithDescription(t("TOOL_GET_GLOBAL_SECURITY_ADVISORY_DESCRIPTION", "Get a global security advisory")), | ||
@@ -226,3 +315,83 @@ func GetGlobalSecurityAdvisory(getClient GetClientFn, t translations.Translation | ||
return mcp.NewToolResultText(string(r)), nil | ||
} | ||
} | ||
func ListOrgRepositorySecurityAdvisories(getClient GetClientFn, t translations.TranslationHelperFunc) (tool mcp.Tool, handler server.ToolHandlerFunc) { | ||
return mcp.NewTool("list_org_repository_security_advisories", | ||
mcp.WithDescription(t("TOOL_LIST_ORG_REPOSITORY_SECURITY_ADVISORIES_DESCRIPTION", "List repository security advisories for a GitHub organization.")), | ||
mcp.WithToolAnnotation(mcp.ToolAnnotation{ | ||
Title: t("TOOL_LIST_ORG_REPOSITORY_SECURITY_ADVISORIES_USER_TITLE", "List org repository security advisories"), | ||
ReadOnlyHint: ToBoolPtr(true), | ||
}), | ||
mcp.WithString("org", | ||
mcp.Required(), | ||
mcp.Description("The organization login."), | ||
), | ||
mcp.WithString("direction", | ||
mcp.Description("Sort direction."), | ||
mcp.Enum("asc", "desc"), | ||
), | ||
mcp.WithString("sort", | ||
mcp.Description("Sort field."), | ||
mcp.Enum("created", "updated", "published"), | ||
), | ||
mcp.WithString("state", | ||
mcp.Description("Filter by advisory state."), | ||
mcp.Enum("triage", "draft", "published", "closed"), | ||
), | ||
), func(ctx context.Context, request mcp.CallToolRequest) (*mcp.CallToolResult, error) { | ||
org, err := RequiredParam[string](request, "org") | ||
if err != nil { | ||
return mcp.NewToolResultError(err.Error()), nil | ||
} | ||
direction, err := OptionalParam[string](request, "direction") | ||
if err != nil { | ||
return mcp.NewToolResultError(err.Error()), nil | ||
} | ||
sortField, err := OptionalParam[string](request, "sort") | ||
if err != nil { | ||
return mcp.NewToolResultError(err.Error()), nil | ||
} | ||
state, err := OptionalParam[string](request, "state") | ||
if err != nil { | ||
return mcp.NewToolResultError(err.Error()), nil | ||
} | ||
client, err := getClient(ctx) | ||
if err != nil { | ||
return nil, fmt.Errorf("failed to get GitHub client: %w", err) | ||
} | ||
opts := &github.ListRepositorySecurityAdvisoriesOptions{} | ||
if direction != "" { | ||
opts.Direction = direction | ||
} | ||
if sortField != "" { | ||
opts.Sort = sortField | ||
} | ||
if state != "" { | ||
opts.State = state | ||
} | ||
jurre marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
advisories, resp, err := client.SecurityAdvisories.ListRepositorySecurityAdvisoriesForOrg(ctx, org, opts) | ||
if err != nil { | ||
return nil, fmt.Errorf("failed to list organization repository security advisories: %w", err) | ||
} | ||
defer func() { _ = resp.Body.Close() }() | ||
if resp.StatusCode != http.StatusOK { | ||
body, err := io.ReadAll(resp.Body) | ||
if err != nil { | ||
return nil, fmt.Errorf("failed to read response body: %w", err) | ||
} | ||
return mcp.NewToolResultError(fmt.Sprintf("failed to list organization repository advisories: %s", string(body))), nil | ||
} | ||
r, err := json.Marshal(advisories) | ||
if err != nil { | ||
return nil, fmt.Errorf("failed to marshal advisories: %w", err) | ||
} | ||
return mcp.NewToolResultText(string(r)), nil | ||
} | ||
} |
Oops, something went wrong.
Uh oh!
There was an error while loading.Please reload this page.
Oops, something went wrong.
Uh oh!
There was an error while loading.Please reload this page.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.