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
Closed

Comments

@julieqiu
Copy link
Contributor

@julieqiu 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.

@amarjeetanandsingh
Copy link

@amarjeetanandsingh amarjeetanandsingh commented Jul 3, 2020

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

@julieqiu
Copy link
Contributor Author

@julieqiu 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

@amarjeetanandsingh 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
Contributor Author

@julieqiu 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

@amarjeetanandsingh amarjeetanandsingh commented Jul 4, 2020

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

@amarjeetanandsingh
Copy link

@amarjeetanandsingh 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
Contributor Author

@julieqiu 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

@gopherbot gopherbot commented Jul 10, 2020

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

@gopherbot
Copy link

@gopherbot gopherbot commented Jul 14, 2020

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
3 participants
You can’t perform that action at this time.