grab correct url

This commit is contained in:
legitnull 2023-07-11 11:55:22 -06:00
parent 5f82434ec2
commit cffb9b0a6a
WARNING! Although there is a key with this ID in the database it does not verify this commit! This commit is SUSPICIOUS.
GPG Key ID: 28D3A882F3E6AD02

28
main.go
View File

@ -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)