Skip to content

Commit 40527c1

Browse files
committed
[validate.go] Refactored invalid repository result page into message
Closes #66 Instead of error page will be displayed error message on the same screen.
1 parent 57eae87 commit 40527c1

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

internal/resources/templates/pubvalidate.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ var PubValidate = `
88
Enter the full name of a GIN repository (user/repository) below and select a validator to run:
99
</h4>
1010
<div class="ui attached segment">
11+
{{ if .ErrorMessage }}
12+
<div class="ui message red">{{ .ErrorMessage }}</div>
13+
{{ end }}
1114
<div class="required inline field left">
1215
<label for="repopath">Repository name</label>
1316
<input id="repopath" name="repopath" value="" autofocus required>

internal/web/validate.go

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -505,6 +505,13 @@ func Root(w http.ResponseWriter, r *http.Request) {
505505
// to manually run a validator on a publicly accessible repository, without
506506
// using a web hook.
507507
func PubValidateGet(w http.ResponseWriter, r *http.Request) {
508+
renderValidationForm(w, r, "")
509+
}
510+
511+
// renderValidationForm renders the one-time validation form, which allows the user
512+
// to manually run a validator on a publicly accessible repository, without
513+
// using a web hook.
514+
func renderValidationForm(w http.ResponseWriter, r *http.Request, errMsg string) {
508515
tmpl := template.New("layout")
509516
tmpl, err := tmpl.Parse(templates.Layout)
510517
if err != nil {
@@ -521,11 +528,13 @@ func PubValidateGet(w http.ResponseWriter, r *http.Request) {
521528
year, _, _ := time.Now().Date()
522529
srvcfg := config.Read()
523530
data := struct {
524-
GinURL string
525-
CurrentYear int
531+
GinURL string
532+
CurrentYear int
533+
ErrorMessage string
526534
}{
527535
srvcfg.GINAddresses.WebURL,
528536
year,
537+
errMsg,
529538
}
530539
tmpl.Execute(w, &data)
531540
}
@@ -560,7 +569,7 @@ func PubValidatePost(w http.ResponseWriter, r *http.Request) {
560569
// check if repository is accessible
561570
repoinfo, err := gcl.GetRepo(repopath)
562571
if err != nil {
563-
fail(w, http.StatusNotFound, err.Error())
572+
renderValidationForm(w, r, fmt.Sprintf("Repository '%s' does not exist.", repopath))
564573
return
565574
}
566575
if repoinfo.Private {

0 commit comments

Comments
 (0)