Граф коммитов

490 Коммитов

Автор SHA1 Сообщение Дата
Kush Patel 6440758d8a content/static,internal/frontend,internal/middleware: add 'y' keyboard shortcut to canonicalise URL with version
The address bar URL will be updated to be the canonical url of package.
Canonical url includes the module version in address bar.

Fixes golang/go#36807

Change-Id: I4a6f9737ff7e112ebf1d093b2eebe2af311fb0c6
Reviewed-on: https://go-review.googlesource.com/c/pkgsite/+/239179
Reviewed-by: Jamal Carvalho <jamal@golang.org>
Reviewed-by: Andrew Bonventre <andybons@golang.org>
Run-TryBot: Andrew Bonventre <andybons@golang.org>
TryBot-Result: kokoro <noreply+kokoro@google.com>
2020-08-20 19:08:49 +00:00
Miguel Acero a1d3b21add internal/postgres: sort version lists to prefer non-incompatible modules
Currently the version tab displays incompatible modules first in the
list.

Example before: https://i.imgur.com/h1MjpVC.png

This change modifies the SQL queries responsible for fetching the
version list such that the list prefers non-incompatible modules,
leaving incompatible modules at the bottom of the list.

Example after: https://i.imgur.com/jbPzE7Z.png

Tests are also updated to reflect the order change.

Change-Id: I882a9ce042fce924b8e90d733aee6d717dfca7ea
Reviewed-on: https://go-review.googlesource.com/c/pkgsite/+/248859
Reviewed-by: Julie Qiu <julie@golang.org>
2020-08-19 14:14:33 +00:00
Julie Qiu f245a6b99f internal/frontend: limit number of paths allowed by frontend fetch
A upperbound of 10 candidateModulePaths is added for the number of fetch
attempts that a single frontend fetch request will make. Based on our
current dataset, there aren't any module paths that currently have more
than 7 path elements.

Change-Id: Ia098e538abb5a22ba23c9d6c147ffd1da4f1fbb7
Reviewed-on: https://go-review.googlesource.com/c/pkgsite/+/248377
Run-TryBot: Julie Qiu <julie@golang.org>
TryBot-Result: kokoro <noreply+kokoro@google.com>
Reviewed-by: Jamal Carvalho <jamal@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
2020-08-13 19:49:20 +00:00
Julie Qiu ffac86ebe0 internal/frontend: return bad request errors
Errors from candidateModulePaths are now returned in
servePathNotFoundPage, which will all be bad request errors.

Previously, if a request was made to an predetermined invalid path, the
user would only get a BadRequest error after clicking "Request <path>".

The error is now returned on page load.

Change-Id: I98b25122c678ab2a59b70939cab8b74e2b627a2a
Reviewed-on: https://go-review.googlesource.com/c/pkgsite/+/245902
Run-TryBot: Julie Qiu <julie@golang.org>
TryBot-Result: kokoro <noreply+kokoro@google.com>
Reviewed-by: Jonathan Amsterdam <jba@google.com>
2020-08-07 14:40:16 +00:00
Julie Qiu 03d34d43ff internal/proxy: rename testhelper functions
TestProxyServer is renamed to NewClientForServer, so that the function
doesn't have a "Test" prefix when it is not a test.

SetupTestProxy is renamed to SetupTestClient, since it returns a
proxy.Client, and proxy.SetupTestClient reads better.

Change-Id: I6c3152638e29b41e61275174df5e08e7eef5b2c4
Reviewed-on: https://go-review.googlesource.com/c/pkgsite/+/247297
Reviewed-by: Jonathan Amsterdam <jba@google.com>
2020-08-07 14:32:58 +00:00
Jonathan Amsterdam aa6b858a4b internal/frontend: rewrite fetchPackageOverviewDetails to use constructOverviewDetails
For golang/go#39629

Change-Id: Ib92823381e802dca0b4aeb8bd742d914e7dedc41
Reviewed-on: https://go-review.googlesource.com/c/pkgsite/+/247137
Reviewed-by: Julie Qiu <julie@golang.org>
2020-08-07 11:33:32 +00:00
Jonathan Amsterdam 2053b32a64 internal/frontend, content/static: check for insecure HTML ids
Add a check for HTML ids that could be valid Go identifiers or dotted
expressions. Such ids are reserved for rendered documentation, which
must use them so people can jump directly to the documentation for a
symbol by typing it as a fragment.

Change-Id: I646449906a845d17ce9d3740ad13d0e0ae514b8d
Reviewed-on: https://go-review.googlesource.com/c/pkgsite/+/242498
Reviewed-by: Julie Qiu <julie@golang.org>
2020-08-04 21:32:41 +00:00
shaquilleq 6ed53dd70c internal/middleware: update cache to check AuthHeader and AcceptedAuthValues
The cache now performs the same checks as the quota server for a known
header to see if a request should bypass the cache. The shared header
name is now hardcoded since there's no point in keeping it in an
environment variable.

This functionality allows load-testing the frontend server without
hitting the cache.

Change-Id: I7c0fb0196ddc946e84b5fb95ea254f4ab85a3eec
Reviewed-on: https://go-review.googlesource.com/c/pkgsite/+/246138
Reviewed-by: Julie Qiu <julie@golang.org>
Reviewed-by: Jonathan Amsterdam <jba@google.com>
2020-08-04 18:59:37 +00:00
Julie Qiu f7906b062e internal/frontend: add version type metric
A metric is added to determine the number of requests that are made to
@latest, @master, or a specific semantic version. This metric is used to
get better insight into the type of requests that are being made to the
details endpoint.

The version type tag for frontend fetch is removed, since this data
isn't useful.

Change-Id: Ib89acb69297430acd3722bb805456d8ebb30730c
Reviewed-on: https://go-review.googlesource.com/c/pkgsite/+/246397
Reviewed-by: Jonathan Amsterdam <jba@google.com>
2020-08-03 17:26:34 +00:00
Julie Qiu 2f05667100 internal/frontend: enqueue tasks in serveDetails using separate context
When calling ScheduleFetch in serveDetails, it is possible that the
request ends and the context is canceled, before the goroutine finishes
enqueuing a task to the frontend fetch task queue.

A context.Background with a timeout is used instead.

Change-Id: Iee6909c1318c618e4ad3a275d281274c0be87355
Reviewed-on: https://go-review.googlesource.com/c/pkgsite/+/246217
Run-TryBot: Julie Qiu <julie@golang.org>
TryBot-Result: kokoro <noreply+kokoro@google.com>
Reviewed-by: Jonathan Amsterdam <jba@google.com>
2020-08-03 17:22:47 +00:00
Miguel Acero cd12599264 internal/frontend: add metrics for playground share requests
A metric is added for everytime a request is sent to play.golang.org.
The request status code will be used and is useful to have better
visibility on how many users click the new playground "play" button.

For golang/go#36865

Change-Id: I243efe5b3d8724fa6bdd60d332e2932925ffe094
Reviewed-on: https://go-review.googlesource.com/c/pkgsite/+/245898
Reviewed-by: Jonathan Amsterdam <jba@google.com>
2020-08-03 13:27:26 +00:00
Julie Qiu 493b2f3af5 internal/frontend: improve validation of candidate module paths for fetch
Additional source hosts are added to pre-filter invalid module paths.
Each path is also validated using module.CheckImportPath.

For golang/go#37002

Change-Id: I4090a915c023b4d84b9b139e74256c61ca183176
Reviewed-on: https://go-review.googlesource.com/c/pkgsite/+/245897
Reviewed-by: Jonathan Amsterdam <jba@google.com>
2020-07-30 19:35:10 +00:00
Andrew Bonventre 02388aa5df content/static,internal/frontend: add more granular page types
This change specifies more granular page types primarily for use
by the details pages to differentiate between the type of page
(module, package, etc.) and the name of the item being viewed.

This change also hides the type of the item in the fixed header
when it is not wide enough to show other information.

Change-Id: I1e25e75dbdbac01b5d54ea96224f3464cf9fa9f9
Reviewed-on: https://go-review.googlesource.com/c/pkgsite/+/245487
Reviewed-by: Julie Qiu <julie@golang.org>
2020-07-30 19:32:45 +00:00
Andrew Bonventre 98472f3dd8 content/static,devtools,internal: update header to spec
This change implements the latest designs for the site header,
adds a new fixed header to details pages, and updates to the
latest Closure Compiler Docker image tag to support an API used
by the new fixed header implementation (ResizeObserver).

The global header is no longer sticky, but on the details page
a hybrid header that shows a combination of the header content
and details tabs is displayed when the inline tab list goes out
of view.

Both the inline and fixed tab lists are responsive in that the
elements are pushed to an overflow container when they can no
longer fit on screen. A native <select> tag is used for this to
avoid implementing a popup menu (perhaps that can be done in a
future change).

The mechanism used to copy the current path to the clipboard has
also been updated to avoid hacks that didn’t play well with
screen readers. This method does not work on iOS, but a message
is displayed to the user in that case.

Fixes golang/go#37110

Change-Id: I2b8b73d7e85c122992b106e9b89d7e207be9f099
Reviewed-on: https://go-review.googlesource.com/c/pkgsite/+/245400
Run-TryBot: Andrew Bonventre <andybons@golang.org>
TryBot-Result: kokoro <noreply+kokoro@google.com>
Reviewed-by: Jamal Carvalho <jamal@golang.org>
2020-07-30 19:31:21 +00:00
Julie Qiu d002a14131 internal/frontend: return 404 on invalid stdlib paths
At the moment, pkg.go.dev/404 returns the following error message:

Package “404” could not be found, but you can view module “std” at
https://pkg.go.dev/mod/std.

This is because stdlib.Contains(404) returns true.

This error is fixed so that pkg.go.dev/404 just shows a normal 404
error, when frontend fetch is active.

For golang/go#37002

Change-Id: I787a10009294d105d3f92df19790dcd438123f8d
Reviewed-on: https://go-review.googlesource.com/c/pkgsite/+/245878
Reviewed-by: Jonathan Amsterdam <jba@google.com>
2020-07-30 17:07:46 +00:00
Julie Qiu 9884140fac content,internal: update text in fetch.tmpl
The text in fetch.tmpl is updated to provide clearer instructions.

Corresponding CSS is also adjusted for these text changes.

For golang/go#37002

Change-Id: Iae8b641eb2471172eb4465493fe83a4005bce6fc
Reviewed-on: https://go-review.googlesource.com/c/pkgsite/+/245880
Run-TryBot: Julie Qiu <julie@golang.org>
Reviewed-by: Jamal Carvalho <jamal@golang.org>
2020-07-30 16:25:23 +00:00
Julie Qiu 12620322f2 internal/frontend: tweak response text for fetch requests
The response text for different frontend fetch outcomes is
updated.

The code in fetchRequestStatusAndResponseText is also
refactored.

For golang/go#36811
For golang/go#37002

Change-Id: I175921acde5edc5cbf677eb1d1f23171b40318b9
Reviewed-on: https://go-review.googlesource.com/c/pkgsite/+/245640
Run-TryBot: Julie Qiu <julie@golang.org>
Reviewed-by: Jonathan Amsterdam <jba@google.com>
Reviewed-by: Jamal Carvalho <jamal@golang.org>
TryBot-Result: kokoro <noreply+kokoro@google.com>
2020-07-29 21:32:56 +00:00
Miguel Acero a956e7c37d internal/frontend: add integration test for playground example
This change adds a boolean "replay" flag in the existing playground test for the /share endpoint. When enabled, the test will make a request to play.golang.org instead of a mock httptest server.

For golang/go#36865

Change-Id: I26bb79d21500edbc128ce46e19bed493585a3e31
Reviewed-on: https://go-review.googlesource.com/c/pkgsite/+/245378
Reviewed-by: Julie Qiu <julie@golang.org>
Reviewed-by: Jonathan Amsterdam <jba@google.com>
2020-07-29 19:36:54 +00:00
Julie Qiu bfc2a457bf internal/frontend: allow refetch of paths that previously failed
When a fetch request results in a 404, it's possible that the module
path will appear later in the index. Similarly, when a fetch request
results in a 480 or 500, it's possible that the error was transient or
has been fixed but not yet reprocessed.

In these cases, we should allow the user to refetch the path after the
taskIDChangeInterval has passed.

For golang/go#36811
For golang/go#37002

Change-Id: Ia4813140ca793b7b91d80bdc196f61af075766ca
Reviewed-on: https://go-review.googlesource.com/c/pkgsite/+/244601
Reviewed-by: Jonathan Amsterdam <jba@google.com>
2020-07-28 18:20:00 +00:00
Julie Qiu f37c9e18ed internal/frontend: use statusNotFoundInVersionMap for frontend fetch
Previously, we used http.StatusProcessing and http.StatusNoContent to
indicate when a row did not exist in the version_map table.

Neither of these status codes fit well, so our own error code is defined
for the case when a module path has not been processed yet:
statusNotFoundInVersionMap.

For golang/go#36811
For golang/go#37002

Change-Id: Ia55972bfbfb1950ad82254d8f1082dda052bf376
Reviewed-on: https://go-review.googlesource.com/c/pkgsite/+/245020
Run-TryBot: Julie Qiu <julie@golang.org>
TryBot-Result: kokoro <noreply+kokoro@google.com>
Reviewed-by: Jonathan Amsterdam <jba@google.com>
2020-07-28 18:19:34 +00:00
Julie Qiu 782b775a20 internal: add function to return path suffix
The path suffix is used in several places in the codebase. The logic for
how to get the suffix isn't necessarily intuitive, so this logic is
moved to a Suffix function.

Change-Id: Id7e6db67632d4933a8bc3ac78a7b3e0471191a6e
Reviewed-on: https://go-review.googlesource.com/c/pkgsite/+/244437
Reviewed-by: Jonathan Amsterdam <jba@google.com>
2020-07-28 14:19:34 +00:00
Julie Qiu e173fc247d internal/frontend: fix timeout error from checkForPath
Previously, if the context deadline exceeded when calling GetVersionMap
in checkForPath, a 500 was returned. This is fixed so that a 408 is
returned instead.

For golang/go#36811
For golang/go#37002

Change-Id: I60d78fa0e76d5f3e4bb4dab34d66d73a45121955
Reviewed-on: https://go-review.googlesource.com/c/pkgsite/+/245121
Run-TryBot: Julie Qiu <julie@golang.org>
TryBot-Result: kokoro <noreply+kokoro@google.com>
Reviewed-by: Jonathan Amsterdam <jba@google.com>
2020-07-28 14:18:16 +00:00
Julie Qiu 80cd2739a6 internal/frontend: delete s.fetchModule
s.fetchModule is removed. The logic from that function is moved into
checkPossibleModulePaths, which is renamed from checkPossiblePaths for
clarity.

For golang/go#36811
For golang/go#37002

Change-Id: I8ac26ac13fcddc19582682bd5351b0b7a6a2858f
Reviewed-on: https://go-review.googlesource.com/c/pkgsite/+/245021
Run-TryBot: Julie Qiu <julie@golang.org>
TryBot-Result: kokoro <noreply+kokoro@google.com>
Reviewed-by: Jonathan Amsterdam <jba@google.com>
2020-07-28 14:17:01 +00:00
Julie Qiu 19e31bfe34 internal/proxy: rename TestModule to Module
TestModule is renamed to Module, since it is shorter and proxy.Module is
equally descriptive as an exported variable.

Change-Id: Iebce664fa6e4580a4ab6b62fb73ad4bff611d067
Reviewed-on: https://go-review.googlesource.com/c/pkgsite/+/245118
Reviewed-by: Jonathan Amsterdam <jba@google.com>
2020-07-28 14:16:45 +00:00
Julie Qiu 0c07af624c internal/frontend: use request context in recordFrontendFetchMetric
When recording tags for frontend fetch, the context from the request is
now used so that we know which service the request came from.

Change-Id: I2e016a734f599edac1a1db626a54026d1783b42a
Reviewed-on: https://go-review.googlesource.com/c/pkgsite/+/245128
Run-TryBot: Julie Qiu <julie@golang.org>
Reviewed-by: Jonathan Amsterdam <jba@google.com>
2020-07-28 13:29:07 +00:00
Jonathan Amsterdam ef183200d1 internal/middleware: get ExperimentSource from a function
Get the ExperimentSource for an Experimenter by calling a function
each time one is needed.

Part of the reorganization that will let us switch between
databases when one is bad.

Updates b/149906513.

Change-Id: I0ce6f48ad80402e9ccc3a0a3ef2cfe195f01bdc2
Reviewed-on: https://go-review.googlesource.com/c/pkgsite/+/244611
Run-TryBot: Jonathan Amsterdam <jba@google.com>
TryBot-Result: kokoro <noreply+kokoro@google.com>
Reviewed-by: Julie Qiu <julie@golang.org>
2020-07-28 13:14:38 +00:00
Jonathan Amsterdam 5e159604f7 internal/frontend: get a DataSource on each request
Reorganize the server so that each request gets its own DataSource,
instead of using a single DataSource for every request.

Currently, the behavior doesn't change because we do in fact use
the same DataSource for every request. But this paves the way
to having a pool of health-checked DB connections, while still
having each request work with a single connection.

For golang/go#40444.

Change-Id: I717450593a8dcfd5689a8d28f634324776305042
Reviewed-on: https://go-review.googlesource.com/c/pkgsite/+/244603
Reviewed-by: Julie Qiu <julie@golang.org>
2020-07-28 13:14:05 +00:00
Julie Qiu 206bce3ee7 internal/frontend: display path result if previously fetched
If a path does not exist in the paths table, but we have already
unsuccessfully fetched it in the past, display the response for that
fetch result. Otherwise, when the user click the "Fetch" button, they
will just see that response anyway.

For golang/go#37002

Change-Id: I28ac16dfd40aee15b90d68ba986862f9e1143152
Reviewed-on: https://go-review.googlesource.com/c/pkgsite/+/244698
Reviewed-by: Jonathan Amsterdam <jba@google.com>
2020-07-27 22:18:01 +00:00
Julie Qiu f93008ec95 internal/frontend: remove "frontend" prefix from frontendFetch variables
frontend.FrontendFetch is repetitive, so the frontend prefix is removed.

Change-Id: Id9467ed83aff0e917984ba6ffc3ce3e5d467b151
Reviewed-on: https://go-review.googlesource.com/c/pkgsite/+/244697
Reviewed-by: Jonathan Amsterdam <jba@google.com>
2020-07-27 14:53:57 +00:00
Julie Qiu 1fb4ec10c9 internal/frontend: fix basePage for custom error pages
This change fixes an issue in initiating the base page for a custom
error pages, which prevent fields such as the AppVersion and
GoogleTagManagerID to be set.

Change-Id: Ifdc7a058b1d6281132004036f678bebca9ef5811
Reviewed-on: https://go-review.googlesource.com/c/pkgsite/+/244549
Reviewed-by: Jamal Carvalho <jamal@golang.org>
Run-TryBot: Julie Qiu <julie@golang.org>
TryBot-Result: kokoro <noreply+kokoro@google.com>
2020-07-23 20:34:08 +00:00
Julie Qiu 2e770e1fc5 internal/frontend: update response text for fetch timeout
The response text for fetch timeouts is updated to be more conscise.

For golang/go#37002

Change-Id: Iec7eed7fac03260ab72a276b9295033c397c0a86
Reviewed-on: https://go-review.googlesource.com/c/pkgsite/+/244543
Reviewed-by: Jamal Carvalho <jamal@golang.org>
2020-07-23 17:41:08 +00:00
Julie Qiu 5bf7727407 internal/frontend: add fetchVersionsDetails and fetchModuleVersionsDetails
Change-Id: Id5a2d3360f905290731444c4d07e39e0c0e6a5df
Reviewed-on: https://go-review.googlesource.com/c/pkgsite/+/243703
Run-TryBot: Julie Qiu <julie@golang.org>
Reviewed-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Jamal Carvalho <jamal@golang.org>
2020-07-23 16:44:53 +00:00
Jonathan Amsterdam 94ee022909 internal/frontend: remove HTML-walking feature flag
Now that we have determined that walking the HTML to translate
relative image tags does no harm, use it all the time.

Change-Id: Ifcb43ed52a691daebe78029bde1f3426db7c565f
Reviewed-on: https://go-review.googlesource.com/c/pkgsite/+/243999
Reviewed-by: Julie Qiu <julie@golang.org>
2020-07-23 11:05:39 +00:00
Anze Kolar 0b550ca830 internal/frontend: refactor serverTestCases()
With this change, the flow of TestServer() is simplified: decision logic
whether a test should be run (based on enabled experiments) is moved to
testServer(). Required experiments can be specified when creating
individual test cases in serverTestCases().

This should make the process of adding new tests more transparent
(experiments can be allowed on the test case itself) and remove the need
for returning multiple slices of test cases (for different combinations
of experiments) which are then merged together on a per-test-server
basis. As a trade-off, additional decision logic is added to
testServer() and required experiments have to be specified on each
individual case (as opposed to a block of cases as before).

For golang/go#39663.

Change-Id: Iccdce5ddd7705e1ef8acd8aa4673d4b6a1193b2e
Reviewed-on: https://go-review.googlesource.com/c/pkgsite/+/243017
Reviewed-by: Julie Qiu <julie@golang.org>
2020-07-23 01:34:02 +00:00
Jonathan Amsterdam 23fc355e37 internal/frontend: handle img src attributes with surrounding whitespace
Following the HTML spec at
https://html.spec.whatwg.org/multipage/embedded-content.html#attr-img-src,
it is OK to have spaces around an img src attribute. Trim them before
escaping.

Change-Id: I07e57a18cfc342ba2f8c24ba99fd92f838975222
Reviewed-on: https://go-review.googlesource.com/c/pkgsite/+/243859
Reviewed-by: Julie Qiu <julie@golang.org>
2020-07-21 12:35:38 +00:00
Julie Qiu fbdbaf6b69 internal/frontend: fix TestReadmeHTML/valid_markdown_readme_with_CRLF
TestReadmeHTML/valid_markdown_readme_with_CRLF was introduced in
CL 243457 and doesn't pass. The test is fixed.

Change-Id: Ia9d12e408d9574f2cb15c3f88f82e7a309ed5b52
Reviewed-on: https://go-review.googlesource.com/c/pkgsite/+/243701
Reviewed-by: Jamal Carvalho <jamal@golang.org>
2020-07-20 22:25:28 +00:00
Anze Kolar 6bba22c162 internal/frontend: replace \r\n with \n in readmes and licences
Replace CRLF line terminators in readme and license files before
rendering Overview and Licenses tabs on the Details page. Keeping \r
characters interferes with blackfriday's parser, resulting in an
incorrectly rendered HTML output (see golang/go#40203 for details).

Fixes golang/go#40203.

Change-Id: Id6c2951c9f23e7054957071cf1c33fd3fa6494c6
Reviewed-on: https://go-review.googlesource.com/c/pkgsite/+/243457
Reviewed-by: Julie Qiu <julie@golang.org>
2020-07-20 20:25:16 +00:00
Julie Qiu 50e50040f9 internal/frontend: poll the database for frontend fetch results less frequently
pollEvery is increased to every second instead of every 500ms, since
most fetch requests took longer than 500ms to finish when testing
locally.

For golang/go#37002

Change-Id: I6d0e77153872a6303cd60df68419adb8821dcebe
Reviewed-on: https://go-review.googlesource.com/c/pkgsite/+/242923
Reviewed-by: Jonathan Amsterdam <jba@google.com>
2020-07-20 19:28:23 +00:00
Julie Qiu 3d14dbdc5a internal/frontend: update response text for fetch endpoint
The response text for statuses http.StatusSeeOther and
http.StatusNotFound is updated to use smart quotes and specify the
requested version.

TODOs in internal/frontend/fetch.go are also updated.

For golang/go#37002

Change-Id: I274847ca979e47dc5d9e98456d84e8511332a811
Reviewed-on: https://go-review.googlesource.com/c/pkgsite/+/242921
Reviewed-by: Jonathan Amsterdam <jba@google.com>
2020-07-20 19:28:15 +00:00
Jonathan Amsterdam 5dab955ef2 internal/frontend: clean up TestReadmeHTML
No longer require the exact trailing space.

Change-Id: I6f93fd57cf7e8a32cc43cabe618ccc3ce024b81c
Reviewed-on: https://go-review.googlesource.com/c/pkgsite/+/243619
Reviewed-by: Julie Qiu <julie@golang.org>
2020-07-20 14:18:00 +00:00
Jonathan Amsterdam 5bdfc28e08 internal/frontend: use escaped path when modifying image sources
When walking HTML inside markdown to translate relative image sources,
use the escaped path of the source rather than the original path.

Previously, if the value of an img src tag was escaped, like

    a%20b

it was being converted to

    a b

The sanitizer then removed the entire img tag.

Using URL.EscapedPath preserves the original escaping.

Change-Id: I05544a7f2d089c7026dedac605e07b193823957b
Reviewed-on: https://go-review.googlesource.com/c/pkgsite/+/243618
Reviewed-by: Julie Qiu <julie@golang.org>
2020-07-20 14:17:37 +00:00
Jonathan Amsterdam 977cf9335e internal/frontend: factor out common test value
In TestReadmeHTML, move repeated ModuleInfo to a local variable.

Change-Id: Ib866715686aa4f144d21d41a7210ae65e7c5ef08
Reviewed-on: https://go-review.googlesource.com/c/pkgsite/+/243617
Reviewed-by: Julie Qiu <julie@golang.org>
2020-07-20 14:17:31 +00:00
Jonathan Amsterdam cb17e53bcd internal/frontend: improvements to translateHTML
- Walk all the children of the body node, not just the first: there
  may be more than one.

- Fail if the top-level node is not what we expect, rather than
  returning something.

Change-Id: I2c479064dbe45a9bbd402f3878ab4638d62dd475
Reviewed-on: https://go-review.googlesource.com/c/pkgsite/+/243224
Reviewed-by: Julie Qiu <julie@golang.org>
2020-07-17 21:07:46 +00:00
Jonathan Amsterdam 186838c492 internal/source: use better github raw template
Replace the previous github template for raw data
(raw.githubusercontent...)  with a new one that is more uniform (the
same as the blob template, with "raw" instead of "blob").

The main advantage is that we can drop the "repoPath" parameter to the
template, which was necessary only to support the unusual GitHub
URLs.

Now that GitHub and GitLab templates are identical, we can drop the
GitLab ones. We preserve "gitlab" in the map from kinds to templates
so we can continue to unmarshal DB modules.source_info columns
that use "gitlab".

Change-Id: Id3d45929f0eb2c040109449d4208279cca44f079
Reviewed-on: https://go-review.googlesource.com/c/pkgsite/+/243217
Reviewed-by: Julie Qiu <julie@golang.org>
2020-07-17 13:38:46 +00:00
Jonathan Amsterdam cd77657e37 internal/frontend: don't regenerate HTML unless it changed
While walking HTML, keep track of whether we made any changes.
If not, return the original HTML, not the re-rendered version.

This minimizes changes to existing readmes (since parsing HTML and
then rendering it does not always give you back the same thing).

Change-Id: Id43c1d45359d44fffd0ab9e6b655fad12262ede7
Reviewed-on: https://go-review.googlesource.com/c/pkgsite/+/242980
Reviewed-by: Julie Qiu <julie@golang.org>
2020-07-17 13:38:14 +00:00
Jonathan Amsterdam c587389cc5 internal/frontend: export ReadmeHTML
Export the ReadmeHTML function to enable testing by code outside the
package.

Specifically, we'll be writing a program to test HTML changes against
the database.

Change-Id: I21dbd2606e1c370c974e9bf65d2535860884435b
Reviewed-on: https://go-review.googlesource.com/c/pkgsite/+/242979
Reviewed-by: Julie Qiu <julie@golang.org>
2020-07-16 15:44:29 +00:00
Jonathan Amsterdam ec5c5861be internal/frontend: add a test case for bad SourceInfo
Confirm that attacks that exploit bad URLs are thwarted.

Change-Id: I079f81e0b3f6777fa6d271c4e43fccf7a0c6b438
Reviewed-on: https://go-review.googlesource.com/c/pkgsite/+/242978
Reviewed-by: Julie Qiu <julie@golang.org>
2020-07-16 15:44:11 +00:00
Jonathan Amsterdam 1e106a2018 internal/frontend: translateRelativeLink takes source.Info instead of ModuleInfo
Change the arg to translateRelativeLink and friends to be a source.Info, since
it doesn't need a full ModuleInfo.

Change-Id: Iae92f39328c5f207c4f28ea5ba8cd4c2ca38392f
Reviewed-on: https://go-review.googlesource.com/c/pkgsite/+/242977
Reviewed-by: Julie Qiu <julie@golang.org>
2020-07-16 15:43:50 +00:00
Julie Qiu bf169b2ac3 internal/derrors: rename ToHTTPStatus to ToStatus
ToHTTPStatus is renamed to ToStatus, since several derrors codes are
not HTTP status codes.

Change-Id: I41bf1452fdbbafe1a4f752bc3092e39515a2db4b
Reviewed-on: https://go-review.googlesource.com/c/pkgsite/+/242882
Reviewed-by: Jonathan Amsterdam <jba@google.com>
2020-07-16 14:19:09 +00:00
Julie Qiu 606e69c6ed internal/frontend: use GetLicenses
GetLicenses is now used by the frontend to fetch license data when the
"use-directories" experiment is on.

For golang/go#39629

Change-Id: I7a4c358b9e4f0d0089c301a40703becda1d5514d
Reviewed-on: https://go-review.googlesource.com/c/pkgsite/+/242778
Reviewed-by: Jonathan Amsterdam <jba@google.com>
2020-07-16 14:18:56 +00:00