diff --git a/modules/github-bots/sdk/github.go b/modules/github-bots/sdk/github.go index 3f43dc2b..e7d0adad 100644 --- a/modules/github-bots/sdk/github.go +++ b/modules/github-bots/sdk/github.go @@ -579,6 +579,22 @@ func (c GitHubClient) GetFileContent(ctx context.Context, owner, repo, path, ref return content, nil } +// SearchFilenameInRepository searches for a filename in a specific repository +func (c GitHubClient) SearchFilenameInRepository(ctx context.Context, owner, repo, path string) (*github.CodeSearchResult, error) { + query := fmt.Sprintf("filename:%s repo:%s/%s", path, owner, repo) + result, resp, err := c.inner.Search.Code( + ctx, + query, + &github.SearchOptions{}, + ) + + if err := validateResponse(ctx, err, resp, fmt.Sprintf("search filename %s in repository", path)); err != nil { + return &github.CodeSearchResult{}, err + } + + return result, nil +} + // ListFiles lists the files in a directory at a given ref func (c GitHubClient) ListFiles(ctx context.Context, owner, repo, path, ref string) ([]*github.RepositoryContent, error) { opts := &github.RepositoryContentGetOptions{Ref: ref} diff --git a/modules/github-bots/test/main.go b/modules/github-bots/test/main.go new file mode 100644 index 00000000..56e54040 --- /dev/null +++ b/modules/github-bots/test/main.go @@ -0,0 +1 @@ +package test