@@ -132,11 +132,11 @@ private static async Task<int> CreateReleaseAsync(CreateSubOptions subOptions, I
132132
133133 if ( string . IsNullOrEmpty ( subOptions . Milestone ) )
134134 {
135- await CreateReleaseFromMilestone ( github , subOptions . RepositoryOwner , subOptions . RepositoryName , subOptions . Milestone , subOptions . TargetCommitish , subOptions . AssetPaths , subOptions . PreRelease , configuration ) ;
135+ await CreateReleaseFromMilestone ( github , subOptions . RepositoryOwner , subOptions . RepositoryName , subOptions . Milestone , subOptions . TargetCommitish , subOptions . AssetPaths , subOptions . Prerelease , configuration ) ;
136136 }
137137 else
138138 {
139- await CreateReleaseFromInputFile ( github , subOptions . RepositoryOwner , subOptions . RepositoryName , subOptions . Name , subOptions . InputFilePath , subOptions . TargetCommitish , subOptions . AssetPaths , subOptions . PreRelease , configuration ) ;
139+ await CreateReleaseFromInputFile ( github , subOptions . RepositoryOwner , subOptions . RepositoryName , subOptions . Name , subOptions . InputFilePath , subOptions . TargetCommitish , subOptions . AssetPaths , subOptions . Prerelease ) ;
140140 }
141141
142142 return 0 ;
@@ -227,46 +227,20 @@ private static async Task<int> ExportReleasesAsync(ExportSubOptions subOptions,
227227 }
228228 }
229229
230- private static async Task CreateReleaseFromMilestone ( GitHubClient github , string owner , string repository , string milestone , string targetCommitish , IList < string > assets , bool preRelease , Config configuration )
230+ private static async Task CreateReleaseFromMilestone ( GitHubClient github , string owner , string repository , string milestone , string targetCommitish , IList < string > assets , bool prerelease , Config configuration )
231231 {
232232 var releaseNotesBuilder = new ReleaseNotesBuilder ( new DefaultGitHubClient ( github , owner , repository ) , owner , repository , milestone , configuration ) ;
233233
234234 var result = await releaseNotesBuilder . BuildReleaseNotes ( ) ;
235235
236- var releaseUpdate = new ReleaseUpdate ( milestone )
237- {
238- Draft = true ,
239- Body = result ,
240- Name = milestone ,
241- Prerelease = preRelease
242- } ;
243-
244- if ( ! string . IsNullOrEmpty ( targetCommitish ) )
245- {
246- releaseUpdate . TargetCommitish = targetCommitish ;
247- }
236+ var releaseUpdate = CreateReleaseUpdate ( milestone , result , prerelease , targetCommitish ) ;
248237
249238 var release = await github . Release . Create ( owner , repository , releaseUpdate ) ;
250239
251- foreach ( var asset in assets )
252- {
253- if ( ! File . Exists ( asset ) )
254- {
255- continue ;
256- }
257-
258- var upload = new ReleaseAssetUpload
259- {
260- FileName = Path . GetFileName ( asset ) ,
261- ContentType = "application/octet-stream" ,
262- RawData = File . Open ( asset , FileMode . Open )
263- } ;
264-
265- await github . Release . UploadAsset ( release , upload ) ;
266- }
240+ await AddAssets ( github , assets , release ) ;
267241 }
268242
269- private static async Task CreateReleaseFromInputFile ( GitHubClient github , string owner , string repository , string name , string inputFilePath , string targetCommitish , IList < string > assets , bool preRelease , Config configuration )
243+ private static async Task CreateReleaseFromInputFile ( GitHubClient github , string owner , string repository , string name , string inputFilePath , string targetCommitish , IList < string > assets , bool prerelease )
270244 {
271245 if ( ! File . Exists ( inputFilePath ) )
272246 {
@@ -275,37 +249,11 @@ private static async Task CreateReleaseFromInputFile(GitHubClient github, string
275249
276250 var inputFileContents = File . ReadAllText ( inputFilePath ) ;
277251
278- var releaseUpdate = new ReleaseUpdate ( name )
279- {
280- Draft = true ,
281- Body = inputFileContents ,
282- Name = name ,
283- Prerelease = preRelease
284- } ;
285-
286- if ( ! string . IsNullOrEmpty ( targetCommitish ) )
287- {
288- releaseUpdate . TargetCommitish = targetCommitish ;
289- }
252+ var releaseUpdate = CreateReleaseUpdate ( name , inputFileContents , prerelease , targetCommitish ) ;
290253
291254 var release = await github . Release . Create ( owner , repository , releaseUpdate ) ;
292255
293- foreach ( var asset in assets )
294- {
295- if ( ! File . Exists ( asset ) )
296- {
297- continue ;
298- }
299-
300- var upload = new ReleaseAssetUpload
301- {
302- FileName = Path . GetFileName ( asset ) ,
303- ContentType = "application/octet-stream" ,
304- RawData = File . Open ( asset , FileMode . Open )
305- } ;
306-
307- await github . Release . UploadAsset ( release , upload ) ;
308- }
256+ await AddAssets ( github , assets , release ) ;
309257 }
310258
311259 private static async Task AddAssets ( GitHubClient github , string owner , string repository , string tagName , IList < string > assetPaths )
@@ -378,7 +326,46 @@ private static async Task PublishRelease(GitHubClient github, string owner, stri
378326 await github . Release . Edit ( owner , repository , release . Id , releaseUpdate ) ;
379327 }
380328
381- [ System . Diagnostics . CodeAnalysis . SuppressMessage ( "Microsoft.Design" , "CA1031:DoNotCatchGeneralExceptionTypes" , Justification = "This is required here" ) ]
329+ private static async Task AddAssets ( GitHubClient github , IList < string > assets , Release release )
330+ {
331+ foreach ( var asset in assets )
332+ {
333+ if ( ! File . Exists ( asset ) )
334+ {
335+ continue ;
336+ }
337+
338+ var upload = new ReleaseAssetUpload
339+ {
340+ FileName = Path . GetFileName ( asset ) ,
341+ ContentType = "application/octet-stream" ,
342+ RawData = File . Open ( asset , FileMode . Open )
343+ } ;
344+
345+ await github . Release . UploadAsset ( release , upload ) ;
346+ }
347+ }
348+
349+ private static ReleaseUpdate CreateReleaseUpdate ( string name , string body , bool prerelease , string targetCommitish )
350+ {
351+ var releaseUpdate = new ReleaseUpdate ( name )
352+ {
353+ Draft = true ,
354+ Body = body ,
355+ Name = name ,
356+ Prerelease = prerelease
357+ } ;
358+
359+ if ( ! string . IsNullOrEmpty ( targetCommitish ) )
360+ {
361+ releaseUpdate . TargetCommitish = targetCommitish ;
362+ }
363+
364+ return releaseUpdate ;
365+ }
366+
367+ [ System . Diagnostics . CodeAnalysis . SuppressMessage ( "Microsoft.Reliability" , "CA2000:Dispose objects before losing scope" , Justification = "Not required." ) ]
368+ [ System . Diagnostics . CodeAnalysis . SuppressMessage ( "Microsoft.Design" , "CA1031:DoNotCatchGeneralExceptionTypes" , Justification = "This is required here." ) ]
382369 private static void ConfigureLogging ( string logFilePath )
383370 {
384371 var writeActions = new List < Action < string > >
0 commit comments