Skip to content

Commit eabc417

Browse files
committed
(GH-50) Added ability to specify multiple assets
- The CommandLineParser has the ability to specify lists of strings in the command line parameters, so let's use that, rather than add individual assets one at a time.
1 parent b17c6e5 commit eabc417

File tree

3 files changed

+37
-14
lines changed

3 files changed

+37
-14
lines changed

Source/GitHubReleaseManager.Cli/Options/AddAssetSubOptions.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,13 @@
66

77
namespace GitHubReleaseManager.Cli.Options
88
{
9+
using System.Collections.Generic;
10+
911
using CommandLine;
1012

1113
public class AddAssetSubOptions : CommonSubOptions
1214
{
13-
[Option('a', "asset", HelpText = "Path to the file to include in the release.", Required = true)]
14-
public string AssetPath { get; set; }
15+
[OptionList('a', "assets", Separator = ',', HelpText = "Paths to the files to include in the release.", Required = true)]
16+
public IList<string> AssetPaths { get; set; }
1517
}
1618
}

Source/GitHubReleaseManager.Cli/Options/CreateSubOptions.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,14 @@
66

77
namespace GitHubReleaseManager.Cli.Options
88
{
9+
using System.Collections.Generic;
10+
911
using CommandLine;
1012

1113
public class CreateSubOptions : CommonSubOptions
1214
{
13-
[Option('a', "asset", HelpText = "Path to the file to include in the release.", Required = false)]
14-
public string AssetPath { get; set; }
15+
[OptionList('a', "assets", Separator = ',', HelpText = "Paths to the files to include in the release.", Required = false)]
16+
public IList<string> AssetPaths { get; set; }
1517

1618
[Option('c', "targetcommitish", HelpText = "The commit to tag. Can be a branch or SHA. Defaults to repository's default branch.", Required = false)]
1719
public string TargetCommitish { get; set; }

Source/GitHubReleaseManager.Cli/Program.cs

Lines changed: 29 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ private static int Main(string[] args)
6565
var addAssetSubOptions = baseSubOptions as AddAssetSubOptions;
6666
if (addAssetSubOptions != null)
6767
{
68-
result = AddAssetAsync(addAssetSubOptions).Result;
68+
result = AddAssetsAsync(addAssetSubOptions).Result;
6969
}
7070
}
7171

@@ -130,7 +130,7 @@ private static async Task<int> CreateReleaseAsync(CreateSubOptions subOptions, I
130130
var github = subOptions.CreateGitHubClient();
131131
var configuration = ConfigurationProvider.Provide(subOptions.TargetPath, fileSystem);
132132

133-
await CreateRelease(github, subOptions.RepositoryOwner, subOptions.RepositoryName, subOptions.Milestone, subOptions.TargetCommitish, subOptions.AssetPath, configuration);
133+
await CreateRelease(github, subOptions.RepositoryOwner, subOptions.RepositoryName, subOptions.Milestone, subOptions.TargetCommitish, subOptions.AssetPaths, configuration);
134134

135135
return 0;
136136
}
@@ -142,13 +142,13 @@ private static async Task<int> CreateReleaseAsync(CreateSubOptions subOptions, I
142142
}
143143
}
144144

145-
private static async Task<int> AddAssetAsync(AddAssetSubOptions subOptions)
145+
private static async Task<int> AddAssetsAsync(AddAssetSubOptions subOptions)
146146
{
147147
try
148148
{
149149
var github = subOptions.CreateGitHubClient();
150150

151-
await AddAsset(github, subOptions.RepositoryOwner, subOptions.RepositoryName, subOptions.Milestone, subOptions.AssetPath);
151+
await AddAssets(github, subOptions.RepositoryOwner, subOptions.RepositoryName, subOptions.Milestone, subOptions.AssetPaths);
152152

153153
return 0;
154154
}
@@ -222,7 +222,6 @@ private static async Task<int> ExportReleasesAsync(ExportSubOptions subOptions,
222222
}
223223
}
224224

225-
private static async Task CreateRelease(GitHubClient github, string owner, string repository, string milestone, string targetCommitish, string asset, Config configuration)
226225
{
227226
var releaseNotesBuilder = new ReleaseNotesBuilder(new DefaultGitHubClient(github, owner, repository), owner, repository, milestone, configuration);
228227

@@ -234,22 +233,32 @@ private static async Task CreateRelease(GitHubClient github, string owner, strin
234233
Body = result,
235234
Name = milestone
236235
};
236+
237237
if (!string.IsNullOrEmpty(targetCommitish))
238238
{
239239
releaseUpdate.TargetCommitish = targetCommitish;
240240
}
241241

242242
var release = await github.Release.Create(owner, repository, releaseUpdate);
243243

244-
if (File.Exists(asset))
244+
foreach (var asset in assets)
245245
{
246-
var upload = new ReleaseAssetUpload { FileName = Path.GetFileName(asset), ContentType = "application/octet-stream", RawData = File.Open(asset, FileMode.Open) };
246+
if (!File.Exists(asset))
247+
{
248+
continue;
249+
}
250+
251+
var upload = new ReleaseAssetUpload
252+
{
253+
FileName = Path.GetFileName(asset),
254+
ContentType = "application/octet-stream",
255+
RawData = File.Open(asset, FileMode.Open)
256+
};
247257

248258
await github.Release.UploadAsset(release, upload);
249259
}
250260
}
251261

252-
private static async Task AddAsset(GitHubClient github, string owner, string repository, string milestone, string assetPath)
253262
{
254263
var releases = await github.Release.GetAll(owner, repository);
255264

@@ -261,9 +270,19 @@ private static async Task AddAsset(GitHubClient github, string owner, string rep
261270
return;
262271
}
263272

264-
if (File.Exists(assetPath))
273+
foreach (var assetPath in assetPaths)
265274
{
266-
var upload = new ReleaseAssetUpload { FileName = Path.GetFileName(assetPath), ContentType = "application/octet-stream", RawData = File.Open(assetPath, FileMode.Open) };
275+
if (!File.Exists(assetPath))
276+
{
277+
continue;
278+
}
279+
280+
var upload = new ReleaseAssetUpload
281+
{
282+
FileName = Path.GetFileName(assetPath),
283+
ContentType = "application/octet-stream",
284+
RawData = File.Open(assetPath, FileMode.Open)
285+
};
267286
await github.Release.UploadAsset(release, upload);
268287
}
269288
}

0 commit comments

Comments
 (0)