From cffb9b0a6a1281566b247f1dc5ef8f853d65376a Mon Sep 17 00:00:00 2001 From: legitnull <> Date: Tue, 11 Jul 2023 11:55:22 -0600 Subject: [PATCH] grab correct url --- main.go | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/main.go b/main.go index 281c7ee..49139af 100644 --- a/main.go +++ b/main.go @@ -4,7 +4,7 @@ import ( "context" "fmt" "log" - "regexp" + "strings" "github.com/fatih/color" "github.com/google/go-github/github" @@ -69,32 +69,32 @@ func fetchMatchingLine(url string) (string, error) { ctx := context.Background() client := github.NewClient(nil) - owner := "OWNER" - repo := "REPO" - path := "PATH" + apiURL := strings.Replace(url, "github.com", "api.github.com/repos", 1) + apiURL = strings.Replace(apiURL, "blob/", "", 1) - content, _, _, err := client.Repositories.GetContents(ctx, owner, repo, path, &github.RepositoryContentGetOptions{}) + fileContent, _, _, err := client.Repositories.GetContents(ctx, "", "", apiURL, &github.RepositoryContentGetOptions{}) if err != nil { return "", err } - contentBytes, err := content.GetContent() + contentBytes, err := fileContent.GetContent() if err != nil { return "", err } - // Find the matching line using regular expression - re := regexp.MustCompile(`.*filename:config irc_pass.*`) - match := re.FindString(string(contentBytes)) - if match == "" { - return "", fmt.Errorf("matching line not found") + // Find the matching line + lines := strings.Split(string(contentBytes), "\n") + for _, line := range lines { + if strings.Contains(line, "irc_pass") { + return line, nil + } } - return match, nil + return "", fmt.Errorf("matching line not found") } func main() { - token := "YOUR_PERSONAL_ACCESS_TOKEN" // Replace with your GitHub token + token := "token here" // Replace with your GitHub token client := createClient(token) err := scrapeGitHubRepositories(client)