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]: Support make_latest in create and update release #2757

Merged
merged 1 commit into from
Aug 3, 2023
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 38 additions & 1 deletion Octokit.Tests.Integration/Clients/ReleasesClientTests.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using System.IO;
using System.IO.Compression;
Expand Down Expand Up @@ -55,6 +55,21 @@ public async Task SendsCreateToCorrectUrlWithRepositoryId()
Assert.NotNull(release);
}

[IntegrationTest]
public async Task CreateReleaseAsLatest()
{
var firstReleaseRequest = new NewRelease("0.1") { MakeLatest = MakeLatestQualifier.False };
await _releaseClient.Create(_context.Repository.Id, firstReleaseRequest);

Assert.ThrowsAsync<NotFoundException>(async () => await _releaseClient.GetLatest(_context.RepositoryOwner, _context.RepositoryName));

var secondReleaseRequest = new NewRelease("0.2") { MakeLatest = MakeLatestQualifier.True };
var secondRelease = await _releaseClient.Create(_context.Repository.Id, secondReleaseRequest);

var latestRelease = await _releaseClient.GetLatest(_context.RepositoryOwner, _context.RepositoryName);
Assert.Equal(secondRelease.Id, latestRelease.Id);
}

public void Dispose()
{
_context.Dispose();
Expand Down Expand Up @@ -444,6 +459,28 @@ public async Task CanChangeCommitIshOfReleaseWithRepositoryId()
Assert.Equal(newHead.Object.Sha, updatedRelease.TargetCommitish);
}

[IntegrationTest]
public async Task CanMakeReleaseLatest()
{
var firstReleaseRequest = new NewRelease("0.1");
var firstRelease = await _releaseClient.Create(_context.RepositoryOwner, _context.RepositoryName, firstReleaseRequest);

var secondReleaseRequest = new NewRelease("0.2") { Draft = true };
var secondRelease = await _releaseClient.Create(_context.RepositoryOwner, _context.RepositoryName, secondReleaseRequest);

var latestRelease = await _releaseClient.GetLatest(_context.RepositoryOwner, _context.RepositoryName);
Assert.Equal(firstRelease.Id, latestRelease.Id);

var editRelease = secondRelease.ToUpdate();
editRelease.Draft = false;
editRelease.MakeLatest = MakeLatestQualifier.True;

await _releaseClient.Edit(_context.RepositoryOwner, _context.RepositoryName, secondRelease.Id, editRelease);

latestRelease = await _releaseClient.GetLatest(_context.RepositoryOwner, _context.RepositoryName);
Assert.Equal(secondRelease.Id, latestRelease.Id);
}

public void Dispose()
{
_context.Dispose();
Expand Down
14 changes: 14 additions & 0 deletions Octokit/Models/Request/MakeLatestQualifier.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using Octokit.Internal;

namespace Octokit
{
public enum MakeLatestQualifier
{
[Parameter(Value = "true")]
True = 1,
[Parameter(Value = "false")]
False = 2,
[Parameter(Value = "legacy")]
Legacy = 3,
}
}
10 changes: 10 additions & 0 deletions Octokit/Models/Request/NewRelease.cs
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,16 @@ public NewRelease(string tagName)
/// </value>
public bool GenerateReleaseNotes { get; set; }

/// <summary>
/// Specifies whether this release should be set as the latest release for the repository.
/// Drafts and prereleases cannot be set as latest. Defaults to true for newly published releases.
/// </summary>
/// <value>
/// <c>True</c> set release as latest;
/// <c>Legacy</c> specifies that the latest release should be determined based on the release creation date and higher semantic version.
/// </value>
public MakeLatestQualifier? MakeLatest { get; set; }

internal string DebuggerDisplay
{
get
Expand Down
9 changes: 9 additions & 0 deletions Octokit/Models/Request/ReleaseUpdate.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,15 @@ public class ReleaseUpdate
/// </value>
public bool? Prerelease { get; set; }

/// <summary>
/// Specifies whether this release should be set as the latest release for the repository.
/// Drafts and prereleases cannot be set as latest. Defaults to true for newly published releases.
/// </summary>
/// <value>
/// <c>True</c> set release as latest;
/// <c>Legacy</c> specifies that the latest release should be determined based on the release creation date and higher semantic version.
/// </value>
public MakeLatestQualifier? MakeLatest { get; set; }
internal string DebuggerDisplay
{
get
Expand Down
Loading