Skip to content

Commit 5230359

Browse files
authored
Merge pull request #71 from pavelsne/iss56
"Back to GIN" link should be dynamic (#56) resolved
2 parents b28c8e8 + 85b5341 commit 5230359

File tree

5 files changed

+45
-9
lines changed

5 files changed

+45
-9
lines changed

internal/resources/templates/layout.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,10 @@ var Layout = `
2929
<div class="ui grid">
3030
<div class="column">
3131
<div class="ui top secondary menu">
32-
<a class="item brand" href="https://gin.g-node.org/">
32+
<a class="item brand" href="{{.GinURL}}">
3333
<img class="ui mini image" src="/assets/favicon.png">
3434
</a>
35-
<a class="item" href="https://gin.g-node.org/">Back to GIN</a>
35+
<a class="item" href="{{.GinURL}}">Back to GIN</a>
3636
<a class="item" href="/repos">Repositories</a>
3737
<a class="item" href="/pubvalidate">One-time validation</a>
3838
<a class="item" href="/login">Login</a>

internal/web/fail.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"html/template"
55
"net/http"
66

7+
"github.com/G-Node/gin-valid/internal/config"
78
"github.com/G-Node/gin-valid/internal/log"
89
"github.com/G-Node/gin-valid/internal/resources/templates"
910
)
@@ -26,14 +27,17 @@ func fail(w http.ResponseWriter, status int, message string) {
2627
w.Write([]byte(message))
2728
return
2829
}
30+
srvcfg := config.Read()
2931
errinfo := struct {
3032
StatusCode int
3133
StatusText string
3234
Message string
35+
GinURL string
3336
}{
3437
status,
3538
http.StatusText(status),
3639
message,
40+
srvcfg.GINAddresses.WebURL,
3741
}
3842
tmpl.Execute(w, &errinfo)
3943
}

internal/web/results.go

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -167,11 +167,13 @@ func renderInProgress(w http.ResponseWriter, r *http.Request, badge []byte, vali
167167

168168
// Parse results into html template and serve it
169169
head := fmt.Sprintf("%s validation for %s/%s", validator, user, repo)
170+
srvcfg := config.Read()
170171
info := struct {
171172
Badge template.HTML
172173
Header string
173174
Content string
174-
}{template.HTML(badge), head, string(progressmsg)}
175+
GinURL string
176+
}{template.HTML(badge), head, string(progressmsg), srvcfg.GINAddresses.WebURL}
175177

176178
err = tmpl.ExecuteTemplate(w, "layout", info)
177179
if err != nil {
@@ -208,11 +210,13 @@ func renderBIDSResults(w http.ResponseWriter, r *http.Request, badge []byte, con
208210

209211
// Parse results into html template and serve it
210212
head := fmt.Sprintf("BIDS validation for %s/%s", user, repo)
213+
srvcfg := config.Read()
211214
info := struct {
212215
Badge template.HTML
213216
Header string
214217
*BidsResultStruct
215-
}{template.HTML(badge), head, &resBIDS}
218+
GinURL string
219+
}{template.HTML(badge), head, &resBIDS, srvcfg.GINAddresses.WebURL}
216220

217221
err = tmpl.ExecuteTemplate(w, "layout", info)
218222
if err != nil {
@@ -241,11 +245,13 @@ func renderNIXResults(w http.ResponseWriter, r *http.Request, badge []byte, cont
241245

242246
// Parse results into html template and serve it
243247
head := fmt.Sprintf("NIX validation for %s/%s", user, repo)
248+
srvcfg := config.Read()
244249
info := struct {
245250
Badge template.HTML
246251
Header string
247252
Content string
248-
}{template.HTML(badge), head, string(content)}
253+
GinURL string
254+
}{template.HTML(badge), head, string(content), srvcfg.GINAddresses.WebURL}
249255

250256
err = tmpl.ExecuteTemplate(w, "layout", info)
251257
if err != nil {
@@ -274,11 +280,13 @@ func renderODMLResults(w http.ResponseWriter, r *http.Request, badge []byte, con
274280

275281
// Parse results into html template and serve it
276282
head := fmt.Sprintf("odML validation for %s/%s", user, repo)
283+
srvcfg := config.Read()
277284
info := struct {
278285
Badge template.HTML
279286
Header string
280287
Content string
281-
}{template.HTML(badge), head, string(content)}
288+
GinURL string
289+
}{template.HTML(badge), head, string(content), srvcfg.GINAddresses.WebURL}
282290

283291
err = tmpl.ExecuteTemplate(w, "layout", info)
284292
if err != nil {

internal/web/user.go

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,13 @@ func LoginGet(w http.ResponseWriter, r *http.Request) {
167167
fail(w, http.StatusInternalServerError, "something went wrong")
168168
return
169169
}
170-
tmpl.Execute(w, nil)
170+
srvcfg := config.Read()
171+
data := struct {
172+
GinURL string
173+
}{
174+
srvcfg.GINAddresses.WebURL,
175+
}
176+
tmpl.Execute(w, &data)
171177
}
172178

173179
// LoginPost logs in the user to the GIN server, storing a session token.
@@ -291,12 +297,15 @@ func ListRepos(w http.ResponseWriter, r *http.Request) {
291297
reposInactive = append(reposInactive, rhinfo)
292298
}
293299
}
300+
srvcfg := config.Read()
294301
allrepos := struct {
295302
Active []repoHooksInfo
296303
Inactive []repoHooksInfo
304+
GinURL string
297305
}{
298306
reposActive,
299307
reposInactive,
308+
srvcfg.GINAddresses.WebURL,
300309
}
301310
tmpl.Execute(w, &allrepos)
302311
}
@@ -446,6 +455,15 @@ func ShowRepo(w http.ResponseWriter, r *http.Request) {
446455
if err != nil {
447456
hooks = make(map[string]ginhook)
448457
}
449-
repohi := repoHooksInfo{repoinfo, hooks}
458+
srvcfg := config.Read()
459+
repohi := struct {
460+
gogs.Repository
461+
Hooks map[string]ginhook
462+
GinURL string
463+
}{
464+
repoinfo,
465+
hooks,
466+
srvcfg.GINAddresses.WebURL,
467+
}
450468
tmpl.Execute(w, &repohi)
451469
}

internal/web/validate.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -619,7 +619,13 @@ func PubValidateGet(w http.ResponseWriter, r *http.Request) {
619619
fail(w, http.StatusInternalServerError, "something went wrong")
620620
return
621621
}
622-
tmpl.Execute(w, nil)
622+
srvcfg := config.Read()
623+
data := struct {
624+
GinURL string
625+
}{
626+
srvcfg.GINAddresses.WebURL,
627+
}
628+
tmpl.Execute(w, &data)
623629
}
624630

625631
// PubValidatePost parses the POST data from the root form and calls the

0 commit comments

Comments
 (0)