grab correct url
This commit is contained in:
parent
5f82434ec2
commit
cffb9b0a6a
28
main.go
28
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 == "" {
|
||||
// Find the matching line
|
||||
lines := strings.Split(string(contentBytes), "\n")
|
||||
for _, line := range lines {
|
||||
if strings.Contains(line, "irc_pass") {
|
||||
return line, nil
|
||||
}
|
||||
}
|
||||
|
||||
return "", fmt.Errorf("matching line not found")
|
||||
}
|
||||
|
||||
return match, nil
|
||||
}
|
||||
|
||||
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)
|
||||
|
Loading…
Reference in New Issue
Block a user