SearchCommits creates a tool to search for commits across GitHub repositories.
(t translations.TranslationHelperFunc)
| 494 | |
| 495 | // SearchCommits creates a tool to search for commits across GitHub repositories. |
| 496 | func SearchCommits(t translations.TranslationHelperFunc) inventory.ServerTool { |
| 497 | schema := &jsonschema.Schema{ |
| 498 | Type: "object", |
| 499 | Properties: map[string]*jsonschema.Schema{ |
| 500 | "query": { |
| 501 | Type: "string", |
| 502 | Description: "Commit search query (GitHub commit search REST). Searches commit messages on the default branch only. Scope the search with `repo:owner/repo`, `org:`, or `user:` (queries without a scope qualifier match across all of GitHub and are usually not what you want). Other qualifiers: `author:`, `committer:`, `author-name:`, `committer-name:`, `author-email:`, `committer-email:`, `author-date:`, `committer-date:` (supports `>`, `<`, `>=`, `<=`, and `YYYY-MM-DD..YYYY-MM-DD` ranges), `merge:true|false`, `hash:`, `tree:`, `parent:`, `is:public`. Examples: `repo:owner/repo fix panic`; `org:github author:defunkt committer-date:>=2024-01-01`; `\"refactor cache\" repo:o/r`; `hash:abc1234 repo:o/r`.", |
| 503 | }, |
| 504 | "sort": { |
| 505 | Type: "string", |
| 506 | Description: "Sort by author or committer date (defaults to best match)", |
| 507 | Enum: []any{"author-date", "committer-date"}, |
| 508 | }, |
| 509 | "order": { |
| 510 | Type: "string", |
| 511 | Description: "Sort order", |
| 512 | Enum: []any{"asc", "desc"}, |
| 513 | }, |
| 514 | }, |
| 515 | Required: []string{"query"}, |
| 516 | } |
| 517 | WithPagination(schema) |
| 518 | |
| 519 | return NewTool( |
| 520 | ToolsetMetadataRepos, |
| 521 | mcp.Tool{ |
| 522 | Name: "search_commits", |
| 523 | Description: t("TOOL_SEARCH_COMMITS_DESCRIPTION", "Search for commits across GitHub repositories using GitHub's commit search syntax. Useful for finding specific changes, authors, or messages across one or many repositories. Searches the default branch only."), |
| 524 | Annotations: &mcp.ToolAnnotations{ |
| 525 | Title: t("TOOL_SEARCH_COMMITS_USER_TITLE", "Search commits"), |
| 526 | ReadOnlyHint: true, |
| 527 | }, |
| 528 | InputSchema: schema, |
| 529 | }, |
| 530 | []scopes.Scope{scopes.Repo}, |
| 531 | func(ctx context.Context, deps ToolDependencies, _ *mcp.CallToolRequest, args map[string]any) (*mcp.CallToolResult, any, error) { |
| 532 | query, err := RequiredParam[string](args, "query") |
| 533 | if err != nil { |
| 534 | return utils.NewToolResultError(err.Error()), nil, nil |
| 535 | } |
| 536 | sort, err := OptionalParam[string](args, "sort") |
| 537 | if err != nil { |
| 538 | return utils.NewToolResultError(err.Error()), nil, nil |
| 539 | } |
| 540 | order, err := OptionalParam[string](args, "order") |
| 541 | if err != nil { |
| 542 | return utils.NewToolResultError(err.Error()), nil, nil |
| 543 | } |
| 544 | pagination, err := OptionalPaginationParams(args) |
| 545 | if err != nil { |
| 546 | return utils.NewToolResultError(err.Error()), nil, nil |
| 547 | } |
| 548 | |
| 549 | opts := &github.SearchOptions{ |
| 550 | Sort: sort, |
| 551 | Order: order, |
| 552 | ListOptions: github.ListOptions{ |
| 553 | Page: pagination.Page, |