Get repo go import
This commit is contained in:
parent
d217b4d53b
commit
7ac73b86e1
@ -13,6 +13,7 @@ import (
|
|||||||
"html/template"
|
"html/template"
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
//go:embed pages/index.go.html
|
//go:embed pages/index.go.html
|
||||||
@ -83,7 +84,9 @@ func (m *Module) homepage(rw http.ResponseWriter, req *http.Request, state *util
|
|||||||
selOrg := ""
|
selOrg := ""
|
||||||
repoSimple := make([]struct{ Name string }, 0)
|
repoSimple := make([]struct{ Name string }, 0)
|
||||||
selRepo := ""
|
selRepo := ""
|
||||||
refSimple := make([]struct{ Name string }, 0)
|
selModule := ""
|
||||||
|
selCommitTime := ""
|
||||||
|
selCommitHash := ""
|
||||||
|
|
||||||
q := req.URL.Query()
|
q := req.URL.Query()
|
||||||
if q.Has("org") {
|
if q.Has("org") {
|
||||||
@ -100,14 +103,35 @@ func (m *Module) homepage(rw http.ResponseWriter, req *http.Request, state *util
|
|||||||
|
|
||||||
if q.Has("repo") {
|
if q.Has("repo") {
|
||||||
selRepo = q.Get("repo")
|
selRepo = q.Get("repo")
|
||||||
refs, _, err := giteaClient.GetRepoRefs(selOrg, selRepo, "heads")
|
repo, _, err := giteaClient.GetRepo(selOrg, selRepo)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
http.Error(rw, err.Error(), http.StatusInternalServerError)
|
http.Error(rw, err.Error(), http.StatusInternalServerError)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
refSimple = make([]struct{ Name string }, len(refs))
|
refs, _, err := giteaClient.GetRepoRefs(selOrg, selRepo, "heads/"+repo.DefaultBranch)
|
||||||
for i, ref := range refs {
|
if err != nil {
|
||||||
refSimple[i] = struct{ Name string }{Name: ref.Ref}
|
http.Error(rw, err.Error(), http.StatusInternalServerError)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if len(refs) == 1 {
|
||||||
|
ref := refs[0]
|
||||||
|
commit, _, err := giteaClient.GetSingleCommit(selOrg, selRepo, ref.Object.SHA)
|
||||||
|
if err != nil {
|
||||||
|
http.Error(rw, err.Error(), http.StatusInternalServerError)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
selCommitTime = commit.CommitMeta.Created.Format("20060102150405")
|
||||||
|
selCommitHash = commit.CommitMeta.SHA[:12]
|
||||||
|
goMod, _, err := giteaClient.GetFile(selOrg, selRepo, ref.Object.SHA, "go.mod")
|
||||||
|
if err != nil {
|
||||||
|
http.Error(rw, err.Error(), http.StatusInternalServerError)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
goModStr := string(goMod)
|
||||||
|
goModIdx := strings.Index(goModStr, "\n")
|
||||||
|
goModLine := goModStr[:goModIdx]
|
||||||
|
goModSpace := strings.Index(goModLine, " ")
|
||||||
|
selModule = goModLine[goModSpace+1:]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -118,21 +142,25 @@ func (m *Module) homepage(rw http.ResponseWriter, req *http.Request, state *util
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
err = tmp.Execute(rw, struct {
|
err = tmp.Execute(rw, struct {
|
||||||
Username string
|
Username string
|
||||||
Orgs []struct{ Name string }
|
Orgs []struct{ Name string }
|
||||||
Repos []struct{ Name string }
|
Repos []struct{ Name string }
|
||||||
SelOrg string
|
SelOrg string
|
||||||
ShowOrg bool
|
ShowOrg bool
|
||||||
SelRepo string
|
SelModule string
|
||||||
ShowRepo bool
|
ShowRepo bool
|
||||||
|
CommitTime string
|
||||||
|
CommitHash string
|
||||||
}{
|
}{
|
||||||
Username: myUser.UserName,
|
Username: myUser.UserName,
|
||||||
Orgs: orgSimple,
|
Orgs: orgSimple,
|
||||||
Repos: repoSimple,
|
Repos: repoSimple,
|
||||||
SelOrg: selOrg,
|
SelOrg: selOrg,
|
||||||
SelRepo: selRepo,
|
SelModule: selModule,
|
||||||
ShowOrg: selOrg != "",
|
ShowOrg: selOrg != "",
|
||||||
ShowRepo: selRepo != "",
|
ShowRepo: selModule != "",
|
||||||
|
CommitTime: selCommitTime,
|
||||||
|
CommitHash: selCommitHash,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println("Template execute error:", err)
|
fmt.Println("Template execute error:", err)
|
||||||
|
@ -41,7 +41,7 @@
|
|||||||
{{if .ShowRepo}}
|
{{if .ShowRepo}}
|
||||||
<div>
|
<div>
|
||||||
<p>Repository details:</p>
|
<p>Repository details:</p>
|
||||||
<p>Go import: go get {{.SelRepo.Full}}</p>
|
<p>Go import: go get {{.SelModule}}@v0.0.0-{{.CommitTime}}-{{.CommitHash}}</p>
|
||||||
</div>
|
</div>
|
||||||
{{end}}
|
{{end}}
|
||||||
</div>
|
</div>
|
||||||
|
Loading…
Reference in New Issue
Block a user