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

Add GetPublishedAtAsync to BaseProjectManager #334

Merged
merged 7 commits into from
Apr 26, 2022

Conversation

jpinz
Copy link
Member

@jpinz jpinz commented Apr 26, 2022

It returns the DateTime of a given purl (with a specified version) for when it was published. Or returns null if it couldn't be found.
For CFS we are using this data, so having a direct method to get it vs calling GetPackageMetadata and only keeping the time would help. If you disagree no worries and we can just do that, this was just a fairly easy thing to whip up.

Also, NPMProjectManager wasn't setting UploadTime in the GetPackageMetadata call.

…rns the DateTime of a given purl (with a specified version) for when it was published. Or returns null if it couldn't be found.
@jpinz jpinz added the enhancement New feature or request label Apr 26, 2022
@jpinz jpinz requested review from gfs and pmalmsten April 26, 2022 15:21
@jpinz jpinz self-assigned this Apr 26, 2022
…the UploadTime property, so I added that functionality as well.
Comment on lines 294 to 304

/// <summary>
/// Gets the <see cref="DateTime"/> a package version was published at.
/// </summary>
/// <param name="purl">Package URL specifying the package. Version is mandatory.</param>
/// <param name="useCache">If the cache should be used when looking for the published time.</param>
/// <returns>The <see cref="DateTime"/> when this version was published, or null if not found.</returns>
public virtual Task<DateTime?> GetPublishedAtAsync(PackageURL purl, bool useCache = true)
{
throw new NotImplementedException("BaseProjectManager does not implement GetPublishedAtAsync.");
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: I wonder whether it would make sense to hold off on adding new methods like this to BaseProjectManager until there is 'critical mass' per se of implementations for them for the specific package managers.

Advertising a method like this for all package managers when it only actually works for a small subset is not a great developer experience to have by default.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I get what you're saying. As far as I see it then we have two options. We have this one. And the other one is the consumer has to cast the BaseProjectManager to one of the 3 that implement the method then they can call it. Personally I would rather do it this way, but what do you think?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CFS is the only consumer of this method today right? And if I recall correctly, we are planning to instantiate the correct type of project manager directly anyway?

If that's true, then BaseProjectManager only really serves callers who want to work with more than one type of package at a time / who do not know which type of project manager instance they are getting. If we don't really have any consumers of this data yet from that perspective, I wonder if that gives us time to hold off on adding it to BaseProjectManager until that use case either materializes, or when we finish implementing this for many/most package managers.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah that's a good point. I will have it in just the ones we need it in.

Copy link
Contributor

@gfs gfs Apr 26, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the published time available in the metadata from the metadata method? The default behavior could be to call the metadata method and then return the time.

Agree though that it should ideally be implemented in some manner on most of the managers to belong in the base.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, and I confirmed it in the unit tests.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems to me the upload time value in the metadata object should already be a DateTime.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I could change it to parse it elsewhere that makes sense. I'll go do it real quick.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about having this in the base, once the metadata is returned as an object?

public async DateTime GetPublishTimeAsync(PackagURL Purl) => await GetMetaDataAsync(Purl)?.PublishTime

This requires having a metadata object be returned

public class Metadata
{
    public DateTime PublishTime {get; set;}
    public string Raw { get; set }
}

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah that can be something we look into when we do the larger rework to Metadata.

Copy link
Contributor

@gfs gfs left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Per comments hold off on the base project manager implementation unless there is good coverage. But keep the methods such that it can be added later to the base.

I think it would make sense to change what is returned from base managers metadata call to be a parsed metadata object rather than the raw string - though the string itself could also be included as a field in the metadata object.

…ersion is always the version on the root object we get when calling GetMetadataAsync because it isn't called on a version (similar to NPM)

This way we can get the latest version as a fallback for GetPackageMetadata without having to parse all the versions and sort through them.
This also allowed me to re-enable the ignored tests for the PyPIProjectManager.
@pmalmsten
Copy link
Contributor

I think it would make sense to change what is returned from base managers metadata call to be a parsed metadata object rather than the raw string - though the string itself could also be included as a field in the metadata object.

+1 to this (though it sounds too big for this PR of course). When callers are writing code against the BaseProjectManager interface, they are most likely trying to work with one or more different types of packages as uniformly as possible, so anything we put on BaseProjectManager should emphasize that desired uniformity (i.e. provide parsed metadata objects as return values, methods should function for all / as many as possible different package managers, etc.)

…ssary work to get the uploadTime, and no longer uses the entire GetPackageMetadataAsync method to just take the one value.
@jpinz
Copy link
Member Author

jpinz commented Apr 26, 2022

I think it would make sense to change what is returned from base managers metadata call to be a parsed metadata object rather than the raw string - though the string itself could also be included as a field in the metadata object.

I've been working on something very close to this, meeting with @bhuwan-agarwal tomorrow to discuss it further.

src/Shared/PackageManagers/NPMProjectManager.cs Outdated Show resolved Hide resolved
This allows us to not have to do the parsing in GetPublishedAtAsync.
@jpinz jpinz merged commit aeb202c into microsoft:main Apr 26, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants