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)