Merge branch 'dev' into directory-listing-json

This commit is contained in:
al2f
2024-01-25 12:42:20 +10:30
+12 -14
View File
@@ -5,9 +5,9 @@ import (
"net/http"
"os"
"strings"
"github.com/tidwall/gjson"
"codeberg.org/gothub/gothub/utils"
"github.com/gocolly/colly"
"github.com/gofiber/fiber/v2"
@@ -93,11 +93,11 @@ func HandleRepo(c *fiber.Ctx) error {
sc.OnHTML("div#readme", func(e *colly.HTMLElement) {
Scrape.Readme = e.ChildText("a[href='#readme']")
})
// jq '.props.initialPayload.overview.overviewFiles[]|select(.tabName == "README").richText'
sc.OnHTML("div.Layout-main react-partial script", func(e *colly.HTMLElement) {
jsonMess := e.Text
result := gjson.Get(jsonMess, "props.initialPayload.overview.overviewFiles")
result.ForEach(func(i, e gjson.Result) bool {
if e.Get("tabName").Str == "README" {
@@ -107,28 +107,26 @@ func HandleRepo(c *fiber.Ctx) error {
}
return true // keep iterating
})
result = gjson.Get(jsonMess, "props.initialPayload.tree.items")
//jq '.props.initialPayload.tree.items'
result.ForEach(func(i, e gjson.Result) bool {
var FileType string
if(e.Get("contentType").Str == "directory"){
if e.Get("contentType").Str == "directory" {
FileType = "dir"
} else {
FileType = "file"
}
repoFilesArray = append(repoFilesArray, RepoFiles{
Name: e.Get("name").Str,
Path: e.Get("path").Str,
Type: FileType,
Name: e.Get("name").Str,
Path: e.Get("path").Str,
Type: FileType,
DefaultBranch: gjson.Get(jsonMess, "props.initialPayload.repo.defaultBranch").Str,
Fullname: Scrape.Fullname,
Fullname: Scrape.Fullname,
})
return true //keep iterating
})
})
sc.OnHTML("div.BorderGrid-cell ul.list-style-none", func(e *colly.HTMLElement) {
@@ -147,7 +145,7 @@ func HandleRepo(c *fiber.Ctx) error {
Scrape.DefaultBranch = e.ChildText("span.css-truncate-target")
})
sc.Visit("https://github.com/" + c.Params("user") + "/" + repoUrl + branchExists)
// Add scrape-based info to repoArray
repoArray = append(repoArray, Scrape)
return c.Render("repo", fiber.Map{