Publish release group after uploading assets.

This commit is contained in:
Kevin Bost
2024-09-28 23:02:41 -07:00
committed by Caelan
parent 78d9706f46
commit e11fb71dfb
4 changed files with 53 additions and 11 deletions

View File

@@ -1,9 +1,4 @@
#if NET6_0_OR_GREATER
#else
using System.Net.Http;
#endif
#nullable enable
#nullable enable
namespace Velopack.Packaging.Flow;
internal sealed class CreateReleaseGroupRequest
@@ -11,4 +6,4 @@ internal sealed class CreateReleaseGroupRequest
public string? PackageId { get; set; }
public string? Version { get; set; }
public string? ChannelIdentifier { get; set; }
}
}

View File

@@ -0,0 +1,20 @@
#nullable enable
using Newtonsoft.Json.Converters;
using Newtonsoft.Json;
namespace Velopack.Packaging.Flow;
internal sealed class UpdateReleaseGroupRequest
{
public string? NotesHtml { get; set; }
public string? NotesMarkdown { get; set; }
public ReleaseGroupState? State { get; set; }
}
[JsonConverter(typeof(StringEnumConverter))]
internal enum ReleaseGroupState
{
Draft,
Published,
Unlisted
}

View File

@@ -3,10 +3,6 @@ using Microsoft.Identity.Client.Extensions.Msal;
using NuGet.Versioning;
using Microsoft.Extensions.Logging;
using System.Text;
using System.IO;
using Markdig.Helpers;
#if NET6_0_OR_GREATER
using System.Net.Http.Json;
@@ -190,6 +186,8 @@ public class VelopackFlowServiceClient(HttpClient HttpClient, ILogger Logger) :
Logger.LogInformation("Uploaded {FileName} installer to Velopack Flow", installerFile);
}
await PublishReleaseGroupAsync(releaseGroup, serviceUrl, cancellationToken);
}
private async Task<ReleaseGroup> CreateReleaseGroupAsync(
@@ -236,6 +234,25 @@ public class VelopackFlowServiceClient(HttpClient HttpClient, ILogger Logger) :
response.EnsureSuccessStatusCode();
}
private async Task<ReleaseGroup> PublishReleaseGroupAsync(
ReleaseGroup releaseGroup, string? velopackBaseUrl, CancellationToken cancellationToken)
{
UpdateReleaseGroupRequest request = new() {
State = ReleaseGroupState.Published
};
var endpoint = GetEndpoint($"v1/releaseGroups/{releaseGroup.Id}", velopackBaseUrl);
var response = await HttpClient.PutAsJsonAsync(endpoint, request, cancellationToken);
if (!response.IsSuccessStatusCode) {
string content = await response.Content.ReadAsStringAsync(cancellationToken);
throw new InvalidOperationException($"Failed to publish release group with id {releaseGroup.Id}.{Environment.NewLine}Response status code: {response.StatusCode}{Environment.NewLine}{content}");
}
return await response.Content.ReadFromJsonAsync<ReleaseGroup>(cancellationToken: cancellationToken)
?? throw new InvalidOperationException($"Failed to publish release group with id {releaseGroup.Id}");
}
private async Task<AuthConfiguration> GetAuthConfigurationAsync(VelopackServiceOptions? options, CancellationToken cancellationToken)
{
if (AuthConfiguration is not null)

View File

@@ -29,6 +29,16 @@ public static class HttpClientExtensions
return await client.PostAsync(requestUri, content, cancellationToken);
}
public static async Task<HttpResponseMessage> PutAsJsonAsync<TValue>(
this HttpClient client,
Uri? requestUri,
TValue value,
CancellationToken cancellationToken = default)
{
var content = new StringContent(Newtonsoft.Json.JsonConvert.SerializeObject(value), Encoding.UTF8, "application/json");
return await client.PutAsync(requestUri, content, cancellationToken);
}
public static async Task<TValue?> ReadFromJsonAsync<TValue>(
this HttpContent content,
CancellationToken cancellationToken = default)