mirror of
https://github.com/gojp/goreportcard.git
synced 2026-01-29 06:49:05 +08:00
Merge pull request #345 from gojp/handle-errors-better
Better handling for process failures (Closes #339)
This commit is contained in:
@@ -101,7 +101,13 @@
|
||||
<script id="template-grade" type="text/x-handlebars-template">
|
||||
<div class="column">
|
||||
<h1 class="title">Report for {{#if link}}<a href="{{ link }}">{{/if}}<strong>{{repo}}</strong>{{#if link}}</a>{{/if}}</h1>
|
||||
<p><span class="huge">{{grade}}</span> {{gradeMessage grade}}    Found <strong>{{issues}}</strong> issues across <strong>{{files}}</strong> files</p>
|
||||
<p>
|
||||
{{#if did_error}}
|
||||
<span>An error occurred while generating the report.</span>    Found <strong>{{issues}}</strong> issues across <strong>{{files}}</strong> files</p>
|
||||
{{else}}
|
||||
<span class="huge">{{grade}}</span> {{gradeMessage grade}}    Found <strong>{{issues}}</strong> issues across <strong>{{files}}</strong> files
|
||||
{{/if}}
|
||||
</p>
|
||||
</div>
|
||||
<div class="column is-one-quarter badge-col">
|
||||
<img class="badge" tag="{{repo}}" src="/badge/{{repo}}"/>
|
||||
|
||||
@@ -29,11 +29,12 @@ type Score struct {
|
||||
|
||||
// ChecksResult represents the combined result of multiple checks
|
||||
type ChecksResult struct {
|
||||
Checks []Score `json:"checks"`
|
||||
Average float64 `json:"average"`
|
||||
Grade Grade `json:"GradeFromPercentage"`
|
||||
Files int `json:"files"`
|
||||
Issues int `json:"issues"`
|
||||
Checks []Score `json:"checks"`
|
||||
Average float64 `json:"average"`
|
||||
Grade Grade `json:"GradeFromPercentage"`
|
||||
Files int `json:"files"`
|
||||
Issues int `json:"issues"`
|
||||
DidError bool `json:"did_error"`
|
||||
}
|
||||
|
||||
// Run executes all checks on the given directory
|
||||
@@ -98,6 +99,9 @@ func Run(dir string) (ChecksResult, error) {
|
||||
for _, fs := range s.FileSummaries {
|
||||
issues[fs.Filename] = true
|
||||
}
|
||||
if s.Error != "" {
|
||||
resp.DidError = true
|
||||
}
|
||||
}
|
||||
total /= totalWeight
|
||||
|
||||
|
||||
@@ -19,7 +19,7 @@ func BadgeHandler(w http.ResponseWriter, r *http.Request, db *badger.DB, repo st
|
||||
style = "flat"
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
if err != nil || resp.DidError {
|
||||
log.Printf("ERROR: fetching badge for %s: %v", repo, err)
|
||||
url := "https://img.shields.io/badge/go%20report-error-lightgrey.svg?style=" + style
|
||||
http.Redirect(w, r, url, http.StatusTemporaryRedirect)
|
||||
|
||||
@@ -6,8 +6,8 @@ import (
|
||||
"log"
|
||||
"time"
|
||||
|
||||
"github.com/dgraph-io/badger/v2"
|
||||
"github.com/dustin/go-humanize"
|
||||
badger "github.com/dgraph-io/badger/v2"
|
||||
humanize "github.com/dustin/go-humanize"
|
||||
"github.com/gojp/goreportcard/check"
|
||||
"github.com/gojp/goreportcard/download"
|
||||
)
|
||||
@@ -74,6 +74,7 @@ type checksResp struct {
|
||||
LastRefresh time.Time `json:"last_refresh"`
|
||||
LastRefreshFormatted string `json:"formatted_last_refresh"`
|
||||
LastRefreshHumanized string `json:"humanized_last_refresh"`
|
||||
DidError bool `json:"did_error"`
|
||||
}
|
||||
|
||||
func newChecksResp(db *badger.DB, repo string, forceRefresh bool) (checksResp, error) {
|
||||
@@ -112,6 +113,7 @@ func newChecksResp(db *badger.DB, repo string, forceRefresh bool) (checksResp, e
|
||||
LastRefresh: t,
|
||||
LastRefreshFormatted: t.Format(time.UnixDate),
|
||||
LastRefreshHumanized: humanize.Time(t),
|
||||
DidError: checkResult.DidError,
|
||||
}
|
||||
|
||||
respBytes, err := json.Marshal(resp)
|
||||
|
||||
Reference in New Issue
Block a user