Add myOrg to store username or org name
This commit is contained in:
parent
ccf4318310
commit
d0c7561530
@ -85,6 +85,7 @@ func (m *Module) homepage(rw http.ResponseWriter, req *http.Request, state *util
|
||||
orgSimple[i] = struct{ Name string }{j.UserName}
|
||||
}
|
||||
selOrg := ""
|
||||
myOrg := ""
|
||||
repoSimple := make([]struct{ Name string }, 0)
|
||||
selRepo := ""
|
||||
selModule := ""
|
||||
@ -95,10 +96,12 @@ func (m *Module) homepage(rw http.ResponseWriter, req *http.Request, state *util
|
||||
if q.Has("org") {
|
||||
selOrg = q.Get("org")
|
||||
var repos []*gitea.Repository
|
||||
if selOrg == "@me" {
|
||||
if selOrg == "$me" {
|
||||
myOrg = myUser.UserName
|
||||
repos, _, err = giteaClient.ListMyRepos(gitea.ListReposOptions{ListOptions: gitea.ListOptions{Page: 0, PageSize: 100}})
|
||||
} else {
|
||||
repos, _, err = giteaClient.ListOrgRepos(selOrg, gitea.ListOrgReposOptions{ListOptions: gitea.ListOptions{Page: 0, PageSize: 100}})
|
||||
myOrg = selOrg
|
||||
repos, _, err = giteaClient.ListOrgRepos(myOrg, gitea.ListOrgReposOptions{ListOptions: gitea.ListOptions{Page: 0, PageSize: 100}})
|
||||
}
|
||||
if err != nil {
|
||||
http.Error(rw, err.Error(), http.StatusInternalServerError)
|
||||
@ -111,26 +114,26 @@ func (m *Module) homepage(rw http.ResponseWriter, req *http.Request, state *util
|
||||
|
||||
if q.Has("repo") {
|
||||
selRepo = q.Get("repo")
|
||||
repo, _, err := giteaClient.GetRepo(selOrg, selRepo)
|
||||
repo, _, err := giteaClient.GetRepo(myOrg, selRepo)
|
||||
if err != nil {
|
||||
http.Error(rw, err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
refs, _, err := giteaClient.GetRepoRefs(selOrg, selRepo, "heads/"+repo.DefaultBranch)
|
||||
refs, _, err := giteaClient.GetRepoRefs(myOrg, selRepo, "heads/"+repo.DefaultBranch)
|
||||
if err != nil {
|
||||
http.Error(rw, err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
if len(refs) == 1 {
|
||||
ref := refs[0]
|
||||
commit, _, err := giteaClient.GetSingleCommit(selOrg, selRepo, ref.Object.SHA)
|
||||
commit, _, err := giteaClient.GetSingleCommit(myOrg, selRepo, ref.Object.SHA)
|
||||
if err != nil {
|
||||
http.Error(rw, err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
selCommitTime = commit.CommitMeta.Created.UTC().Format("20060102150405")
|
||||
selCommitHash = commit.CommitMeta.SHA[:12]
|
||||
goMod, _, err := giteaClient.GetFile(selOrg, selRepo, ref.Object.SHA, "go.mod")
|
||||
goMod, _, err := giteaClient.GetFile(myOrg, selRepo, ref.Object.SHA, "go.mod")
|
||||
if err != nil {
|
||||
http.Error(rw, err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
@ -153,6 +156,7 @@ func (m *Module) homepage(rw http.ResponseWriter, req *http.Request, state *util
|
||||
Username string
|
||||
Orgs []struct{ Name string }
|
||||
Repos []struct{ Name string }
|
||||
MyOrg string
|
||||
SelOrg string
|
||||
ShowOrg bool
|
||||
SelModule string
|
||||
@ -163,9 +167,10 @@ func (m *Module) homepage(rw http.ResponseWriter, req *http.Request, state *util
|
||||
Username: myUser.UserName,
|
||||
Orgs: orgSimple,
|
||||
Repos: repoSimple,
|
||||
MyOrg: myOrg,
|
||||
SelOrg: selOrg,
|
||||
SelModule: selModule,
|
||||
ShowOrg: selOrg != "",
|
||||
ShowOrg: myOrg != "",
|
||||
ShowRepo: selModule != "",
|
||||
CommitTime: selCommitTime,
|
||||
CommitHash: selCommitHash,
|
||||
|
@ -28,7 +28,7 @@
|
||||
<p>Select repository source:</p>
|
||||
<ul>
|
||||
<li>
|
||||
<a href="?org=@me">{{.Username}} (my user account)</a>
|
||||
<a href="?org=$me">{{.Username}} (my user account)</a>
|
||||
</li>
|
||||
{{range .Orgs}}
|
||||
<li>
|
||||
@ -43,7 +43,7 @@
|
||||
<ul>
|
||||
{{range .Repos}}
|
||||
<li>
|
||||
<a href="?org={{$.SelOrg}}&repo={{.Name}}">{{$.SelOrg}}/{{.Name}}</a>
|
||||
<a href="?org={{$.MyOrg}}&repo={{.Name}}">{{$.SelOrg}}/{{.Name}}</a>
|
||||
</li>
|
||||
{{end}}
|
||||
</ul>
|
||||
|
Loading…
Reference in New Issue
Block a user