diff --git a/go.mod b/go.mod
index c995634..c133ee2 100644
--- a/go.mod
+++ b/go.mod
@@ -10,6 +10,7 @@ require (
github.com/gorilla/sessions v1.2.1
github.com/joho/godotenv v1.4.0
golang.org/x/oauth2 v0.0.0-20220309155454-6242fa91716a
+ gopkg.in/yaml.v3 v3.0.1
)
require (
diff --git a/go.sum b/go.sum
index d858c8c..3c3e0af 100644
--- a/go.sum
+++ b/go.sum
@@ -120,8 +120,10 @@ github.com/joho/godotenv v1.4.0/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwA
github.com/jstemmer/go-junit-report v0.0.0-20190106144839-af01ea7f8024/go.mod h1:6v2b51hI/fHJwM22ozAgKL4VKDeJcHhJFhtBdhmNjmU=
github.com/jstemmer/go-junit-report v0.9.1/go.mod h1:Brl9GWCQeLvo8nXZwPNNblvFj/XSXhF0NWZEnDohbsk=
github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck=
+github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI=
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
+github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
@@ -381,10 +383,13 @@ google.golang.org/protobuf v1.24.0/go.mod h1:r/3tXBNzIEhYS9I1OUVjXDlt8tc493IdKGj
google.golang.org/protobuf v1.25.0 h1:Ejskq+SyPohKW+1uil0JJMtmHCgJPJ/qWTxr8qp+R4c=
google.golang.org/protobuf v1.25.0/go.mod h1:9JNX74DMeImyA3h4bdi1ymwjUzf21/xIlbajtzgsN7c=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
+gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY=
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI=
gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw=
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
+gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
+gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
honnef.co/go/tools v0.0.0-20190106161140-3f1c8253044a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
honnef.co/go/tools v0.0.0-20190418001031-e561f6794a2a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
diff --git a/module/gitea/assets/assets.go b/module/gitea/assets/assets.go
new file mode 100644
index 0000000..5d101d2
--- /dev/null
+++ b/module/gitea/assets/assets.go
@@ -0,0 +1,6 @@
+package assets
+
+import "embed"
+
+//go:embed swagger
+var SwaggerAssets embed.FS
diff --git a/module/gitea/assets/swagger/swagger-initializer-custom.js b/module/gitea/assets/swagger/swagger-initializer-custom.js
new file mode 100644
index 0000000..c9d7723
--- /dev/null
+++ b/module/gitea/assets/swagger/swagger-initializer-custom.js
@@ -0,0 +1,21 @@
+window.onload = function() {
+ //
\n")
- _, _ = rw.Write(specFile)
- _, _ = fmt.Fprintf(rw, "\n
\n")
+
+ tmp, err := template.New("swagger").Parse(swaggerTemplate)
+ if err != nil {
+ fmt.Println("Template parse error:", err)
+ return
+ }
+ q2 := q
+ q2.Set("raw", "true")
+ err = tmp.Execute(rw, struct {
+ LoadUrls []struct {
+ Url string `json:"url"`
+ Name string `json:"name"`
+ }
+ LoadMain string
+ }{
+ LoadUrls: []struct {
+ Url string `json:"url"`
+ Name string `json:"name"`
+ }{
+ {Url: "/gitea/?" + q2.Encode(), Name: contents.Name},
+ },
+ LoadMain: contents.Name,
+ })
+ if err != nil {
+ fmt.Println("Template execute error:", err)
+ return
+ }
return
}
@@ -178,6 +256,9 @@ func (m *Module) homepage(rw http.ResponseWriter, req *http.Request, state *util
goModLine := goModStr[:goModIdx]
goModSpace := strings.Index(goModLine, " ")
selModule = goModLine[goModSpace+1:]
+ if resp.StatusCode == http.StatusNotFound {
+ selModule = ""
+ }
trees, resp, err := giteaClient.GetTrees(myOrg, selRepo, ref.Object.SHA, true)
if err != nil {
@@ -186,10 +267,31 @@ func (m *Module) homepage(rw http.ResponseWriter, req *http.Request, state *util
return
}
}
- for i := range trees.Entries {
- switch filepath.Ext(trees.Entries[i].Path) {
+ for _, i := range trees.Entries {
+ switch filepath.Ext(i.Path) {
case ".yml", ".yaml":
- mySpecs = append(mySpecs, trees.Entries[i].Path)
+ file, resp, err := giteaClient.GetFile(myOrg, selRepo, ref.Object.SHA, i.Path)
+ if err != nil {
+ switch resp.StatusCode {
+ case http.StatusForbidden, http.StatusUnauthorized, http.StatusNotFound:
+ mySpecs = append(mySpecs, struct {
+ Name string
+ Code int
+ }{Name: i.Path, Code: resp.StatusCode})
+ }
+ continue
+ }
+ a := struct {
+ OpenAPI string `yaml:"openapi"`
+ }{}
+ err = yaml.Unmarshal(file, &a)
+ if err != nil || a.OpenAPI == "" {
+ continue
+ }
+ mySpecs = append(mySpecs, struct {
+ Name string
+ Code int
+ }{Name: i.Path, Code: http.StatusOK})
}
}
}
@@ -213,11 +315,14 @@ func (m *Module) homepage(rw http.ResponseWriter, req *http.Request, state *util
SelRepo string
ShowOrg bool
SelModule string
- ShowRepo bool
+ ShowGoMod bool
CommitTime string
CommitHash string
ShowSpec bool
- Specs []string
+ Specs []struct {
+ Name string
+ Code int
+ }
}{
Username: myUser.UserName,
Orgs: orgSimple,
@@ -227,7 +332,7 @@ func (m *Module) homepage(rw http.ResponseWriter, req *http.Request, state *util
SelRepo: selRepo,
SelModule: selModule,
ShowOrg: myOrg != "",
- ShowRepo: selModule != "",
+ ShowGoMod: selModule != "",
CommitTime: selCommitTime,
CommitHash: selCommitHash,
ShowSpec: len(mySpecs) > 0,
diff --git a/module/gitea/pages/index.go.html b/module/gitea/pages/index.go.html
index 21e6d4b..28aebd2 100644
--- a/module/gitea/pages/index.go.html
+++ b/module/gitea/pages/index.go.html
@@ -54,24 +54,28 @@
{{end}}
- {{if .ShowRepo}}
- Repository details:
Go import: go get {{.SelModule}}@v0.0.0-{{.CommitTime}}-{{.CommitHash}}
-OpenAPI specs:
-OpenAPI specs:
+