-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
github-bots: add a function to search for a filename in a repo (#643)
On the ai remediation bot, we need to search for specific filenames on a repository such as go.mod, pyproject.toml, Cargo.toml... If these files are found then we get the content specifying the path using another existing function GetFileContent which would be used to generate a precise patch. --------- Signed-off-by: hectorj2f <[email protected]>
- Loading branch information
Showing
2 changed files
with
57 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
//go:build integration | ||
// +build integration | ||
|
||
package sdk | ||
|
||
import ( | ||
"context" | ||
"os" | ||
"testing" | ||
|
||
"github.com/google/go-github/v61/github" | ||
) | ||
|
||
// NOTE: This is an integration test that requires 'GITHUB_TOKEN' env variable to be set! | ||
// It is recommended to run this test in a local environment. | ||
func Test_SearchFilenameInRepository(t *testing.T) { | ||
ctx := context.Background() | ||
|
||
if os.Getenv("GITHUB_TOKEN") == "" { | ||
t.Fatalf("GITHUB_TOKEN env var not set\n") | ||
} | ||
|
||
// create a GitHub client | ||
repoOrg := "kserve" | ||
repoName := "kserve" | ||
// sdk allows an override of GIT_TOKEN env var so we can test from a local environment | ||
cli := NewGitHubClient(ctx, repoOrg, repoName, "test") | ||
result, err := cli.SearchFilenameInRepository(ctx, repoOrg, repoName, "pyproject.toml", &github.ListOptions{}) | ||
if err != nil { | ||
t.Fatalf("SearchFilenameInRepository err: %v\n", err) | ||
} | ||
|
||
if *result.Total == 0 { | ||
t.Fatalf("SearchFilenameInRepository result is zero\n") | ||
} | ||
} |