@@ -35,87 +35,87 @@ private static int Main(string[] args)
3535 args ,
3636 options ,
3737 ( verb , subOptions ) =>
38- {
39- result = 1 ;
38+ {
39+ result = 1 ;
4040
41- var baseSubOptions = subOptions as BaseSubOptions ;
42- if ( baseSubOptions != null )
41+ var baseSubOptions = subOptions as BaseSubOptions ;
42+ if ( baseSubOptions != null )
43+ {
44+ if ( string . IsNullOrEmpty ( baseSubOptions . TargetDirectory ) )
4345 {
44- if ( string . IsNullOrEmpty ( baseSubOptions . TargetPath ) )
45- {
46- baseSubOptions . TargetPath = Environment . CurrentDirectory ;
47- }
48-
49- ConfigureLogging ( baseSubOptions . LogFilePath ) ;
46+ baseSubOptions . TargetDirectory = Environment . CurrentDirectory ;
5047 }
5148
52- var fileSystem = new FileSystem ( ) ;
49+ ConfigureLogging ( baseSubOptions . LogFilePath ) ;
50+ }
51+
52+ var fileSystem = new FileSystem ( ) ;
5353
54- if ( verb == "create" )
54+ if ( verb == "create" )
55+ {
56+ var createSubOptions = baseSubOptions as CreateSubOptions ;
57+ if ( createSubOptions != null )
5558 {
56- var createSubOptions = baseSubOptions as CreateSubOptions ;
57- if ( createSubOptions != null )
58- {
59- result = CreateReleaseAsync ( createSubOptions , fileSystem ) . Result ;
60- }
59+ result = CreateReleaseAsync ( createSubOptions , fileSystem ) . Result ;
6160 }
61+ }
6262
63- if ( verb == "addasset" )
63+ if ( verb == "addasset" )
64+ {
65+ var addAssetSubOptions = baseSubOptions as AddAssetSubOptions ;
66+ if ( addAssetSubOptions != null )
6467 {
65- var addAssetSubOptions = baseSubOptions as AddAssetSubOptions ;
66- if ( addAssetSubOptions != null )
67- {
68- result = AddAssetsAsync ( addAssetSubOptions ) . Result ;
69- }
68+ result = AddAssetsAsync ( addAssetSubOptions ) . Result ;
7069 }
70+ }
7171
72- if ( verb == "close" )
72+ if ( verb == "close" )
73+ {
74+ var closeSubOptions = baseSubOptions as CloseSubOptions ;
75+ if ( closeSubOptions != null )
7376 {
74- var closeSubOptions = baseSubOptions as CloseSubOptions ;
75- if ( closeSubOptions != null )
76- {
77- result = CloseMilestoneAsync ( closeSubOptions ) . Result ;
78- }
77+ result = CloseMilestoneAsync ( closeSubOptions ) . Result ;
7978 }
79+ }
8080
81- if ( verb == "publish" )
81+ if ( verb == "publish" )
82+ {
83+ var publishSubOptions = baseSubOptions as PublishSubOptions ;
84+ if ( publishSubOptions != null )
8285 {
83- var publishSubOptions = baseSubOptions as PublishSubOptions ;
84- if ( publishSubOptions != null )
85- {
86- result = CloseAndPublishReleaseAsync ( publishSubOptions ) . Result ;
87- }
86+ result = PublishReleaseAsync ( publishSubOptions ) . Result ;
8887 }
88+ }
8989
90- if ( verb == "export" )
90+ if ( verb == "export" )
91+ {
92+ var exportSubOptions = baseSubOptions as ExportSubOptions ;
93+ if ( exportSubOptions != null )
9194 {
92- var exportSubOptions = baseSubOptions as ExportSubOptions ;
93- if ( exportSubOptions != null )
94- {
95- result = ExportReleasesAsync ( exportSubOptions , fileSystem ) . Result ;
96- }
95+ result = ExportReleasesAsync ( exportSubOptions , fileSystem ) . Result ;
9796 }
97+ }
9898
99- if ( verb == "init" )
99+ if ( verb == "init" )
100+ {
101+ var initSubOptions = baseSubOptions as InitSubOptions ;
102+ if ( initSubOptions != null )
100103 {
101- var initSubOptions = baseSubOptions as InitSubOptions ;
102- if ( initSubOptions != null )
103- {
104- ConfigurationProvider . WriteSample ( initSubOptions . TargetPath , fileSystem ) ;
105- result = 0 ;
106- }
104+ ConfigurationProvider . WriteSample ( initSubOptions . TargetDirectory , fileSystem ) ;
105+ result = 0 ;
107106 }
107+ }
108108
109- if ( verb == "showconfig" )
109+ if ( verb == "showconfig" )
110+ {
111+ var showConfigSubOptions = baseSubOptions as ShowConfigSubOptions ;
112+ if ( showConfigSubOptions != null )
110113 {
111- var showConfigSubOptions = baseSubOptions as ShowConfigSubOptions ;
112- if ( showConfigSubOptions != null )
113- {
114- Console . WriteLine ( ConfigurationProvider . GetEffectiveConfigAsString ( showConfigSubOptions . TargetPath , fileSystem ) ) ;
115- result = 0 ;
116- }
114+ Console . WriteLine ( ConfigurationProvider . GetEffectiveConfigAsString ( showConfigSubOptions . TargetDirectory , fileSystem ) ) ;
115+ result = 0 ;
117116 }
118- } ) )
117+ }
118+ } ) )
119119 {
120120 return 1 ;
121121 }
@@ -128,9 +128,16 @@ private static async Task<int> CreateReleaseAsync(CreateSubOptions subOptions, I
128128 try
129129 {
130130 var github = subOptions . CreateGitHubClient ( ) ;
131- var configuration = ConfigurationProvider . Provide ( subOptions . TargetPath , fileSystem ) ;
131+ var configuration = ConfigurationProvider . Provide ( subOptions . TargetDirectory , fileSystem ) ;
132132
133- await CreateRelease ( github , subOptions . RepositoryOwner , subOptions . RepositoryName , subOptions . Milestone , subOptions . TargetCommitish , subOptions . AssetPaths , configuration ) ;
133+ if ( string . IsNullOrEmpty ( subOptions . Milestone ) )
134+ {
135+ await CreateReleaseFromMilestone ( github , subOptions . RepositoryOwner , subOptions . RepositoryName , subOptions . Milestone , subOptions . TargetCommitish , subOptions . AssetPaths , configuration ) ;
136+ }
137+ else
138+ {
139+ await CreateReleaseFromInputFile ( github , subOptions . RepositoryOwner , subOptions . RepositoryName , subOptions . Name , subOptions . InputFilePath , subOptions . TargetCommitish , subOptions . AssetPaths , configuration ) ;
140+ }
134141
135142 return 0 ;
136143 }
@@ -148,7 +155,7 @@ private static async Task<int> AddAssetsAsync(AddAssetSubOptions subOptions)
148155 {
149156 var github = subOptions . CreateGitHubClient ( ) ;
150157
151- await AddAssets ( github , subOptions . RepositoryOwner , subOptions . RepositoryName , subOptions . Milestone , subOptions . AssetPaths ) ;
158+ await AddAssets ( github , subOptions . RepositoryOwner , subOptions . RepositoryName , subOptions . TagName , subOptions . AssetPaths ) ;
152159
153160 return 0 ;
154161 }
@@ -178,15 +185,13 @@ private static async Task<int> CloseMilestoneAsync(CloseSubOptions subOptions)
178185 }
179186 }
180187
181- private static async Task < int > CloseAndPublishReleaseAsync ( PublishSubOptions subOptions )
188+ private static async Task < int > PublishReleaseAsync ( PublishSubOptions subOptions )
182189 {
183190 try
184191 {
185192 var github = subOptions . CreateGitHubClient ( ) ;
186193
187- await CloseMilestone ( github , subOptions . RepositoryOwner , subOptions . RepositoryName , subOptions . Milestone ) ;
188-
189- await PublishRelease ( github , subOptions . RepositoryOwner , subOptions . RepositoryName , subOptions . Milestone ) ;
194+ await PublishRelease ( github , subOptions . RepositoryOwner , subOptions . RepositoryName , subOptions . TagName ) ;
190195
191196 return 0 ;
192197 }
@@ -203,7 +208,7 @@ private static async Task<int> ExportReleasesAsync(ExportSubOptions subOptions,
203208 try
204209 {
205210 var github = subOptions . CreateGitHubClient ( ) ;
206- var configuration = ConfigurationProvider . Provide ( subOptions . TargetPath , fileSystem ) ;
211+ var configuration = ConfigurationProvider . Provide ( subOptions . TargetDirectory , fileSystem ) ;
207212
208213 var releasesMarkdown = await ExportReleases ( github , subOptions . RepositoryOwner , subOptions . RepositoryName , configuration ) ;
209214
@@ -222,7 +227,7 @@ private static async Task<int> ExportReleasesAsync(ExportSubOptions subOptions,
222227 }
223228 }
224229
225- private static async Task CreateRelease ( GitHubClient github , string owner , string repository , string milestone , string targetCommitish , IList < string > assets , Config configuration )
230+ private static async Task CreateReleaseFromMilestone ( GitHubClient github , string owner , string repository , string milestone , string targetCommitish , IList < string > assets , Config configuration )
226231 {
227232 var releaseNotesBuilder = new ReleaseNotesBuilder ( new DefaultGitHubClient ( github , owner , repository ) , owner , repository , milestone , configuration ) ;
228233
@@ -260,15 +265,56 @@ private static async Task CreateRelease(GitHubClient github, string owner, strin
260265 }
261266 }
262267
263- private static async Task AddAssets ( GitHubClient github , string owner , string repository , string milestone , IList < string > assetPaths )
268+ private static async Task CreateReleaseFromInputFile ( GitHubClient github , string owner , string repository , string name , string inputFilePath , string targetCommitish , IList < string > assets , Config configuration )
269+ {
270+ if ( ! File . Exists ( inputFilePath ) )
271+ {
272+ throw new ArgumentException ( "Unable to locate input file." ) ;
273+ }
274+
275+ var inputFileContents = File . ReadAllText ( inputFilePath ) ;
276+
277+ var releaseUpdate = new ReleaseUpdate ( name )
278+ {
279+ Draft = true ,
280+ Body = inputFileContents ,
281+ Name = name
282+ } ;
283+
284+ if ( ! string . IsNullOrEmpty ( targetCommitish ) )
285+ {
286+ releaseUpdate . TargetCommitish = targetCommitish ;
287+ }
288+
289+ var release = await github . Release . Create ( owner , repository , releaseUpdate ) ;
290+
291+ foreach ( var asset in assets )
292+ {
293+ if ( ! File . Exists ( asset ) )
294+ {
295+ continue ;
296+ }
297+
298+ var upload = new ReleaseAssetUpload
299+ {
300+ FileName = Path . GetFileName ( asset ) ,
301+ ContentType = "application/octet-stream" ,
302+ RawData = File . Open ( asset , FileMode . Open )
303+ } ;
304+
305+ await github . Release . UploadAsset ( release , upload ) ;
306+ }
307+ }
308+
309+ private static async Task AddAssets ( GitHubClient github , string owner , string repository , string tagName , IList < string > assetPaths )
264310 {
265311 var releases = await github . Release . GetAll ( owner , repository ) ;
266312
267- var release = releases . FirstOrDefault ( r => r . TagName == milestone ) ;
313+ var release = releases . FirstOrDefault ( r => r . TagName == tagName ) ;
268314
269315 if ( release == null )
270316 {
271- Logger . WriteError ( "Unable to find Release with specified milestone " ) ;
317+ Logger . WriteError ( "Unable to find Release with specified tagName " ) ;
272318 return ;
273319 }
274320
@@ -312,17 +358,17 @@ private static async Task CloseMilestone(GitHubClient github, string owner, stri
312358 await milestoneClient . Update ( owner , repository , milestone . Number , new MilestoneUpdate { State = ItemState . Closed } ) ;
313359 }
314360
315- private static async Task PublishRelease ( GitHubClient github , string owner , string repository , string milestone )
361+ private static async Task PublishRelease ( GitHubClient github , string owner , string repository , string tagName )
316362 {
317363 var releases = await github . Release . GetAll ( owner , repository ) ;
318- var release = releases . FirstOrDefault ( r => r . Name == milestone ) ;
364+ var release = releases . FirstOrDefault ( r => r . TagName == tagName ) ;
319365
320366 if ( release == null )
321367 {
322368 return ;
323369 }
324370
325- var releaseUpdate = new ReleaseUpdate ( milestone )
371+ var releaseUpdate = new ReleaseUpdate ( tagName )
326372 {
327373 Draft = false
328374 } ;
0 commit comments