Skip to content

Commit 72d623c

Browse files
authored
Merge pull request #484 from jibedoubleve/issue_454
Issue 454: Assets on a draft release can be null
2 parents 013ea64 + ecf921c commit 72d623c

File tree

2 files changed

+44
-3
lines changed

2 files changed

+44
-3
lines changed

src/GitReleaseManager.Core.Tests/VcsServiceTests.cs

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,45 @@ await _vcsProvider.Received(1).CreateReleaseAsync(OWNER, REPOSITORY, Arg.Is<Rele
321321
_logger.Received(1).Debug(Arg.Any<string>(), Arg.Any<Release>());
322322
}
323323

324+
[Test]
325+
public async Task Should_Create_Release_From_Milestone_With_Assets()
326+
{
327+
var release = new Release { Assets = new List<ReleaseAsset>() };
328+
329+
var assetsCount = _assets.Count;
330+
331+
_releaseNotesBuilder.BuildReleaseNotes(OWNER, REPOSITORY, MILESTONE_TITLE, ReleaseTemplates.DEFAULT_NAME)
332+
.Returns(Task.FromResult(RELEASE_NOTES));
333+
334+
_vcsProvider.GetReleaseAsync(OWNER, REPOSITORY, MILESTONE_TITLE)
335+
.Returns(Task.FromResult<Release>(null));
336+
337+
_vcsProvider.CreateReleaseAsync(OWNER, REPOSITORY, Arg.Any<Release>())
338+
.Returns(Task.FromResult(release));
339+
340+
var result = await _vcsService.CreateReleaseFromMilestoneAsync(
341+
OWNER,
342+
REPOSITORY,
343+
MILESTONE_TITLE,
344+
MILESTONE_TITLE,
345+
null,
346+
_assets,
347+
false,
348+
null
349+
).ConfigureAwait(false);
350+
result.ShouldBeSameAs(release);
351+
352+
await _releaseNotesBuilder.Received(1).BuildReleaseNotes(OWNER, REPOSITORY, MILESTONE_TITLE, ReleaseTemplates.DEFAULT_NAME).ConfigureAwait(false);
353+
await _vcsProvider.Received(1).GetReleaseAsync(OWNER, REPOSITORY, MILESTONE_TITLE).ConfigureAwait(false);
354+
await _vcsProvider.Received(1).CreateReleaseAsync(OWNER, REPOSITORY, Arg.Is<Release>(o =>
355+
o.Body == RELEASE_NOTES &&
356+
o.Name == MILESTONE_TITLE &&
357+
o.TagName == MILESTONE_TITLE)).ConfigureAwait(false);
358+
359+
_logger.Received(1).Verbose(Arg.Any<string>(), MILESTONE_TITLE, OWNER, REPOSITORY);
360+
_logger.Received(1).Debug(Arg.Any<string>(), Arg.Any<Release>());
361+
}
362+
324363
[Test]
325364
public async Task Should_Create_Release_From_Milestone_Using_Template_File()
326365
{

src/GitReleaseManager.Core/VcsService.cs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ private async Task<Release> CreateReleaseAsync(string owner, string repository,
101101
await _vcsProvider.UpdateReleaseAsync(owner, repository, release).ConfigureAwait(false);
102102
}
103103

104-
await AddAssetsAsync(owner, repository, tagName, assets).ConfigureAwait(false);
104+
await AddAssetsAsync(owner, repository, tagName, assets, release).ConfigureAwait(false);
105105

106106
return release;
107107
}
@@ -127,13 +127,15 @@ public async Task DiscardReleaseAsync(string owner, string repository, string ta
127127
}
128128
}
129129

130-
public async Task AddAssetsAsync(string owner, string repository, string tagName, IList<string> assets)
130+
public async Task AddAssetsAsync(string owner, string repository, string tagName, IList<string> assets) => await AddAssetsAsync(owner, repository, tagName, assets, null);
131+
132+
private async Task AddAssetsAsync(string owner, string repository, string tagName, IList<string> assets, Release currentRelease)
131133
{
132134
if (assets?.Any() == true)
133135
{
134136
try
135137
{
136-
var release = await _vcsProvider.GetReleaseAsync(owner, repository, tagName).ConfigureAwait(false);
138+
var release = currentRelease ?? await _vcsProvider.GetReleaseAsync(owner, repository, tagName).ConfigureAwait(false);
137139

138140
foreach (var asset in assets)
139141
{

0 commit comments

Comments
 (0)