Skip to content

Commit

Permalink
github-bots: add a function to search for a filename in a repo
Browse files Browse the repository at this point in the history
Signed-off-by: hectorj2f <[email protected]>
  • Loading branch information
hectorj2f committed Nov 27, 2024
1 parent f5d0763 commit 82ee316
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
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
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}
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

0 comments on commit 82ee316

Please sign in to comment.