add contributor scraping and non-markdown Release Notes

This commit is contained in:
Arya Kiran
2023-05-09 17:09:26 +05:30
parent aa578ff02c
commit a5324ccdca
+8 -6
View File
@@ -75,15 +75,17 @@ func ReleaseView(c *fiber.Ctx) error {
Content, _ := e.DOM.Html()
Scrape.ReleaseContent = strings.Replace(strings.Replace(strings.Replace(strings.Replace(string(utils.UGCPolicy().SanitizeBytes([]byte(Content))), "https://github.com", "", -1), "user-content-", "", -1), "https://camo.githubusercontent.com", "/camo", -1), "https://raw.githubusercontent.com", "/raw", -1)
})
// Check if the release notes are in <pre> form if it isn't markdown
if Scrape.ReleaseContent == "" {
sc.OnHTML("div.Box-body pre", func(e *colly.HTMLElement) {
Content, _ := e.DOM.Html()
Scrape.ReleaseContent = "<pre>" + strings.Replace(strings.Replace(strings.Replace(strings.Replace(string(utils.UGCPolicy().SanitizeBytes([]byte(Content))), "https://github.com", "", -1), "user-content-", "", -1), "https://camo.githubusercontent.com", "/camo", -1), "https://raw.githubusercontent.com", "/raw", -1) + "</pre>"
})
}
sc.OnHTML("div.Box-footer", func(e *colly.HTMLElement) {
Scrape.AssetCount = e.ChildText("details summary span.Counter")
e.ForEach("ul li", func(i int, el *colly.HTMLElement) {
Scrape.Assets = append(Scrape.Assets, Assets{
Name: el.ChildText("div.flex-justify-start a span.text-bold"),
Link: el.ChildAttr("div.flex-justify-start a", "href"),
Size: el.ChildText("div.flex-justify-end span.text-sm-left"),
ReleasedOn: el.ChildText("div.flex-justify-end span.text-right relative-time"),
})
Scrape.Contributors = append(Scrape.Contributors, strings.TrimPrefix(el.ChildAttr("a img", "alt"), "@"))
})
})
sc.Visit("https://github.com/" + c.Params("user") + "/" + c.Params("repo") + "/releases/" + c.Params("release"))