Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

x/pkgsite: add postgres.GetLicenses function to return licenses for a given path #40027

Closed
julieqiu opened this issue Jul 3, 2020 · 9 comments
Labels
FrozenDueToAge help wanted NeedsFix The path to resolution is known, but the work has not been done. pkgsite Suggested Issues that may be good for new contributors looking for work to do.
Milestone

Comments

@julieqiu
Copy link
Member

julieqiu commented Jul 3, 2020

As part of the new data model migration (#39629), we will have a single function get licenses for a given path (regardless of whether that path is a package, module, or directory).

This function will replace the existing LegacyGetPackageLicenses and LegacyGetModuleLicenses.

The function signature will be:

GetLicenses(ctx context.Context, fullpath, modulePath, resolvedVersion string)([]*licenses.License, error)

The function will execute the query below:

SELECT
    l.types,
    l.file_path,
    l.contents,
    l.coverage
FROM
    licenses l
INNER JOIN
    paths p
ON
    p.module_id=l.module_id
INNER JOIN
    modules m
ON
    p.module_id=m.id
WHERE
    p.path = $1
    AND m.module_path = $2
    AND m.version = $3;

Only licenses relevant to the path should be returned. A license applies to the path if the license is in the path directory, or any of its parent directories.

@julieqiu julieqiu added Suggested Issues that may be good for new contributors looking for work to do. help wanted NeedsFix The path to resolution is known, but the work has not been done. pkgsite labels Jul 3, 2020
@gopherbot gopherbot added this to the Unreleased milestone Jul 3, 2020
@amarjeetanandsingh
Copy link
Contributor

Hi @julieqiu
If allowed, may I pick this up?

@julieqiu
Copy link
Member Author

julieqiu commented Jul 3, 2020

Please do! :)

@julieqiu julieqiu changed the title x/pkgsite: add GetLicenses function to return licenses for a given path x/pkgsite: add postgres.GetLicenses function to return licenses for a given path Jul 4, 2020
@amarjeetanandsingh
Copy link
Contributor

amarjeetanandsingh commented Jul 4, 2020

Hi @julieqiu
Thanks for allowing me to work on this issue ))

Just to confirm if I understood it correctly, we need to implement -
func (db *DB) GetLicenses(ctx context.Context, fullPath, modulePath, resolvedVersion string) (_ []*licenses.License, err error) {
in internal/postgres/postgres.go file to fetch the list of licenses for given fullPath & modulePath.

I am correct?

If yes, then internal.DataSource interface will have GetLicenses( ) as contract.
As a result, DataSource in internal/proxydatasource will also need an implementation of GetLicenses().

@julieqiu
Copy link
Member Author

julieqiu commented Jul 4, 2020

Thank you for contributing! :)

That is correct. I would add the function to internal/postgres/licenses.go though, as opposed to internal/postgres/postgres.go.

@amarjeetanandsingh
Copy link
Contributor

ohh yeah...
Thanks @julieqiu for correcting me.
Will try to implement tomorrow.

@amarjeetanandsingh
Copy link
Contributor

amarjeetanandsingh commented Jul 4, 2020

@julieqiu
Is there a way to load some initial sample data in my local docker postgres? Any doc you can point to?

@julieqiu
Copy link
Member Author

julieqiu commented Jul 4, 2020

Yup! Check out doc/worker.md#populating-data-locally-using-the-worker for instructions.

By the way, if you have other questions, feel free to reach out in the #pkgsite channel on Gophers Slack!

@gopherbot
Copy link
Contributor

Change https://golang.org/cl/241718 mentions this issue: internal: add GetLicenses by path

@gopherbot
Copy link
Contributor

Change https://golang.org/cl/242617 mentions this issue: internal: add GetLicenses by path

@golang golang locked and limited conversation to collaborators Jul 15, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge help wanted NeedsFix The path to resolution is known, but the work has not been done. pkgsite Suggested Issues that may be good for new contributors looking for work to do.
Projects
None yet
Development

No branches or pull requests

3 participants