Skip to content

Commit

Permalink
[feat]: Support make_latest in create and update release
Browse files Browse the repository at this point in the history
  • Loading branch information
Simplicitdk committed Aug 1, 2023
1 parent bbcd33d commit 28576b8
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 1 deletion.
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

0 comments on commit 28576b8

Please sign in to comment.