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

Feat: Add link to compare release to previous #345

Merged
merged 2 commits into from
Jan 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 8 additions & 6 deletions Source/Bake/Cooking/Cooks/GitHub/GitHubReleaseCook.cs
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,8 @@ public class GitHubReleaseCook : Cook<GitHubReleaseRecipe>
.AppendLine();
}

if (context.Ingredients.Changelog != null && context.Ingredients.Changelog.Any())
if (context.Ingredients.Changelog != null && context.Ingredients.Changelog.Changes.Any())
{


foreach (var a in new[]
{
new {changeType = ChangeType.Other, title = "Changes"},
Expand All @@ -101,7 +99,7 @@ public class GitHubReleaseCook : Cook<GitHubReleaseRecipe>
.AppendLine($"#### {a.title}")
.AppendLine();

foreach (var change in context.Ingredients.Changelog[a.changeType])
foreach (var change in context.Ingredients.Changelog.Changes[a.changeType])
{
stringBuilder.AppendLine($"* {change.Text}");
}
Expand All @@ -110,6 +108,12 @@ public class GitHubReleaseCook : Cook<GitHubReleaseRecipe>
}

stringBuilder.AppendLine();

if (context.Ingredients.GitHub != null)
{
stringBuilder.AppendLine(
$"Full Changelog: {context.Ingredients.GitHub.Url.AbsoluteUri.TrimEnd('/')}/compare/{context.Ingredients.Changelog.PreviousReleaseTag.Sha}...{context.Ingredients.Git!.Sha}");
}
}

var releaseFiles = (await CreateReleaseFilesAsync(additionalFiles, recipe, cancellationToken)).ToList();
Expand Down Expand Up @@ -202,8 +206,6 @@ public class GitHubReleaseCook : Cook<GitHubReleaseRecipe>
}));
}



private static string CalculateArtifactFileName(ExecutableArtifact artifact)
{
var parts = new[]
Expand Down
15 changes: 7 additions & 8 deletions Source/Bake/Cooking/Ingredients/Gathers/ChangelogGather.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,6 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.

using System;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using Bake.Services;
using Bake.ValueObjects;
using Microsoft.Extensions.Logging;
Expand Down Expand Up @@ -75,23 +71,26 @@ public class ChangelogGather : IGather
return;
}

var tag = tags
var previousReleaseTag = tags
.Where(t => t.Version.LegacyVersion < ingredients.Version.LegacyVersion)
.MaxBy(t => t.Version);

if (tag == null)
if (previousReleaseTag == null)
{
_logger.LogInformation("Could not find a su");
ingredients.FailChangelog();
return;
}

var pullRequests = await _gitHub.GetPullRequestsAsync(
tag.Sha,
previousReleaseTag.Sha,
gitInformation.Sha,
gitHubInformation, cancellationToken);

ingredients.Changelog = _changeLogBuilder.Build(pullRequests);
var changes = _changeLogBuilder.Build(pullRequests);
ingredients.Changelog = new ChangeLog(
previousReleaseTag,
changes);
}
}
}
38 changes: 38 additions & 0 deletions Source/Bake/ValueObjects/ChangeLog.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// MIT License
//
// Copyright (c) 2021-2024 Rasmus Mikkelsen
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.

namespace Bake.ValueObjects
{
public class ChangeLog
{
public Tag PreviousReleaseTag { get; }
public IReadOnlyDictionary<ChangeType, IReadOnlyCollection<Change>> Changes { get; }

public ChangeLog(
Tag previousReleaseTag,
IReadOnlyDictionary<ChangeType, IReadOnlyCollection<Change>> changes)
{
PreviousReleaseTag = previousReleaseTag;
Changes = changes;
}
}
}
6 changes: 3 additions & 3 deletions Source/Bake/ValueObjects/Ingredients.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public class Ingredients
public List<Destination> Destinations { get; [Obsolete] set; } = new();

[YamlMember]
public IReadOnlyDictionary<ChangeType, IReadOnlyCollection<Change>>? Changelog
public ChangeLog? Changelog
{
get => _changelog.Task.IsCompletedSuccessfully ? _changelog.Task.Result : null;
set
Expand Down Expand Up @@ -161,15 +161,15 @@ public class Ingredients
public Task<GitHubInformation> GitHubTask => _gitHub.Task;

[YamlIgnore]
public Task<IReadOnlyDictionary<ChangeType, IReadOnlyCollection<Change>>> ChangelogTask => _changelog.Task;
public Task<ChangeLog> ChangelogTask => _changelog.Task;

[YamlIgnore]
public Task<PullRequestInformation> PullRequestTask => _pullRequest.Task;

private readonly TaskCompletionSource<GitInformation> _git = new();
private readonly TaskCompletionSource<ReleaseNotes> _releaseNotes = new();
private readonly TaskCompletionSource<GitHubInformation> _gitHub = new();
private readonly TaskCompletionSource<IReadOnlyDictionary<ChangeType, IReadOnlyCollection<Change>>> _changelog = new();
private readonly TaskCompletionSource<ChangeLog> _changelog = new();
private readonly TaskCompletionSource<Description> _description = new();
private readonly TaskCompletionSource<PullRequestInformation> _pullRequest = new();

Expand Down