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

218 Коммитов

Автор SHA1 Сообщение Дата
Rob Findley db22c1a2b9 discovery: add multiple license support
This CL changes our data model so that licenses are associated with
packages rather than module versions, and adds multiple license
detection.  As a result, given following file layout

  my.mod/LICENSE
  my.mod/pkgfoo/COPYING
  my.mod/pkgbar/LICENSE.md

both LICENSE and COPYING (but not LICENSE.md) will be associated with
the package my.mod/pkgfoo.

Additionally make some minimal UI changes to support the new data model,
though a proper implementation of the licenses tab is deferred to a
later CL.

Fixes b/130372424
Updates b/129371814
Updates b/129372226
Fixes b/129000846
Fixes b/129372204

Change-Id: Ife58498914fea75e4c58e7c713a8071887f87000
Reviewed-on: https://team-review.git.corp.google.com/c/golang/discovery/+/447910
Reviewed-by: Julie Qiu <julieqiu@google.com>
2020-03-27 16:46:35 -04:00
Dmitri Shuralyov b2e8ade79d internal/frontend, content: add a starting point for the documentation page
There's no godoc content yet, that will follow in future CLs.

Change the tab name from "docs" to just "doc". This is simpler and more
consistent with "godoc", etc. The current future plan is to make this
the default tab, so it won't have a name then. But it'll continue to be
"doc" while the page is in development.

Change-Id: If4ec229a6b7f49aee216f6ea845bcf3d1e2fa356
Reviewed-on: https://team-review.git.corp.google.com/c/golang/discovery/+/449355
Reviewed-by: Julie Qiu <julieqiu@google.com>
2020-03-27 16:46:35 -04:00
Andrew Bonventre 6b4b716926 content/static/html: move search snippet fragment into search template
Also removes a superfluous HTML self-closing tag since those are
optional in HTML5.

Change-Id: Ifa066a9cbd76a6f574757793a86d2492811f6184
Reviewed-on: https://team-review.git.corp.google.com/c/golang/discovery/+/449353
Reviewed-by: Julie Qiu <julieqiu@google.com>
2020-03-27 16:46:35 -04:00
Andrew Bonventre cd91bad772 internal/frontend: switch to using a get param for versions
Additionally passes the template context to the nav template
on all pages with some other small updates.

Fixes b/130230126

Change-Id: I10114822382c6fc6c0a9f547749aa4faa433a851
Reviewed-on: https://team-review.git.corp.google.com/c/golang/discovery/+/449352
Reviewed-by: Julie Qiu <julieqiu@google.com>
2020-03-27 16:46:35 -04:00
Andrew Bonventre 78a6b8a7c8 content/static/html: clean up some template logic
+ Disable autocomplete, spellcheck, autocorrect, etc. in the search
  input
+ Remove redundant "equal" template function in favor of the built-in
  "eq"
+ Populate the search input with the current query
+ Show the query first in the title since tabs are typically not
  wide enough to show everything
+ Redirect to the homepage if the q param is empty
+ Other very small cleanup changes

Change-Id: Ib9baa41c336088cb3e9555ddaf527545292bb118
Reviewed-on: https://team-review.git.corp.google.com/c/golang/discovery/+/449351
Reviewed-by: Julie Qiu <julieqiu@google.com>
2020-03-27 16:46:35 -04:00
Julie Qiu 23e1fd27ba .gitignore: add GCP files to .gitignore
Change-Id: Ic5819d4dc2af207c0fcad9d038095adad71a0770
Reviewed-on: https://team-review.git.corp.google.com/c/golang/discovery/+/447918
Reviewed-by: Robert Findley <rfindley@google.com>
2020-03-27 16:46:35 -04:00
Rob Findley 0f2671b130 migrations: schema changes enabling multiple licenses
Add a licenses table to capture license information, along with a join
table that associates packages and licenses.  This caused package
queries in internal/postgres to become pretty complicated, so add a
helper view to offload some of that complexity.

Fixes b/129370884

Change-Id: I7d97b3458b35c7c1b2400a28f5025ba3f83a5af1
Reviewed-on: https://team-review.git.corp.google.com/c/golang/discovery/+/448258
Reviewed-by: Julie Qiu <julieqiu@google.com>
2020-03-27 16:46:35 -04:00
Julie Qiu 6720b6293f cmd/cron,internal/cron: fix compile error introduced in commit e51b998
The fetchTimeout const was moved from cmd/cron/main.go to
internal/cron/cron.go in commit e51b998, but the signature of
cron.FetchVersions was not updated, which led to a compile error. This
CL fixes that bug.

Change-Id: I4ac4037e34115073e0ce96decbc696c4d9f74514
Reviewed-on: https://team-review.git.corp.google.com/c/golang/discovery/+/448153
Reviewed-by: Robert Findley <rfindley@google.com>
2020-03-27 16:46:35 -04:00
Julie Qiu f7f036cf7a internal: remove "returned error" from error messages
The terms "returned error" are removed from error messages where
unnecessary.

Change-Id: I06ef2e45ae0ba3365d4d1fec86b46c917ca0b3b2
Reviewed-on: https://team-review.git.corp.google.com/c/golang/discovery/+/447330
Reviewed-by: Robert Findley <rfindley@google.com>
2020-03-27 16:46:35 -04:00
Julie Qiu effbce9ef1 discovery: add .idea directory to .gitignore
IntelliJ creates a .idea ignore in the repository root, which is now
ignored by git.

Change-Id: Ieda599bbc0865649e91bb4bee82b001d615a1026
Reviewed-on: https://team-review.git.corp.google.com/c/golang/discovery/+/447072
Reviewed-by: Robert Findley <rfindley@google.com>
2020-03-27 16:46:35 -04:00
Julie Qiu 4c70155b9e content,internal/frontend,internal/postgres: create module page
The module page is added, which displays the directory and synopsis
of all packages in the module and the README.

This change includes the following additions:
* frontend.fetchModulePage: returns data needed to populate module.tmpl
* postgres.GetVersionForPackage: returns the version for a given
  package_path and version, along with all of the packages for that
  version.

Note: At the moment, both the overview page and the module page display
the README. Once a decision is made on where the README will be displayed,
these pages will be updated.

Fixes b/130112117
Fixes b/130111944

Change-Id: Ib240b1744cf66be72a63683804b521beaec62307
Reviewed-on: https://team-review.git.corp.google.com/c/golang/discovery/+/444468
Reviewed-by: Andrew Bonventre <andybons@google.com>
2020-03-27 16:46:35 -04:00
Julie Qiu bf8adebf67 cmd/cron,internal/cron: introduce max parallelism for requests to fetch service
Requests made from the cron endpoint /new/ to the fetch service are now
parallelized using cron.FetchVersions and by specifying a workers flag
for the maximum number of requests in flight.

Fixes b/128540164

Change-Id: Ic0885739ae668495cd91e5dacfd39846b16e83f3
Reviewed-on: https://team-review.git.corp.google.com/c/golang/discovery/+/442300
Reviewed-by: Robert Findley <rfindley@google.com>
2020-03-27 16:46:35 -04:00
Rob Findley 25fea74665 internal/frontend: rename 'tabName' to the more correct 'pageName'
Change-Id: Iadc768b1e5fad23f49f688cee857d59e2f72d9a2
Reviewed-on: https://team-review.git.corp.google.com/c/golang/discovery/+/446470
Reviewed-by: Julie Qiu <julieqiu@google.com>
2020-03-27 16:46:34 -04:00
Julie Qiu ad6bee21ae cmd/cron,cmd/frontend: listen on port defined by environment variable PORT
App Engine requires that apps listen on the port defined by the PORT
environment variable. Otherwise, it logs an error message like the
following:

App is listening on port 8080, it should instead listen on the port
defined by the PORT environment variable. As a consequence, nginx cannot
be started. Performance may be degraded. Please listen on the port
defined by the PORT environment variable.

Change-Id: I38f8e0e96cc44e384fb712510efbfaaa68fef4f4
Reviewed-on: https://team-review.git.corp.google.com/c/golang/discovery/+/446246
Reviewed-by: Robert Findley <rfindley@google.com>
2020-03-27 16:46:34 -04:00
Julie Qiu 79707fd405 internal/fetch: do not read non-.go files greater than 10MB
extractPackagesFromZip is updated so that it will skip non-.go files
greater than 10MB when parsing packages. If there is a .go file in the
module greater than 10MB, an error will be returned.

detectLicense is updated so that it will skip license files found
that are greater than 10MB.

Fixes b/130089430

Change-Id: I8ea97d514b7b07968bbc219c9b257f125df50e33
Reviewed-on: https://team-review.git.corp.google.com/c/golang/discovery/+/446245
Reviewed-by: Robert Findley <rfindley@google.com>
2020-03-27 16:46:34 -04:00
Dmitri Shuralyov e22e11aa97 internal/frontend: use blackfriday/v2 from github.com instead of gopkg.in
The canonical import path of blackfriday v2 in module mode is:

	github.com/russross/blackfriday/v2

It can be seen in the go.mod file of the latest version (v2.0.1)
at https://github.com/russross/blackfriday/blob/v2.0.1/go.mod#L1.
Also, https://github.com/russross/blackfriday#versions says:

> With package management you should import github.com/russross/blackfriday
> and specify that you're using version 2.0.0.

The wording there needs to be improved/updated, but for module mode,
it means to add a /v2 suffix.

Change-Id: Ie833acef8ecd1727a902723c07da4a918cdc7e68
Reviewed-on: https://team-review.git.corp.google.com/c/golang/discovery/+/446244
Reviewed-by: Julie Qiu <julieqiu@google.com>
2020-03-27 16:46:34 -04:00
Rob Findley 83c075957a frontend: refactor template parsing and fix active nav tab
This CL implements a pattern similar to that used in
github.com/golang/gddo to implement an active tab selector for the nav.
Along the way, refactor a bit so that the frontend package is fully
responsible for templates.

Also replace the pattern of Make*HandlerFunc with handler methods.

Also fix a minor typo in all.bash that was causing misspell not to be
installed.

Updates b/124309095

Change-Id: I802ba69b91b81be13c6314140326fe8783608a0c
Reviewed-on: https://team-review.git.corp.google.com/c/golang/discovery/+/445973
Reviewed-by: Julie Qiu <julieqiu@google.com>
2020-03-27 16:46:34 -04:00
Rob Findley 860eff1d8c cron: use the index timestamp for polling
This fixes a latent bug where clock offsets cause us to miss versions.
Spanner provides a monotonicity guarantee so that its commit time is
viable for pagination, if not ideal.

Unfortunately it's only monotonic: querying for since=t_0 returns all
versions with Timestamp >= t_0, and therefore we'll always have an
at-least-1 module overlap in our polling.

Fixes b/129700670

Change-Id: Iab9a2ed0445c913ef5f1d590d30152adda9a157e
Reviewed-on: https://team-review.git.corp.google.com/c/golang/discovery/+/444659
Reviewed-by: Julie Qiu <julieqiu@google.com>
2020-03-27 16:46:34 -04:00
Julie Qiu 4705fcbef6 cmd: add environment variable GO_DISCOVERY_[service]_ADDR and default proxy to proxy.golang.org
The GO_DISCOVERY_[service]_ADDR variable is introduced, to set the adrr
that various services are running on. The default is set to
localhost:[port] to mute to popup on incoming networking connections
when running locally.

The default for GO_MODULE_PROXY_URL is set to https://proxy.golang.org
and for GO_MODULE_PROXY_INDEX is set to https://index.golang.org/index.

Change-Id: I097fd96a5c51ce1ec73ceab1928fda39de506352
Reviewed-on: https://team-review.git.corp.google.com/c/golang/discovery/+/445646
Reviewed-by: Robert Findley <rfindley@google.com>
2020-03-27 16:46:34 -04:00
Julie Qiu 8b6fd3a242 internal/postgres: fix strconv.Atoi invalid syntax error
Previously, an error occurred when parsing versions with build tags,
such as "v1.2.5+incompatible".

This CL fixes the error and moves parsing major, minor and patch inside
internal/postgres to individual functions.

Fixes #130041347.

Change-Id: I192dad8b1620c2235f19ddc8cf0f04f98c473b39
Reviewed-on: https://team-review.git.corp.google.com/c/golang/discovery/+/444465
Reviewed-by: Andrew Bonventre <andybons@google.com>
2020-03-27 16:46:34 -04:00
Julie Qiu 79fb951b9e content,internal/frontend: link versions to default details page
The links in versions.tmpl now route to the default tab instead of the
versions tabs.

An error with using the wrong type to format an arg for the
createPackageHeader error message is also fixed.

Change-Id: I5479895e13e04867aa00153e4276e0e6fc4aee43
Reviewed-on: https://team-review.git.corp.google.com/c/golang/discovery/+/444466
Reviewed-by: Robert Findley <rfindley@google.com>
2020-03-27 16:46:34 -04:00
Julie Qiu 995f0d2aea discovery: add misspell to all.bash
Change-Id: I4e68a66553182908b1108cfd9139c65b04c09bfb
Reviewed-on: https://team-review.git.corp.google.com/c/golang/discovery/+/445469
Reviewed-by: Andrew Bonventre <andybons@google.com>
2020-03-27 16:46:34 -04:00
Channing Kimble-Brown e16f400131 content, cmd/frontend, internal/fetch, internal/frontend: add search and home frontend
The following endpoints now have handler funcs HTML/CSS:
- "/" directs the user to the home page which contains just a search bar.
This endpoint is handled by MakeDetailsHandlerFunc.
- "/search?q=<query>" directs the user to a list of search results for the
specified query. This endpint is handled by MakeSearchHandlerFunc.

Fixes b/125408009.

Change-Id: I2d919e35b8d5d8d5f76a6895d47f99897b4f32ff
Reviewed-on: https://team-review.git.corp.google.com/c/golang/discovery/+/444660
Reviewed-by: Julie Qiu <julieqiu@google.com>
2020-03-27 16:46:34 -04:00
Julie Qiu 5be9805028 internal/fetch,internal/postgres: fix no packages error and error messages display
validateVersions used to return an error if a version did not have any
packages. These versions should be inserted into the database, since we
could have a module without any packages.

Error messages corresponding to a given version no longer print the full
struct. They will only print the module path and version.

GetLatestPackageForPaths is also moved to internal/postgres/search.go, since
it is used for search.

Fixes b/130027196.

Change-Id: Ief0ee0ab977a47ee0840da14ef2336f082b2db28
Reviewed-on: https://team-review.git.corp.google.com/c/golang/discovery/+/444661
Reviewed-by: Channing Kimble-Brown <ckimblebrown@google.com>
2020-03-27 16:46:34 -04:00
Rob Findley 89cdb14112 discovery: add a timeout for client requests
Use the Timeout middleware to to add a timeout for incoming requests.
As a notable exception, don't do this for module fetch, as we want
module processing to continue even if the client cancels their request
early.  Instead, set an explicit timeout for module processing.

Additionally, bind work done on behalf of the request to the request
context.  This required switching to the context-aware sql APIs, setting
a context on outbound HTTP requests, and quite a bit of 'ctx' threading.

Fixes b/128689909

Change-Id: Ic732808b6df89a61106f5d14b8a9ecaaefb95c4f
Reviewed-on: https://team-review.git.corp.google.com/c/golang/discovery/+/443023
Reviewed-by: Julie Qiu <julieqiu@google.com>
2020-03-27 16:46:34 -04:00
Julie Qiu 5d4ca381ef internal/fetch: insert documents for version
When a new version is downloaded, insert it into the
documents table so that it can be used for search.

Change-Id: Id46bc0aa6b14f0c5bc9f7520aef3baad8efe0454
Reviewed-on: https://team-review.git.corp.google.com/c/golang/discovery/+/444658
Reviewed-by: Channing Kimble-Brown <ckimblebrown@google.com>
2020-03-27 16:46:34 -04:00
Julie Qiu 75375817ce fetch: close files immediately after use when extracting zip
extractPackagesFromZip opened and closed files in a loop by calling
defer file.Close(). This led to an error with too many files being open
when unzipping large modules.

The files are now closed immediately after use, using the func
writeFileToDir.

Fixes b/129349898.

Change-Id: If71ab136920ee2c51e20d4c501c2cfd0d7962f22
Reviewed-on: https://team-review.git.corp.google.com/c/golang/discovery/+/444549
Reviewed-by: Robert Findley <rfindley@google.com>
2020-03-27 16:46:34 -04:00
Rob Findley f96a8cb1bd internal/postgres: fix two sources of test flakes
This CL addresses two causes of flaky tests:
 + Non-deterministic sorting in search results, due to results of the
   same rank.
 + Transactional issues due to multiple non-hermetic package tests
   running in parallel.

Fixes b/129855505
Fixes b/129963750
Fixes b/129696857

Change-Id: Ic69cb1f6393325f4c3955d721a4dbdcf73d8258d
Reviewed-on: https://team-review.git.corp.google.com/c/golang/discovery/+/444670
Reviewed-by: Julie Qiu <julieqiu@google.com>
2020-03-27 16:46:34 -04:00
Channing Kimble-Brown a90ca55731 content, internal/frontend, internal/postgres: add ability to render versions tab
fetchVersionsTabPage takes in a package path and a version and then returns
all of the data needed to display the packages that have the same series and
package suffix to make the versions tab content. The data is displayed in a
hierarchical list of major (i.e. "v1") then major and minor (i.e. "1.2") and
lastly the entirety of the version (i.e. "1.2.3" or "1.2.2-alpha.1").

verisons.tmpl is the template that displays all of the data in the
VersionsTabPage struct.

The routing was changed so that MakeFrontendHandlerFunc handles both
/<import path>@<version> which brings up the overview page and
/<import path>@<version>?tab=versions which brings up the versions
tab.

Fixes b/124308701

Change-Id: I92bd86d050ab6e7e669c07a750b325b3e026d052
Reviewed-on: https://team-review.git.corp.google.com/c/golang/discovery/+/443954
Reviewed-by: Julie Qiu <julieqiu@google.com>
2020-03-27 16:46:34 -04:00
Julie Qiu 06f2b9a513 internal/frontend,internal/postgres: implement fetchSearchPage
frontend.fetchSearchPage is implemented, which returns all of the data
needed to generate results for a search page.

postgres.Search is updated so that results with a rank score of 0 are
not returned.

Change-Id: I2e41716ce0cfa9db70b0a84930b4e2568a2c969b
Reviewed-on: https://team-review.git.corp.google.com/c/golang/discovery/+/443906
Reviewed-by: Robert Findley <rfindley@google.com>
2020-03-27 16:46:34 -04:00
Rob Findley cc01e6810b internal/postgres: use microsecond precision for time in tests
Truncate all timestamps used in tests to Microsecond precision, so that
precision is not lost when saving and retrieving from Postgres.

Fixes b/129859073

Change-Id: Id677147ac44dc08cd52e0fae9a6d0510b68a666e
Reviewed-on: https://team-review.git.corp.google.com/c/golang/discovery/+/443892
Reviewed-by: Andrew Bonventre <andybons@google.com>
2020-03-27 16:46:34 -04:00
Julie Qiu b3932ac94f internal/postgres: implement InsertDocuments and Search
InsertDocuments inserts the packages for a given version into the
documents table, and creates tsvector tokens to allow for searching
package name, package path, synopsis tokens, and readme tokens.

Search fetches packages that match a given set of terms, and returns
them in order of rank. Rank is based on relevance and the number of
dependents.

Change-Id: I60e8b690955adb66306e326238e426cf77527f82
Reviewed-on: https://team-review.git.corp.google.com/c/golang/discovery/+/443363
Reviewed-by: Andrew Bonventre <andybons@google.com>
2020-03-27 16:46:34 -04:00
Rob Findley d61efba1e2 internal/middleware: add a middleware package
This adds a simple definition of middleware, along with a single
implementation: a Timeout middleware.  In a follow-up CL I'll use this
to add timeouts to user-facing handlers.

Updates b/128689909

Change-Id: Ie2078e4e3da45767c7ef38f1aab25b8da5b1cf14
Reviewed-on: https://team-review.git.corp.google.com/c/golang/discovery/+/443949
Reviewed-by: Andrew Bonventre <andybons@google.com>
2020-03-27 16:46:34 -04:00
Rob Findley 58e3349772 migrations: add COLLATE "C" to several columns
Depending on locale settings, it is possible for '~' to be ordered as
less than 'a'. This breaks the semver sorting logic. To prevent this,
set explicit "C" collation for versions.prerelease, packages.path,
and packages.module_path.

Fixes b/129684816

Change-Id: I6e290d7d1e55c2979f5c6dcee7a5c00fdecdd680
Reviewed-on: https://team-review.git.corp.google.com/c/golang/discovery/+/443305
Reviewed-by: Julie Qiu <julieqiu@google.com>
2020-03-27 16:46:34 -04:00
Channing Kimble-Brown 354a3540f7 internal/postgres: get all versions with the same series name and package suffix
This CL edits GetTaggedVersions and GetPseudoVersions so that
they fetch all of the versions of associated packages that
have the same specified series name and package path suffix.
These methods will be used to determine which versions to
display on the versions tab in the frontend.

Fixes b/129553236

Change-Id: I3930868b66f11d955f1ce15307aa21c0599ab999
Reviewed-on: https://team-review.git.corp.google.com/c/golang/discovery/+/443090
Reviewed-by: Julie Qiu <julieqiu@google.com>
2020-03-27 16:46:34 -04:00
Julie Qiu bc4d221c92 internal/postgres: fix errors in GetLatestPackageForPaths
GetLatestPackageForPaths originally was not pulling expected packages,
due to how the WHERE clause param was being passed in.

It is fixed in this CLs along with the tests.

Change-Id: Ia377175bd6a51fe4fd53ea3d8ccc2c1dfc377ecb
Reviewed-on: https://team-review.git.corp.google.com/c/golang/discovery/+/443360
Reviewed-by: Channing Kimble-Brown <ckimblebrown@google.com>
2020-03-27 16:46:34 -04:00
Julie Qiu c117934280 cmd/fetch: remove the K8s–applied fields from service.yaml
Remove the K8s-applied fields from service.yaml so that we can run
`kubectl apply -f` on this resource instead of running
`kubectl expose`.

Change-Id: I1399658df53d73d6021979a1334503d8e1510876
Reviewed-on: https://team-review.git.corp.google.com/c/golang/discovery/+/443102
Reviewed-by: Megan O'Keefe <mokeefe@google.com>
Reviewed-by: Channing Kimble-Brown <ckimblebrown@google.com>
2020-03-27 16:46:34 -04:00
Channing Kimble-Brown cf00ac867d internal/postgres: check parsing errors & fix patch parsing
This CL adds error checking for the semver parsing in InsertVersion.
It also fixes patch parsing so that it properly isolates the number
string when there is a prerelease.

Fixes b/129717943

Change-Id: I542b533d9508027917b1f9fa63867607b31d23fc
Reviewed-on: https://team-review.git.corp.google.com/c/golang/discovery/+/443170
Reviewed-by: Julie Qiu <julieqiu@google.com>
2020-03-27 16:46:34 -04:00
Julie Qiu 0c16a4b73e migrations: change documents schema
New schema for the documents table:

     Column      |            Type             | Collation | Nullable | Default
-----------------+-----------------------------+-----------+----------+---------
 created_at      | timestamp without time zone |           | not null | now()
 package_path    | text                        |           | not null |
 module_path     | text                        |           | not null |
 series_path     | text                        |           | not null |
 package_suffix  | text                        |           | not null |
 version         | text                        |           | not null |
 deleted         | boolean                     |           | not null | false
 name_tokens     | tsvector                    |           | not null |
 path_tokens     | tsvector                    |           | not null |
 synopsis_tokens | tsvector                    |           |          |
 readme_tokens   | tsvector                    |           |          |
Indexes:
    "documents_pkey" PRIMARY KEY, btree (package_path, module_path, version)
Foreign-key constraints:
    "documents_package_path_fkey" FOREIGN KEY (package_path, module_path, version) REFERENCES packages(path, module_path, version)

Change-Id: Iaf6e16abe76b274f849862e4d2fcd8d6a462d7a7
Reviewed-on: https://team-review.git.corp.google.com/c/golang/discovery/+/443089
Reviewed-by: Andrew Bonventre <andybons@google.com>
2020-03-27 16:46:34 -04:00
Julie Qiu bef2e3a3a9 cmd/fetch: deploy fetch service using kubernetes
cmd/fetch/main.go can now be deployed to kubernetes following the
instructions in cmd/fetch/README.md, using the Dockerfile and
deployment.yaml in cmd/fetch.

Change-Id: I22c22ccc40059f999ce3373e4f0a8530feaba3b7
Reviewed-on: https://team-review.git.corp.google.com/c/golang/discovery/+/440415
Reviewed-by: Andrew Bonventre <andybons@google.com>
2020-03-27 16:46:34 -04:00
Channing Kimble-Brown 58c05abaa7 internal/fetch, internal/postgres: ingest package suffix
This CL parses the package path in order to fill the 'suffix'
column in the packages table. There is currently no need to
get the value back from the database, it will be used to
fetch all the versions of a particular package in a series.

Fixes b/129546260

Change-Id: I403220f0d3ad90be4c30b563f1fe38d86a2f31df
Reviewed-on: https://team-review.git.corp.google.com/c/golang/discovery/+/442297
Reviewed-by: Julie Qiu <julieqiu@google.com>
2020-03-27 16:46:34 -04:00
Channing Kimble-Brown df4cb83df4 internal/postgres: add GetTaggedVersions and GetPseudoVersions
GetTaggedVersions and GetPseudoVersions both return a list of
versions for a specific package. These methods will be used
by the frontend to fetch the versions that will be displayed
in the 'versions' tab.

Fixes b/126550849

Change-Id: I169aad79823d67273cb7ab1f3995b700d75e8ac2
Reviewed-on: https://team-review.git.corp.google.com/c/golang/discovery/+/441783
Reviewed-by: Julie Qiu <julieqiu@google.com>
2020-03-27 16:46:34 -04:00
Channing Kimble-Brown bf0b20fb4c migrations: add suffix column to packages table
In order to eventually display all the package versions associated
with a specific series this new package suffix column will allow us
to join the 'packages' and 'modules' tables and fetch all the package
versions with the same package suffix and series name. These versions
will then be listed on the versions tab for the frontend.

Fixes b/129545571

Change-Id: I790187a0ea56cd238c7f88603995ea0fe883ba95
Reviewed-on: https://team-review.git.corp.google.com/c/golang/discovery/+/442289
Reviewed-by: Julie Qiu <julieqiu@google.com>
2020-03-27 16:46:34 -04:00
Julie Qiu 1a323c51c5 discovery: add GCP service account JSON file to .gitignore
Change-Id: I8d7fa5e13d67af93e5ab9208ad9084598bb8a091
Reviewed-on: https://team-review.git.corp.google.com/c/golang/discovery/+/441335
Reviewed-by: Channing Kimble-Brown <ckimblebrown@google.com>
2020-03-27 16:46:34 -04:00
Channing Kimble-Brown c63f17b138 content/static/html, internal/frontend, internal/postgres: fix package header
The module overview page is being updated to be a package
overview page instead. The package header information
has been pulled out into its own struct because that information
will need to be used across various tabs and GetPackage was
updated to also return the module path and readme from the
database.

Fixes b/129020591

Change-Id: I09174c68077b3dc9c27da608b219cabf610639ee
Reviewed-on: https://team-review.git.corp.google.com/c/golang/discovery/+/441334
Reviewed-by: Julie Qiu <julieqiu@google.com>
2020-03-27 16:46:34 -04:00
Julie Qiu 605c59da44 internal: change JSON tag for VersionLog.ModulePath to match proxy index
The proxy index field "Name" is now "Path.

The JSON struct tag for VersionLog.ModulePath is updated to reflect that change.

Change-Id: I4a6488e2c55a9ba6e3fd6943551c2e997b61b42f
Reviewed-on: https://team-review.git.corp.google.com/c/golang/discovery/+/440424
Reviewed-by: Andrew Bonventre <andybons@google.com>
2020-03-27 16:46:34 -04:00
Julie Qiu e3aae5f686 internal/postgres: close prepared statement in InsertVersion
stmt.Close() is called to free any resources used to create a prepared
statement for inserting packages inside postgres.InsertVersion.

Change-Id: I84ca3128af503b343f0b7f811090ddd8cb9226ab
Reviewed-on: https://team-review.git.corp.google.com/c/golang/discovery/+/440425
Reviewed-by: Andrew Bonventre <andybons@google.com>
2020-03-27 16:46:34 -04:00
Julie Qiu 18e6a51c96 migrations: alter documents table for package search
The documents table is changed to allow package search instead of module
search.

New schema:
                                   Table "public.documents"
         Column          |            Type             | Nullable |      Default
-------------------------+-----------------------------+----------+-------------------
 package_path            | text                        | not null |
 version                 | text                        | not null |
 package_name_tokens     | tsvector                    | not null |
 package_synopsis_tokens | tsvector                    |          |
 readme_tokens           | tsvector                    |          |
 created_at              | timestamp without time zone |          | CURRENT_TIMESTAMP
Foreign-key constraints:
    "documents_series_name_fkey" FOREIGN KEY (package_path) REFERENCES series(path)

Old schema:

 Table "public.documents"
         Column          |            Type             | Nullable |      Default
-------------------------+-----------------------------+----------+-------------------
 series_name             | text                        | not null |
 version                 | text                        | not null |
 package_name_tokens     | tsvector                    |          |
 package_synopsis_tokens | tsvector                    |          |
 readme_tokens           | tsvector                    |          |
 created_at              | timestamp without time zone |          | CURRENT_TIMESTAMP
 name                    | text                        | not null |
 name_tokens             | tsvector                    |          |
 module_synopsis_tokens  | tsvector                    |          |
Foreign-key constraints:
    "documents_series_name_fkey" FOREIGN KEY (series_name) REFERENCES series(path)

Change-Id: I7c621d71241e36cb854c90c7f003192a7b4cc50f
Reviewed-on: https://team-review.git.corp.google.com/c/golang/discovery/+/440418
Reviewed-by: Channing Kimble-Brown <ckimblebrown@google.com>
Reviewed-by: Andrew Bonventre <andybons@google.com>
2020-03-27 16:46:34 -04:00
Channing Kimble-Brown c0af4a6bb5 internal/postgres, internal/fetch, internal/frontend: check module path is valid
InsertVersion now checks to make sure that the module path is valid
before inserting a version into the database.

parseModulePathAndVersion now checks the module path and returns an
error if the path is invalid.

FetchAndInsertVersion also ensures the module path is valid before
calling InsertVersion.

Fixes b/129269917

Change-Id: I1f9446a671b9af29e48b7cc5554007fda657662a
Reviewed-on: https://team-review.git.corp.google.com/c/golang/discovery/+/440419
Reviewed-by: Julie Qiu <julieqiu@google.com>
2020-03-27 16:46:34 -04:00
Channing Kimble-Brown c2e51712c3 internal/postgres: add GetLatestPackageForPaths
This change adds GetLatestPackageForPaths which returns the latest
package associated with each path in a list of strings. This method
will eventually be used to get the packages queried by search results.

Updates b/124308701
Fixes b/126714352

Change-Id: I2b6e86aec7b5ba82ed0e45db52784d3cde1b8074
Reviewed-on: https://team-review.git.corp.google.com/c/golang/discovery/+/439699
Reviewed-by: Julie Qiu <julieqiu@google.com>
2020-03-27 16:46:34 -04:00