Skip to content

Commit 820fe90

Browse files
committed
feat(secret_scanning): add pagination to list_secret_scanning_alerts (github#2363)
1 parent 7e35a5b commit 820fe90

1 file changed

Lines changed: 45 additions & 29 deletions

File tree

‎pkg/github/secret_scanning.go‎

Lines changed: 45 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,36 @@ func GetSecretScanningAlert(t translations.TranslationHelperFunc) inventory.Serv
9595
}
9696

9797
func ListSecretScanningAlerts(t translations.TranslationHelperFunc) inventory.ServerTool {
98+
schema := &jsonschema.Schema{
99+
Type: "object",
100+
Properties: map[string]*jsonschema.Schema{
101+
"owner": {
102+
Type: "string",
103+
Description: "The owner of the repository.",
104+
},
105+
"repo": {
106+
Type: "string",
107+
Description: "The name of the repository.",
108+
},
109+
"state": {
110+
Type: "string",
111+
Description: "Filter by state",
112+
Enum: []any{"open", "resolved"},
113+
},
114+
"secret_type": {
115+
Type: "string",
116+
Description: "A comma-separated list of secret types to return. All default secret patterns are returned. To return generic patterns, pass the token name(s) in the parameter.",
117+
},
118+
"resolution": {
119+
Type: "string",
120+
Description: "Filter by resolution",
121+
Enum: []any{"false_positive", "wont_fix", "revoked", "pattern_edited", "pattern_deleted", "used_in_tests"},
122+
},
123+
},
124+
Required: []string{"owner", "repo"},
125+
}
126+
WithPagination(schema)
127+
98128
return NewTool(
99129
ToolsetMetadataSecretProtection,
100130
mcp.Tool{
@@ -104,34 +134,7 @@ func ListSecretScanningAlerts(t translations.TranslationHelperFunc) inventory.Se
104134
Title: t("TOOL_LIST_SECRET_SCANNING_ALERTS_USER_TITLE", "List secret scanning alerts"),
105135
ReadOnlyHint: true,
106136
},
107-
InputSchema: &jsonschema.Schema{
108-
Type: "object",
109-
Properties: map[string]*jsonschema.Schema{
110-
"owner": {
111-
Type: "string",
112-
Description: "The owner of the repository.",
113-
},
114-
"repo": {
115-
Type: "string",
116-
Description: "The name of the repository.",
117-
},
118-
"state": {
119-
Type: "string",
120-
Description: "Filter by state",
121-
Enum: []any{"open", "resolved"},
122-
},
123-
"secret_type": {
124-
Type: "string",
125-
Description: "A comma-separated list of secret types to return. All default secret patterns are returned. To return generic patterns, pass the token name(s) in the parameter.",
126-
},
127-
"resolution": {
128-
Type: "string",
129-
Description: "Filter by resolution",
130-
Enum: []any{"false_positive", "wont_fix", "revoked", "pattern_edited", "pattern_deleted", "used_in_tests"},
131-
},
132-
},
133-
Required: []string{"owner", "repo"},
134-
},
137+
InputSchema: schema,
135138
},
136139
[]scopes.Scope{scopes.SecurityEvents},
137140
func(ctx context.Context, deps ToolDependencies, _ *mcp.CallToolRequest, args map[string]any) (*mcp.CallToolResult, any, error) {
@@ -156,11 +159,24 @@ func ListSecretScanningAlerts(t translations.TranslationHelperFunc) inventory.Se
156159
return utils.NewToolResultError(err.Error()), nil, nil
157160
}
158161

162+
pagination, err := OptionalPaginationParams(args)
163+
if err != nil {
164+
return utils.NewToolResultError(err.Error()), nil, nil
165+
}
166+
159167
client, err := deps.GetClient(ctx)
160168
if err != nil {
161169
return nil, nil, fmt.Errorf("failed to get GitHub client: %w", err)
162170
}
163-
alerts, resp, err := client.SecretScanning.ListAlertsForRepo(ctx, owner, repo, &github.SecretScanningAlertListOptions{State: state, SecretType: secretType, Resolution: resolution})
171+
alerts, resp, err := client.SecretScanning.ListAlertsForRepo(ctx, owner, repo, &github.SecretScanningAlertListOptions{
172+
State: state,
173+
SecretType: secretType,
174+
Resolution: resolution,
175+
ListOptions: github.ListOptions{
176+
Page: pagination.Page,
177+
PerPage: pagination.PerPage,
178+
},
179+
})
164180
if err != nil {
165181
return ghErrors.NewGitHubAPIErrorResponse(ctx,
166182
fmt.Sprintf("failed to list alerts for repository '%s/%s'", owner, repo),

0 commit comments

Comments
 (0)