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

Ability to upload to Generic Packages Repository #524

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

gep13
Copy link

@gep13 gep13 commented Sep 11, 2023

No description provided.

@gep13
Copy link
Author

gep13 commented Sep 11, 2023

@meziantou I have opened this as draft, based on the comments that you have made here:

#511 (reply in thread)

I would love to get some feedback on what I have done here, and what changes/suggestions you could make.

This is quite a naive implementation based on my own needs, and the information that I could find here:

https://docs.gitlab.com/ee/user/packages/generic_packages/index.html#do-not-allow-duplicate-generic-packages

Thanks!

NGitLab/Models/PackagePublish.cs Outdated Show resolved Hide resolved
NGitLab/IPackageClient.cs Outdated Show resolved Hide resolved
NGitLab/Impl/PackageClient.cs Outdated Show resolved Hide resolved
NGitLab/Impl/PackageClient.cs Outdated Show resolved Hide resolved
NGitLab/Models/PackageFile.cs Show resolved Hide resolved
NGitLab/Models/Package.cs Outdated Show resolved Hide resolved
NGitLab/Models/Package.cs Outdated Show resolved Hide resolved
NGitLab.Tests/PackageTests.cs Outdated Show resolved Hide resolved
@meziantou
Copy link
Contributor

I would love to get some feedback on what I have done here, and what changes/suggestions you could make.

That's a good start! I've added some comments, but the shape is ok

@gep13 gep13 force-pushed the upload-generic-packages branch from e356b33 to 90326d8 Compare September 12, 2023 10:15
throw new System.NotImplementedException();
}

public IEnumerable<PackageSearchResult> Get(int projectId, PackageQuery packageQuery)
Copy link
Author

Choose a reason for hiding this comment

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

@meziantou I couldn't see any prior art for returning an IEnumerable<T> in any of the existing clients. Happy to make a change here, just wanted to make sure that we are on the same page before making any changes.

Copy link
Contributor

Choose a reason for hiding this comment

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

Other implementations use GitLabCollectionResponse<T>. This supports sync and async enumeration!

Copy link
Author

Choose a reason for hiding this comment

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

Ooo! Missed that one! Will get that fixed up just now!

@gep13 gep13 requested a review from meziantou September 12, 2023 10:18
@gep13
Copy link
Author

gep13 commented Sep 12, 2023

@meziantou I have taken a stab at making the changes that you suggested, and I have implemented a couple more methods on the new PackageClient for Get and GetByIdAsync. Let me know if you have any further questions/suggestions.

Side Question... Should I create an issue for this feature addition, or assuming that we move forward with this, are you ok to merge the PR directly, without an associated issue?

@gep13 gep13 force-pushed the upload-generic-packages branch from 90326d8 to cf00481 Compare September 12, 2023 10:20
public class Package
{
[JsonPropertyName("id")]
public int Id { get; set; }
Copy link
Contributor

Choose a reason for hiding this comment

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

New classes should use long for ids

Suggested change
public int Id { get; set; }
public long Id { get; set; }

public int Id { get; set; }

[JsonPropertyName("package_id")]
public int PackageId { get; set; }
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
public int PackageId { get; set; }
public long PackageId { get; set; }

public DateTime? UpdatedAt { get; set; }

[JsonPropertyName("size")]
public int Size { get; set; }
Copy link
Contributor

Choose a reason for hiding this comment

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

File size is a long. I'm not sure GitLab would allow such big files, but you never know

Suggested change
public int Size { get; set; }
public long Size { get; set; }

public int FileStore { get; set; }

[JsonPropertyName("file_md5")]
public string FileMD5 { get; set; }
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
public string FileMD5 { get; set; }
public string FileMd5 { get; set; }

public string FileMD5 { get; set; }

[JsonPropertyName("file_sha1")]
public string FileSHA1 { get; set; }
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
public string FileSHA1 { get; set; }
public string FileSha1 { get; set; }

@@ -0,0 +1,11 @@
namespace NGitLab.Models
{
public enum PackageStatus
Copy link
Contributor

Choose a reason for hiding this comment

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

Use C# name (e.g. Default) and the EnumMember(Value = "")] attribute to map the actual name

Copy link
Author

Choose a reason for hiding this comment

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

Happy to make this change, but I am curious what your suggestion is when it comes to things like this:

https://github.com/ubisoft/NGitLab/pull/524/files#diff-27c124206cca88b65b78a9a2fe44d27dfcc3fab2b510dc692c6507c5cc7d8833R50

url = Utils.AddParameter(url, "status", query.Status);

i.e. when using the Enum value to construct the URL that is requested. With the change that you have suggested in play, the constructed URL doesn't work, as the GitLab server returns an error...

image

Any suggestions?

Copy link
Author

Choose a reason for hiding this comment

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

@meziantou just wanted to follow up on this one. Any ideas on the best course of action here? Thanks!

Copy link
Contributor

Choose a reason for hiding this comment

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

Sorry for the delay. I think the best solution is to improve Utils.AddParameter to better support enums:

public static string AddParameter<T>(string url, string parameterName, T value)
{
    if (typeof(T).IsEnum)
    {
        // TODO
        // Note: ReflectionExtensions.GetEnumMappings can be used as an example
    }

    return Equals(value, null) ? url : AddParameterInternal(url, parameterName, value.ToString());
}

{
public enum PackageType
{
all,
Copy link
Contributor

Choose a reason for hiding this comment

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

Use C# name (e.g. Default) and the EnumMember(Value = "")] attribute to map the actual name

{
public enum PackageSort
{
asc,
Copy link
Contributor

Choose a reason for hiding this comment

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

Use C# name (e.g. Default) and the EnumMember(Value = "")] attribute to map the actual name

_api = api;
}

public Task<Package> PublishAsync(int projectId, PackagePublish packagePublish, CancellationToken cancellationToken = default)
Copy link
Contributor

Choose a reason for hiding this comment

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

Based on the url, I think the method name should be PublishGenericPackageAsync

Suggested change
public Task<Package> PublishAsync(int projectId, PackagePublish packagePublish, CancellationToken cancellationToken = default)
public Task<Package> PublishGenericPackageAsync(int projectId, PackagePublish packagePublish, CancellationToken cancellationToken = default)

PackageName = "Packages",
PackageVersion = "1.0.0",
Status = "default",
PackageStream = File.OpenRead("../../../../README.md"),
Copy link
Contributor

Choose a reason for hiding this comment

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

You'll need to dispose the stream. Also, don't rely on the file system, you can use a MemoryStream to create a dummy content.

@meziantou
Copy link
Contributor

Side Question... Should I create an issue for this feature addition, or assuming that we move forward with this, are you ok to merge the PR directly, without an associated issue?

No need to create an issue

@ap0llo
Copy link
Contributor

ap0llo commented May 3, 2024

Sorry for barging in, but I was actually looking into adding support for GitLab's package registry to NGitLab myself when I saw there is already an open PR.

Is there anything I can do to complete this? I'd be happy to help out

@gep13
Copy link
Author

gep13 commented May 4, 2024

I keep trying to get back to the PR, but I just haven't had the cycles to do it yet ☹️

From memory, all that was remaining was some re-work for the tests to not depend on file system directly.

If you have some time, I have no objections to you creating a PR into my fork, and then I can update this PR.

@ap0llo
Copy link
Contributor

ap0llo commented May 4, 2024

If you have some time, I have no objections to you creating a PR into my fork, and then I can update this PR.

Great, I'll see what I can do

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

Successfully merging this pull request may close these issues.

3 participants