From 4fd77fb2b6cce8ee5e395e9d6cfccccffb7ee150 Mon Sep 17 00:00:00 2001 From: Martin Tournoij Date: Thu, 27 Oct 2016 20:26:49 +0100 Subject: [PATCH] Follow redirects for "vanity imports" e.g. if you have: then the repo isn't linked; this fixes that by using the resolved destination, rather than the path the user entered. --- handlers/checks.go | 2 ++ templates/report.html | 7 ++++--- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/handlers/checks.go b/handlers/checks.go index 04185f1..97469d1 100644 --- a/handlers/checks.go +++ b/handlers/checks.go @@ -70,6 +70,7 @@ type checksResp struct { Files int `json:"files"` Issues int `json:"issues"` Repo string `json:"repo"` + ResolvedRepo string `json:"resolvedRepo"` LastRefresh time.Time `json:"last_refresh"` HumanizedLastRefresh string `json:"humanized_last_refresh"` } @@ -143,6 +144,7 @@ func newChecksResp(repo string, forceRefresh bool) (checksResp, error) { resp := checksResp{ Repo: repo, + ResolvedRepo: repoRoot.Repo, Files: len(filenames), LastRefresh: time.Now().UTC(), HumanizedLastRefresh: humanize.Time(time.Now().UTC()), diff --git a/templates/report.html b/templates/report.html index db2ae94..7f6924f 100644 --- a/templates/report.html +++ b/templates/report.html @@ -214,7 +214,8 @@ return percentage == false; }); - var allowedLinkDomains = ["github.com/", "bitbucket.org/", "golang.org/"]; + var allowedLinkDomains = ["https://github.com/", "https://bitbucket.org/", + "https://golang.org/", "https://go.googlesource.com/"]; // initialize handlebars templates var templates = {}; @@ -235,8 +236,8 @@ var $resultsDetails = $('.results-details').empty(); for (var i = 0; i < allowedLinkDomains.length; i++) { - if (data.repo.indexOf(allowedLinkDomains[i]) == 0) { - data.link = "https://" + data.repo; + if (data.resolvedRepo.indexOf(allowedLinkDomains[i]) == 0) { + data.link = data.resolvedRepo; } } data.use_an = data.grade == "A" || data.grade == "A+";