ブランチ
このコミットが含まれているのは:
コミット
bfb49a46f0
125
pages/branches.go
ノーマルファイル
125
pages/branches.go
ノーマルファイル
@ -0,0 +1,125 @@
|
||||
package pages
|
||||
|
||||
import (
|
||||
"log"
|
||||
"net/http"
|
||||
"os"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"gitler.moe/suwako/gitlin/utils"
|
||||
"github.com/gocolly/colly"
|
||||
"github.com/gofiber/fiber/v2"
|
||||
)
|
||||
|
||||
type (
|
||||
BranchCat struct {
|
||||
Id, Name string
|
||||
Branch []Branch
|
||||
}
|
||||
CommitDiff struct {
|
||||
Count, Width string
|
||||
}
|
||||
Branch struct {
|
||||
Name, LastCommit, Username, Issue, Status, Activity, Compare string
|
||||
CommitsAhead, CommitsBehind CommitDiff
|
||||
}
|
||||
)
|
||||
|
||||
func HandleBranches (c *fiber.Ctx) error {
|
||||
var branchesArray []BranchCat
|
||||
cat := "/all"
|
||||
if c.Params("cat") != "" {
|
||||
cat = "/" + c.Params("cat")
|
||||
}
|
||||
|
||||
Scrape := BranchCat{}
|
||||
|
||||
repoUrl := strings.TrimSuffix(c.Params("repo"), ".git")
|
||||
resp, err := http.Get("https://github.com/" + c.Params("user") + "/" + repoUrl + "/branches" + cat)
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
}
|
||||
if resp.StatusCode == 404 {
|
||||
return c.Status(404).Render("error", fiber.Map {
|
||||
"title": "Error",
|
||||
"ver": utils.Ver,
|
||||
"ves": utils.Ves,
|
||||
"error": "Repository " + c.Params("user") + "/" + repoUrl + "/branches" + cat + "not found",
|
||||
})
|
||||
}
|
||||
|
||||
ua, ok := os.LookupEnv("GITLIN_USER_AGENT")
|
||||
if !ok {
|
||||
ua = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/110.0.0.0 Safari/537.36"
|
||||
}
|
||||
|
||||
sc := colly.NewCollector(colly.AllowedDomains("github.com"), colly.UserAgent(ua))
|
||||
sc.Limit(&colly.LimitRule {
|
||||
DomainGlob: "github.githubassets.com/*",
|
||||
Delay: 30 * time.Second,
|
||||
RandomDelay: 30 * time.Second,
|
||||
})
|
||||
sc.OnRequest(func(r *colly.Request) {
|
||||
r.Headers.Set("Cache-Control", "no-cache, no-store, must-revalidate")
|
||||
r.Headers.Set("Pragma", "no-cache")
|
||||
r.Headers.Set("Expires", "0")
|
||||
})
|
||||
|
||||
sc.OnHTML(`div[data-target="branch-filter.result"]`, func (e *colly.HTMLElement) {
|
||||
var branchArray []Branch
|
||||
e.ForEach("div.Box--condensed", func (i int, el *colly.HTMLElement) {
|
||||
Scrape.Name = el.ChildText("div.Box-header .Box-title")
|
||||
Scrape.Id = strings.ToLower(strings.TrimSuffix(Scrape.Name, " "))
|
||||
var name, lcom, uname, issue, status, activity, compare string
|
||||
var cahead, cbehind CommitDiff
|
||||
el.ForEach("ul li.position-relative branch-filter-item.Details", func (ij int, elc *colly.HTMLElement) {
|
||||
name = elc.ChildText("div.col-12 a.branch-name")
|
||||
tdate := elc.ChildText("div.col-12 span.css-truncate-target relative-time")
|
||||
td, e := time.Parse("Jan 2, 2006 16:09", tdate)
|
||||
if e != nil {
|
||||
log.Println(e)
|
||||
}
|
||||
lcom = td.Format("2006年01月02日 16:09")
|
||||
uname = elc.ChildText("div.col-12 span.css-truncate-target a.Link--muted")
|
||||
elc.ForEach("div.col-md-6 div.col-md-12 div div div.count-half", func (ijk int, elcb *colly.HTMLElement) {
|
||||
cbehind.Count = elcb.ChildText("count-behind")
|
||||
cbehind.Width = strings.ReplaceAll(elcb.ChildAttr("div.bar-behind", "style"), "width:", "")
|
||||
cahead.Count = elcb.ChildText("count-after")
|
||||
cahead.Width = strings.ReplaceAll(elcb.ChildAttr("div.bar-after", "style"), "width:", "")
|
||||
})
|
||||
issue = strings.TrimPrefix(elc.ChildText(`div.col-md-6 div.Details-content--shown div.text-right a[data-hovercard-type="pull_request"]`), "#")
|
||||
status = strings.TrimPrefix(elc.ChildAttr("div.col-md-6 div.Details-content--shown div.text-right span.State", "title"), "Status: ")
|
||||
activity = elc.ChildAttr("div.col-md-6 div.Details-content--shown a.tooltipped", "href")
|
||||
compare = elc.ChildAttr("div.col-md-6 div.Details-content--shown a.test-compare-link", "href")
|
||||
})
|
||||
|
||||
branchArray = append(branchArray, Branch {
|
||||
Name: name,
|
||||
LastCommit: lcom,
|
||||
Username: uname,
|
||||
CommitsAhead: cahead,
|
||||
CommitsBehind: cbehind,
|
||||
Issue: issue,
|
||||
Status: status,
|
||||
Activity: activity,
|
||||
Compare: compare,
|
||||
})
|
||||
})
|
||||
Scrape.Branch = branchArray
|
||||
branchesArray = append(branchesArray, Scrape)
|
||||
})
|
||||
|
||||
sc.Visit("https://github.com/" + c.Params("user") + "/" + repoUrl + "/branches" + cat)
|
||||
|
||||
return c.Render("branches", fiber.Map {
|
||||
"title": c.Params("user") + "/" + repoUrl + "/branches" + cat,
|
||||
"username": c.Params("user"),
|
||||
"reponame": repoUrl,
|
||||
"ver": utils.Ver,
|
||||
"ves": utils.Ves,
|
||||
"branches": branchesArray,
|
||||
})
|
||||
|
||||
return nil
|
||||
}
|
@ -348,3 +348,11 @@ a:hover {
|
||||
align-items: inherit;
|
||||
flex-direction: inherit;
|
||||
}
|
||||
|
||||
.count-half {
|
||||
position: relative;
|
||||
float: left;
|
||||
width: 90px;
|
||||
padding-bottom: 4px;
|
||||
text-align: right;
|
||||
}
|
||||
|
@ -204,6 +204,7 @@ func Serve(port string) {
|
||||
}
|
||||
})
|
||||
app.Get("/:user/:repo/commits/:branch?", pages.HandleCommits)
|
||||
app.Get("/:user/:repo/branches/:cat?", pages.HandleBranches)
|
||||
|
||||
api := app.Group("/api")
|
||||
v1 := api.Group("/v1")
|
||||
|
53
views/branches.html
ノーマルファイル
53
views/branches.html
ノーマルファイル
@ -0,0 +1,53 @@
|
||||
{{ template "header" . }}
|
||||
|
||||
<main>
|
||||
<div class="user-profile">
|
||||
<h1>
|
||||
<a href="/{{.username}}">{{.username}}</a>
|
||||
/
|
||||
<a href="/{{.username}}/{{.reponame}}">{{.reponame}}</a>
|
||||
</h1>
|
||||
{{.branches}}
|
||||
{{range $key, $value := .branches}}
|
||||
<h3>{{$value.Name}}</h3>
|
||||
<div class="">
|
||||
<a href="/{{$.username}}/{{$.reponame}}/branches" class="button">詳細</a>
|
||||
<a href="/{{$.username}}/{{$.reponame}}/branches/active" class="button">アクティブ</a>
|
||||
<a href="/{{$.username}}/{{$.reponame}}/branches/stale" class="button">中止</a>
|
||||
<a href="/{{$.username}}/{{$.reponame}}/branches/all" class="button">ずべて</a>
|
||||
</div>
|
||||
<table class="user-readme-text file-table">
|
||||
<tbody>
|
||||
{{range $k, $v := $value.Branch}}
|
||||
<tr class="file-u-list">
|
||||
<td>
|
||||
<a href="/{{$.username}}/{{$.reponame}}/tree/{{$v.Name}}">{{$v.Name}}</a>,
|
||||
<a href="/{{$v.Username}}">{{$v.Username}}</a> @ {{$v.LastCommit}}
|
||||
</td>
|
||||
<td>
|
||||
<div class="count-half">
|
||||
{{$value.CommitsBehind.Count}}
|
||||
{{$value.CommitsAhead.Count}}
|
||||
</div>
|
||||
</td>
|
||||
<td>
|
||||
{{if $value.Issue}}<a href="/{{$.username}}/{{$.reponame}}/pull/#{{$value.Issue}}">{{$value.Issue}}</a>{{end}}
|
||||
{{if $value.Compare}}<a href="/{{$.username}}/{{$.reponame}}/compare/{{$value.Compare}}">比較</a>{{end}}
|
||||
{{if $value.Status}}{{$value.Status}}{{end}}
|
||||
</td>
|
||||
</tr>
|
||||
{{end}}
|
||||
{{if ne "default" $value.Id}}
|
||||
<tr>
|
||||
<td colspan="3" style="text-align: center;">
|
||||
<a href="/{{$.username}}/{{$.reponame}}/branches/{{$value.Id}}">他の{{$value.Id}}ブランチを表示</a>
|
||||
</td>
|
||||
</tr>
|
||||
{{end}}
|
||||
</tbody>
|
||||
</table>
|
||||
{{end}}
|
||||
</div>
|
||||
</main>
|
||||
|
||||
{{ template "footer" . }}
|
@ -3,6 +3,7 @@
|
||||
<main>
|
||||
{{ if .repo }} {{ range $key, $value := .repo}}
|
||||
<div class="button-parent">
|
||||
<a href="/{{.Username}}/{{.Reponame}}/branches" class="button">ブランチ</a>
|
||||
<a href="/{{.Username}}/{{.Reponame}}/archive/{{.DefaultBranch}}.tar.gz" class="button">ダウンロード (tar.gz)</a>
|
||||
<a rel="noreferrer" href="https://github.com/{{.Username}}/{{.Reponame}}" class="button">GitHubで確認</a>
|
||||
</div>
|
||||
|
読み込み中…
新しいイシューから参照
ユーザーをブロックする