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" "context"
"fmt" "fmt"
"log" "log"
"regexp" "strings"
"github.com/fatih/color" "github.com/fatih/color"
"github.com/google/go-github/github" "github.com/google/go-github/github"
@ -69,32 +69,32 @@ func fetchMatchingLine(url string) (string, error) {
ctx := context.Background() ctx := context.Background()
client := github.NewClient(nil) client := github.NewClient(nil)
owner := "OWNER" apiURL := strings.Replace(url, "github.com", "api.github.com/repos", 1)
repo := "REPO" apiURL = strings.Replace(apiURL, "blob/", "", 1)
path := "PATH"
content, _, _, err := client.Repositories.GetContents(ctx, owner, repo, path, &github.RepositoryContentGetOptions{}) fileContent, _, _, err := client.Repositories.GetContents(ctx, "", "", apiURL, &github.RepositoryContentGetOptions{})
if err != nil { if err != nil {
return "", err return "", err
} }
contentBytes, err := content.GetContent() contentBytes, err := fileContent.GetContent()
if err != nil { if err != nil {
return "", err return "", err
} }
// Find the matching line using regular expression // Find the matching line
re := regexp.MustCompile(`.*filename:config irc_pass.*`) lines := strings.Split(string(contentBytes), "\n")
match := re.FindString(string(contentBytes)) for _, line := range lines {
if match == "" { if strings.Contains(line, "irc_pass") {
return line, nil
}
}
return "", fmt.Errorf("matching line not found") return "", fmt.Errorf("matching line not found")
} }
return match, nil
}
func main() { func main() {
token := "YOUR_PERSONAL_ACCESS_TOKEN" // Replace with your GitHub token token := "token here" // Replace with your GitHub token
client := createClient(token) client := createClient(token)
err := scrapeGitHubRepositories(client) err := scrapeGitHubRepositories(client)