-
Notifications
You must be signed in to change notification settings - Fork 63
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Ability to upload to Generic Packages Repository
- Loading branch information
Showing
12 changed files
with
257 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
using NGitLab.Models; | ||
|
||
namespace NGitLab.Mock.Clients | ||
{ | ||
internal sealed class PackageClient : ClientBase, IPackageClient | ||
{ | ||
public PackageClient(ClientContext context) | ||
: base(context) | ||
{ | ||
} | ||
|
||
public Package Publish(PackagePublish packagePublish) | ||
{ | ||
throw new System.NotImplementedException(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
using System.Threading.Tasks; | ||
using NGitLab.Models; | ||
using NGitLab.Tests.Docker; | ||
using NUnit.Framework; | ||
|
||
namespace NGitLab.Tests | ||
{ | ||
public class PackageTests | ||
{ | ||
[Test] | ||
[NGitLabRetry] | ||
public async Task Test_publish_package() | ||
{ | ||
using var context = await GitLabTestContext.CreateAsync(); | ||
var project = context.CreateProject(); | ||
var packagesClient = context.Client.Packages; | ||
|
||
var packagePublish = new PackagePublish | ||
{ | ||
ProjectId = project.Id, | ||
FileName = "../../../../README.md", | ||
PackageName = "Packages", | ||
PackageVersion = "1.0.0", | ||
Status = "default", | ||
}; | ||
|
||
var package1 = packagesClient.Publish(packagePublish); | ||
|
||
// TODO: What assertions should be put here? | ||
Assert.True(true); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
using NGitLab.Models; | ||
|
||
namespace NGitLab | ||
{ | ||
public interface IPackageClient | ||
{ | ||
/// <summary> | ||
/// Add a package file with the proposed information to the GitLab Generic Package Repository for the selected Project Id. | ||
/// </summary> | ||
/// <param name="packagePublish">The information about the package file to publish.</param> | ||
/// <returns>The package if it was created. Null if not.</returns> | ||
Package Publish(PackagePublish packagePublish); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
using System; | ||
using System.Globalization; | ||
using System.IO; | ||
using NGitLab.Models; | ||
|
||
namespace NGitLab.Impl | ||
{ | ||
public class PackageClient : IPackageClient | ||
{ | ||
private const string PublishPackageUrl = "/projects/{0}/packages/generic/{1}/{2}/{3}?status={4}&select=package_file"; | ||
|
||
private readonly API _api; | ||
|
||
public PackageClient(API api) | ||
{ | ||
_api = api; | ||
} | ||
|
||
public Package Publish(PackagePublish packagePublish) | ||
{ | ||
var fullFilePath = Path.GetFullPath(packagePublish.FileName); | ||
|
||
if (!File.Exists(fullFilePath)) | ||
{ | ||
throw new InvalidOperationException("Can't find file!"); | ||
} | ||
|
||
var formData = new FileContent(File.OpenRead(fullFilePath)); | ||
var packageFile = new FileInfo(fullFilePath); | ||
|
||
return _api.Put().With(formData).To<Package>(string.Format(CultureInfo.InvariantCulture, | ||
PublishPackageUrl, packagePublish.ProjectId, packagePublish.PackageName, packagePublish.PackageVersion, | ||
packageFile.Name, packagePublish.Status)); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
using System.IO; | ||
|
||
namespace NGitLab.Models | ||
{ | ||
public sealed class FileContent | ||
{ | ||
public FileContent(Stream stream) | ||
{ | ||
Stream = stream; | ||
} | ||
|
||
/// <summary> | ||
/// The stream to be uploaded. | ||
/// </summary> | ||
public Stream Stream { get; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
using System; | ||
using System.ComponentModel; | ||
using System.Text.Json.Serialization; | ||
using NGitLab.Impl.Json; | ||
|
||
namespace NGitLab.Models | ||
{ | ||
public class Package | ||
{ | ||
[EditorBrowsable(EditorBrowsableState.Never)] | ||
[JsonIgnore] | ||
public int Id; | ||
|
||
[JsonPropertyName("package_id")] | ||
public int PackageId; | ||
|
||
[JsonPropertyName("created_at")] | ||
[JsonConverter(typeof(DateOnlyConverter))] | ||
public DateTime CreatedAt; | ||
|
||
[JsonPropertyName("updated_at")] | ||
[JsonConverter(typeof(DateOnlyConverter))] | ||
public DateTime? UpdatedAt; | ||
|
||
[JsonPropertyName("size")] | ||
public int Size; | ||
|
||
[JsonPropertyName("file_store")] | ||
public int FileStore; | ||
|
||
[JsonPropertyName("file_md5")] | ||
public string FileMD5; | ||
|
||
[JsonPropertyName("file_sha1")] | ||
public string FileSHA1; | ||
|
||
[JsonPropertyName("file_sha256")] | ||
public string FileSHA256; | ||
|
||
[JsonPropertyName("file_name")] | ||
public string FileName; | ||
|
||
[JsonPropertyName("verification_retry_at")] | ||
[JsonConverter(typeof(DateOnlyConverter))] | ||
public DateTime? VerificationRetryAt; | ||
|
||
[JsonPropertyName("verified_at")] | ||
[JsonConverter(typeof(DateOnlyConverter))] | ||
public DateTime? VerifiedAt; | ||
|
||
[JsonPropertyName("verification_failure")] | ||
public string VerificationFailure; | ||
|
||
[JsonPropertyName("verification_retry_count")] | ||
public string VerificationRetryCount; | ||
|
||
[JsonPropertyName("verification_checksum")] | ||
public string VerificationChecksum; | ||
|
||
[JsonPropertyName("verification_state")] | ||
public int VerificationState; | ||
|
||
[JsonPropertyName("verification_started_at")] | ||
[JsonConverter(typeof(DateOnlyConverter))] | ||
public DateTime? VerificationStartedAt; | ||
|
||
[JsonPropertyName("new_file_path")] | ||
public string NewFilePath; | ||
|
||
[JsonPropertyName("status")] | ||
public string Status; | ||
|
||
[JsonPropertyName("file")] | ||
public PackageFile File; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
using System.Text.Json.Serialization; | ||
|
||
namespace NGitLab.Models | ||
{ | ||
public class PackageFile | ||
{ | ||
[JsonPropertyName("url")] | ||
public string Url; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
using System.ComponentModel.DataAnnotations; | ||
using System.Text.Json.Serialization; | ||
|
||
namespace NGitLab.Models | ||
{ | ||
public class PackagePublish | ||
{ | ||
[Required] | ||
[JsonPropertyName("id")] | ||
public int ProjectId; | ||
|
||
[Required] | ||
[JsonPropertyName("package_name")] | ||
public string PackageName; | ||
|
||
[Required] | ||
[JsonPropertyName("package_version")] | ||
public string PackageVersion; | ||
|
||
[Required] | ||
[JsonPropertyName("file_name")] | ||
public string FileName; | ||
|
||
[JsonPropertyName("status")] | ||
public string Status; | ||
|
||
[JsonPropertyName("select")] | ||
public string Select; | ||
} | ||
} |