Skip to content
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

github-bots: add a function to search for a filename in a repo #643

Merged
merged 3 commits into from
Nov 27, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
16 changes: 16 additions & 0 deletions modules/github-bots/sdk/github.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
hectorj2f marked this conversation as resolved.
Show resolved Hide resolved
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{},
hectorj2f marked this conversation as resolved.
Show resolved Hide resolved
)

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}
Expand Down
1 change: 1 addition & 0 deletions modules/github-bots/test/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
package test