Skip to content

Commit 8655912

Browse files
committed
[results.go ...] Provide page on missing validation results
Closes #73 "Currently when a logged in user views the validator listing page for a specific repository and there are no results for a specific validator yet, the "Results" link for this validator will lead to a blank page with only the text "404 Nothing to see here ...". Provide a full page including header and footer, an appropriate information text and a link back to the results overview page of the repository." The page provides two links back to the original page as well as to one-time validation page.
1 parent 4f4704e commit 8655912

File tree

3 files changed

+85
-5
lines changed

3 files changed

+85
-5
lines changed
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package templates
2+
3+
// NotValidatedYet is a template that requires a header text, a badge, a
4+
// content and two links. The content is displayed in a <pre> block.
5+
const NotValidatedYet = `
6+
{{define "content"}}
7+
<div class="repository file list">
8+
<div class="header-wrapper">
9+
<div class="ui container">
10+
<div class="ui vertically padded grid head">
11+
<div class="column">
12+
<div class="ui header">
13+
<div class="ui huge breadcrumb">
14+
<i class="mega-octicon octicon-repo"></i>
15+
{{.Header}}
16+
{{.Badge}}
17+
</div>
18+
</div>
19+
</div>
20+
</div>
21+
</div>
22+
<div class="ui tabs container">
23+
</div>
24+
<div class="ui tabs divider"></div>
25+
</div>
26+
<div class="ui container">
27+
<hr>
28+
<div>
29+
<pre>{{.Content}}</pre>
30+
<a href="{{.HrefURL1}}" alt="{{.HrefAlt1}}">{{.HrefText1}}</a> |
31+
<a href="{{.HrefURL2}}" alt="{{.HrefAlt2}}">{{.HrefText2}}</a>
32+
</div>
33+
</div>
34+
</div>
35+
{{end}}
36+
`

internal/web/pkg.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ and disabling hooks on the GIN server running the validation.
66
package web
77

88
const (
9-
serveralias = "gin"
10-
progressmsg = "A validation job for this repository is currently in progress, please do not leave this page and refresh the page after a while."
9+
serveralias = "gin"
10+
progressmsg = "A validation job for this repository is currently in progress, please do not leave this page and refresh the page after a while."
11+
notvalidatedyet = "This repository has not been validated yet. To see the results, update the repository."
1112
)

internal/web/results.go

Lines changed: 46 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -149,8 +149,7 @@ func Results(w http.ResponseWriter, r *http.Request) {
149149
fp = filepath.Join(resdir, srvcfg.Label.ResultsFile)
150150
content, err := ioutil.ReadFile(fp)
151151
if err != nil {
152-
log.ShowWrite("[Error] serving '%s/%s' result: %s\n", user, repo, err.Error())
153-
http.ServeContent(w, r, "unavailable", time.Now(), bytes.NewReader([]byte("404 Nothing to see here...")))
152+
notValidatedYet(w, r, badge, strings.ToUpper(validator), user, repo)
154153
return
155154
}
156155

@@ -174,7 +173,51 @@ func Results(w http.ResponseWriter, r *http.Request) {
174173
return
175174
}
176175

177-
func renderInProgress(w http.ResponseWriter, r *http.Request, badge []byte, validator string, user, repo string) {
176+
func notValidatedYet(w http.ResponseWriter, r *http.Request, badge []byte, validator, user, repo string) {
177+
tmpl := template.New("layout")
178+
tmpl, err := tmpl.Parse(templates.Layout)
179+
if err != nil {
180+
log.ShowWrite("[Error] '%s/%s' result: %s\n", user, repo, err.Error())
181+
http.ServeContent(w, r, "unavailable", time.Now(), bytes.NewReader([]byte("500 Something went wrong...")))
182+
return
183+
}
184+
tmpl, err = tmpl.Parse(templates.NotValidatedYet)
185+
if err != nil {
186+
log.ShowWrite("[Error] '%s/%s' result: %s\n", user, repo, err.Error())
187+
http.ServeContent(w, r, "unavailable", time.Now(), bytes.NewReader([]byte("500 Something went wrong...")))
188+
return
189+
}
190+
191+
// Parse results into html template and serve it
192+
head := fmt.Sprintf("%s validation for %s/%s", validator, user, repo)
193+
srvcfg := config.Read()
194+
year, _, _ := time.Now().Date()
195+
info := struct {
196+
Badge template.HTML
197+
Header string
198+
Content string
199+
GinURL string
200+
CurrentYear int
201+
HrefURL1 string
202+
HrefAlt1 string
203+
HrefText1 string
204+
HrefURL2 string
205+
HrefAlt2 string
206+
HrefText2 string
207+
}{template.HTML(badge), head, string(notvalidatedyet), srvcfg.GINAddresses.WebURL, year,
208+
"/pubvalidate", "Validate now", "Validate this repository right now",
209+
filepath.Join("/repos", user, repo, "hooks"), "Go Back", "Go back to repository information page",
210+
}
211+
212+
err = tmpl.ExecuteTemplate(w, "layout", info)
213+
if err != nil {
214+
log.ShowWrite("[Error] '%s/%s' result: %s\n", user, repo, err.Error())
215+
http.ServeContent(w, r, "unavailable", time.Now(), bytes.NewReader([]byte("500 Something went wrong...")))
216+
return
217+
}
218+
}
219+
220+
func renderInProgress(w http.ResponseWriter, r *http.Request, badge []byte, validator, user, repo string) {
178221
tmpl := template.New("layout")
179222
tmpl, err := tmpl.Parse(templates.Layout)
180223
if err != nil {

0 commit comments

Comments
 (0)