display module version in report

This commit is contained in:
Shawn Smith
2021-11-14 11:08:38 +09:00
parent dd5ab00b38
commit dace0fa8d2
3 changed files with 15 additions and 13 deletions

View File

@@ -100,7 +100,7 @@
</script>
<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>
<h1 class="title">Report for {{#if link}}<a href="{{ link }}">{{/if}}<strong>{{repo}} {{#if version}}({{version}}){{/if}}</strong>{{#if link}}</a>{{/if}}</h1>
<p>
{{#if did_error}}
<span>An error occurred while generating the report.</span> &emsp;&emsp; Found <strong>{{issues}}</strong> issues across <strong>{{files}}</strong> files</p>

View File

@@ -21,10 +21,10 @@ type moduleVersion struct {
}
// ProxyDownload downloads a package from proxy.golang.org
func ProxyDownload(path string) error {
func ProxyDownload(path string) (string, error) {
resp, err := http.Get(fmt.Sprintf(proxyLatestURL, path))
if err != nil {
return err
return "", err
}
defer resp.Body.Close()
@@ -33,48 +33,48 @@ func ProxyDownload(path string) error {
err = json.NewDecoder(resp.Body).Decode(&mv)
if err != nil {
return err
return "", err
}
resp, err = http.Get(fmt.Sprintf(proxyZipURL, path, mv.Version))
if err != nil {
return err
return "", err
}
defer resp.Body.Close()
if resp.StatusCode != 200 {
return fmt.Errorf("status %d", resp.StatusCode)
return "", fmt.Errorf("status %d", resp.StatusCode)
}
zipPath := filepath.Base(path) + "@" + mv.Version + ".zip"
out, err := os.Create(filepath.Join(reposDir, zipPath))
if err != nil {
return err
return "", err
}
defer out.Close()
_, err = io.Copy(out, resp.Body)
if err != nil {
return err
return "", err
}
err = os.RemoveAll(filepath.Join(reposDir, path))
if err != nil {
return err
return "", err
}
cmd := exec.Command("unzip", "-o", filepath.Join(reposDir, zipPath), "-d", reposDir)
err = cmd.Run()
if err != nil {
return err
return "", err
}
err = os.RemoveAll(filepath.Join(reposDir, zipPath))
if err != nil {
return err
return "", err
}
return os.Rename(filepath.Join(reposDir, path+"@"+mv.Version), filepath.Join(reposDir, path))
return mv.Version, os.Rename(filepath.Join(reposDir, path+"@"+mv.Version), filepath.Join(reposDir, path))
}

View File

@@ -70,6 +70,7 @@ type checksResp struct {
Files int `json:"files"`
Issues int `json:"issues"`
Repo string `json:"repo"`
Version string `json:"version"`
ResolvedRepo string `json:"resolvedRepo"`
LastRefresh time.Time `json:"last_refresh"`
LastRefreshFormatted string `json:"formatted_last_refresh"`
@@ -95,7 +96,7 @@ func newChecksResp(db *badger.DB, repo string, forceRefresh bool) (checksResp, e
// return checksResp{}, fmt.Errorf("could not clone repo: %v", err)
//}
err := download.ProxyDownload(repo)
ver, err := download.ProxyDownload(repo)
if err != nil {
fmt.Println("ERROR:", err)
}
@@ -114,6 +115,7 @@ func newChecksResp(db *badger.DB, repo string, forceRefresh bool) (checksResp, e
Files: checkResult.Files,
Issues: checkResult.Issues,
Repo: repo,
Version: ver,
ResolvedRepo: repo,
LastRefresh: t,
LastRefreshFormatted: t.Format(time.UnixDate),