示例#1
0
        /// <summary>
        /// Updates an existing GitHub release.
        /// </summary>
        /// <param name="updateRelease">The updated release.</param>
        /// <param name="cancellationToken">
        /// An optional token to monitor for cancellation requests.
        /// </param>
        /// <returns>The updated release.</returns>
        public async Task <Release> UpdateReleaseAsync(
            UpdateRelease updateRelease, CancellationToken cancellationToken = default)
        {
            var octokitRelease = updateRelease.Id.HasValue
                ? await _gitHubApi
                                 .UpdateReleaseAsync(updateRelease.Id.Value, updateRelease.OctokitUpdateRelease)
                                 .ConfigureAwait(false)
                : await _gitHubApi
                                 .UpdateReleaseAsync(updateRelease.CurrentTagName !, updateRelease.OctokitUpdateRelease)
                                 .ConfigureAwait(false);

            var release = new Release(octokitRelease);

            if (updateRelease.DeleteExistingAssets)
            {
                await _gitHubApi.DeleteAllAssetsAsync(octokitRelease.Id, cancellationToken)
                .ConfigureAwait(false);
            }

            foreach (var asset in updateRelease.NewAssets)
            {
                cancellationToken.ThrowIfCancellationRequested();

                var octokitAsset = await _gitHubApi
                                   .UploadAssetAsync(
                    octokitRelease,
                    asset,
                    overwriteExisting :
                    updateRelease.OverwriteExistingAssets &&
                    !updateRelease.DeleteExistingAssets)
                                   .ConfigureAwait(false);

                release.AddAsset(new ReleaseAsset(octokitAsset));
            }

            return(release);
        }