a71de7e9879163066a28396f6780e3e533c2efc9

Author
TheEdgeOfRage <git@theedgeofrage.com>
Committer
TheEdgeOfRage <git@theedgeofrage.com>
Date

Message

List build status only for projects that have one

Diff

This diff is truncated to protect this page.

  1diff --git a/pkg/web/build_status_test.go b/pkg/web/build_status_test.go
  2index 49d8451bffdeb672bb1c01f61b58a9d1c17d0510..248072b5c12738e0ffdd32f6a2fe9f4d3d7b0bd0 100644
  3--- a/pkg/web/build_status_test.go
  4+++ b/pkg/web/build_status_test.go
  5@@ -71,11 +71,14 @@ func TestHomepageRendersBuildStatusesOnlyForVisiblePublicRepositories(t *testing
  6 	if response.Code != http.StatusOK {
  7 		t.Fatalf("homepage = %d: %s", response.Code, response.Body.String())
  8 	}
  9-	for _, label := range []string{"Queued", "Building", "Passed", "Failed", "No build"} {
 10-		if !strings.Contains(response.Body.String(), "Build status: <span") || !strings.Contains(response.Body.String(), ">"+label+"</span>") {
 11+	for _, label := range []string{"Queued", "Building", "Passed", "Failed"} {
 12+		if !strings.Contains(response.Body.String(), "Build: <span") || !strings.Contains(response.Body.String(), ">"+label+"</span>") {
 13 			t.Errorf("homepage did not render %q: %s", label, response.Body.String())
 14 		}
 15 	}
 16+	if strings.Contains(response.Body.String(), "No build") {
 17+		t.Errorf("homepage rendered a missing build status: %s", response.Body.String())
 18+	}
 19 	sort.Strings(requested)
 20 	if got, want := strings.Join(requested, ","), "failed,missing,passed,queued,running"; got != want {
 21 		t.Errorf("worker status requested repositories = %q, want %q", got, want)
 22@@ -138,7 +141,6 @@ func TestRepositoryOverviewRendersBuildStatusAndChecksAccessBeforeWorker(t *test
 23 		{"status-running", "Building"},
 24 		{"status-passed", "Passed"},
 25 		{"status-failed", "Failed"},
 26-		{"no-build", "No build"},
 27 	} {
 28 		response := httptest.NewRecorder()
 29 		router.ServeHTTP(response, httptest.NewRequest(http.MethodGet, "/"+test.repository, nil))
 30@@ -146,6 +148,12 @@ func TestRepositoryOverviewRendersBuildStatusAndChecksAccessBeforeWorker(t *test
 31 			t.Errorf("overview %s = %d: %s", test.repository, response.Code, response.Body.String())
 32 		}
 33 	}
 34+
 35+	response := httptest.NewRecorder()
 36+	router.ServeHTTP(response, httptest.NewRequest(http.MethodGet, "/no-build", nil))
 37+	if response.Code != http.StatusOK || strings.Contains(response.Body.String(), "status-badge") {
 38+		t.Errorf("overview without a build status = %d: %s", response.Code, response.Body.String())
 39+	}
 40 }
 41 
 42 func TestRepositoryOverviewBuildStatusFailureDoesNotFailPage(t *testing.T) {
 43@@ -164,7 +172,7 @@ func TestRepositoryOverviewBuildStatusFailureDoesNotFailPage(t *testing.T) {
 44 
 45 	response := httptest.NewRecorder()
 46 	NewRouter(ctx).ServeHTTP(response, httptest.NewRequest(http.MethodGet, "/public", nil))
 47-	if response.Code != http.StatusOK || !strings.Contains(response.Body.String(), ">Build status unavailable</span>") {
 48+	if response.Code != http.StatusOK || strings.Contains(response.Body.String(), "status-badge") {
 49 		t.Fatalf("overview = %d: %s", response.Code, response.Body.String())
 50 	}
 51 }
 52diff --git a/pkg/web/pages/status.go b/pkg/web/pages/status.go
 53index f1f7603c1a615051e21a1f4236052445954883b7..5e4bcc2efedd33d9f27621a5225acb9bb5513ddf 100644
 54--- a/pkg/web/pages/status.go
 55+++ b/pkg/web/pages/status.go
 56@@ -18,8 +18,9 @@ const (
 57 var buildStatusHTTPClient = &http.Client{Timeout: 2 * time.Second}
 58 
 59 type repositoryBuildStatus struct {
 60-	Label string
 61-	Class string
 62+	Label   string
 63+	Class   string
 64+	Present bool
 65 }
 66 
 67 type workerBuildStatusRequest struct {
 68@@ -132,24 +133,24 @@ func ensureNoAdditionalJSON(decoder *json.Decoder) error {
 69 func buildStatusBadge(state string) (repositoryBuildStatus, bool) {
 70 	switch state {
 71 	case "queued":
 72-		return repositoryBuildStatus{Label: "Queued", Class: "build-status-queued"}, true
 73+		return repositoryBuildStatus{Label: "Queued", Class: "build-status-queued", Present: true}, true
 74 	case "running":
 75-		return repositoryBuildStatus{Label: "Building", Class: "build-status-running"}, true
 76+		return repositoryBuildStatus{Label: "Building", Class: "build-status-running", Present: true}, true
 77 	case "passed":
 78-		return repositoryBuildStatus{Label: "Passed", Class: "build-status-passed"}, true
 79+		return repositoryBuildStatus{Label: "Passed", Class: "build-status-passed", Present: true}, true
 80 	case "failed":
 81-		return repositoryBuildStatus{Label: "Failed", Class: "build-status-failed"}, true
 82+		return repositoryBuildStatus{Label: "Failed", Class: "build-status-failed", Present: true}, true
 83 	default:
 84 		return repositoryBuildStatus{}, false
 85 	}
 86 }
 87 
 88 func noBuildStatus() repositoryBuildStatus {
 89-	return repositoryBuildStatus{Label: "No build", Class: "build-status-none"}
 90+	return repositoryBuildStatus{}
 91 }
 92 
 93 func markBuildStatusUnavailable(statuses map[string]repositoryBuildStatus, repositories []string) {
 94 	for _, repository := range repositories {
 95-		statuses[repository] = repositoryBuildStatus{Label: "Build status unavailable", Class: "build-status-unavailable"}
 96+		statuses[repository] = repositoryBuildStatus{}
 97 	}
 98 }
 99diff --git a/pkg/web/pages/templates/home.gohtml b/pkg/web/pages/templates/home.gohtml
100index 5ce4f3ce2504c16d9186d92bd961679f24592a72..040c6a5b3dd1c4795709b6fdcf9a7c5938f05e43 100644
101--- a/pkg/web/pages/templates/home.gohtml
102+++ b/pkg/web/pages/templates/home.gohtml
103@@ -43,7 +43,7 @@
104             {{ if .Description }}<p class="repository-description">{{ .Description }}</p>{{ end }}
105           </div>
106           <div class="repository-card-meta">
107-            <span class="build-status">Build status: <span class="status-badge {{ .BuildStatus.Class }}">{{ .BuildStatus.Label }}</span></span>
108+            {{ if .BuildStatus.Present }}<span class="build-status">Build: <span class="status-badge {{ .BuildStatus.Class }}">{{ .BuildStatus.Label }}</span></span>{{ end }}
109             {{ if .UpdatedAt }}<time class="updated">Updated {{ .UpdatedAt }}</time>{{ end }}
110           </div>
111         </a>
112diff --git a/pkg/web/pages/templates/repository.gohtml b/pkg/web/pages/templates/repository.gohtml
113index 1a0f733fd7066088519fd9e74ded1236e4e96699..eec6440498287b7377e3362732855262365085ed 100644
114--- a/pkg/web/pages/templates/repository.gohtml
115+++ b/pkg/web/pages/templates/repository.gohtml
116@@ -15,7 +15,7 @@
117         <h1>{{ .Title }}</h1>
118         {{ if ne .Title .Repository }}<p class="repository-name">{{ .Repository }}</p>{{ end }}
119         {{ if .Description }}<p class="repository-description">{{ .Description }}</p>{{ end }}
120-        <div class="repository-meta"><span class="status-badge {{ .BuildStatus.Class }}">{{ .BuildStatus.Label }}</span>{{ if not .Empty }}<span>Default ref <code>{{ .Ref }}</code></span>{{ end }}</div>