@@ -35,87 +35,87 @@ private static int Main(string[] args)
35
35
args ,
36
36
options ,
37
37
( verb , subOptions ) =>
38
- {
39
- result = 1 ;
38
+ {
39
+ result = 1 ;
40
40
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 ) )
43
45
{
44
- if ( string . IsNullOrEmpty ( baseSubOptions . TargetPath ) )
45
- {
46
- baseSubOptions . TargetPath = Environment . CurrentDirectory ;
47
- }
48
-
49
- ConfigureLogging ( baseSubOptions . LogFilePath ) ;
46
+ baseSubOptions . TargetDirectory = Environment . CurrentDirectory ;
50
47
}
51
48
52
- var fileSystem = new FileSystem ( ) ;
49
+ ConfigureLogging ( baseSubOptions . LogFilePath ) ;
50
+ }
51
+
52
+ var fileSystem = new FileSystem ( ) ;
53
53
54
- if ( verb == "create" )
54
+ if ( verb == "create" )
55
+ {
56
+ var createSubOptions = baseSubOptions as CreateSubOptions ;
57
+ if ( createSubOptions != null )
55
58
{
56
- var createSubOptions = baseSubOptions as CreateSubOptions ;
57
- if ( createSubOptions != null )
58
- {
59
- result = CreateReleaseAsync ( createSubOptions , fileSystem ) . Result ;
60
- }
59
+ result = CreateReleaseAsync ( createSubOptions , fileSystem ) . Result ;
61
60
}
61
+ }
62
62
63
- if ( verb == "addasset" )
63
+ if ( verb == "addasset" )
64
+ {
65
+ var addAssetSubOptions = baseSubOptions as AddAssetSubOptions ;
66
+ if ( addAssetSubOptions != null )
64
67
{
65
- var addAssetSubOptions = baseSubOptions as AddAssetSubOptions ;
66
- if ( addAssetSubOptions != null )
67
- {
68
- result = AddAssetsAsync ( addAssetSubOptions ) . Result ;
69
- }
68
+ result = AddAssetsAsync ( addAssetSubOptions ) . Result ;
70
69
}
70
+ }
71
71
72
- if ( verb == "close" )
72
+ if ( verb == "close" )
73
+ {
74
+ var closeSubOptions = baseSubOptions as CloseSubOptions ;
75
+ if ( closeSubOptions != null )
73
76
{
74
- var closeSubOptions = baseSubOptions as CloseSubOptions ;
75
- if ( closeSubOptions != null )
76
- {
77
- result = CloseMilestoneAsync ( closeSubOptions ) . Result ;
78
- }
77
+ result = CloseMilestoneAsync ( closeSubOptions ) . Result ;
79
78
}
79
+ }
80
80
81
- if ( verb == "publish" )
81
+ if ( verb == "publish" )
82
+ {
83
+ var publishSubOptions = baseSubOptions as PublishSubOptions ;
84
+ if ( publishSubOptions != null )
82
85
{
83
- var publishSubOptions = baseSubOptions as PublishSubOptions ;
84
- if ( publishSubOptions != null )
85
- {
86
- result = CloseAndPublishReleaseAsync ( publishSubOptions ) . Result ;
87
- }
86
+ result = PublishReleaseAsync ( publishSubOptions ) . Result ;
88
87
}
88
+ }
89
89
90
- if ( verb == "export" )
90
+ if ( verb == "export" )
91
+ {
92
+ var exportSubOptions = baseSubOptions as ExportSubOptions ;
93
+ if ( exportSubOptions != null )
91
94
{
92
- var exportSubOptions = baseSubOptions as ExportSubOptions ;
93
- if ( exportSubOptions != null )
94
- {
95
- result = ExportReleasesAsync ( exportSubOptions , fileSystem ) . Result ;
96
- }
95
+ result = ExportReleasesAsync ( exportSubOptions , fileSystem ) . Result ;
97
96
}
97
+ }
98
98
99
- if ( verb == "init" )
99
+ if ( verb == "init" )
100
+ {
101
+ var initSubOptions = baseSubOptions as InitSubOptions ;
102
+ if ( initSubOptions != null )
100
103
{
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 ;
107
106
}
107
+ }
108
108
109
- if ( verb == "showconfig" )
109
+ if ( verb == "showconfig" )
110
+ {
111
+ var showConfigSubOptions = baseSubOptions as ShowConfigSubOptions ;
112
+ if ( showConfigSubOptions != null )
110
113
{
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 ;
117
116
}
118
- } ) )
117
+ }
118
+ } ) )
119
119
{
120
120
return 1 ;
121
121
}
@@ -128,9 +128,16 @@ private static async Task<int> CreateReleaseAsync(CreateSubOptions subOptions, I
128
128
try
129
129
{
130
130
var github = subOptions . CreateGitHubClient ( ) ;
131
- var configuration = ConfigurationProvider . Provide ( subOptions . TargetPath , fileSystem ) ;
131
+ var configuration = ConfigurationProvider . Provide ( subOptions . TargetDirectory , fileSystem ) ;
132
132
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
+ }
134
141
135
142
return 0 ;
136
143
}
@@ -148,7 +155,7 @@ private static async Task<int> AddAssetsAsync(AddAssetSubOptions subOptions)
148
155
{
149
156
var github = subOptions . CreateGitHubClient ( ) ;
150
157
151
- await AddAssets ( github , subOptions . RepositoryOwner , subOptions . RepositoryName , subOptions . Milestone , subOptions . AssetPaths ) ;
158
+ await AddAssets ( github , subOptions . RepositoryOwner , subOptions . RepositoryName , subOptions . TagName , subOptions . AssetPaths ) ;
152
159
153
160
return 0 ;
154
161
}
@@ -178,15 +185,13 @@ private static async Task<int> CloseMilestoneAsync(CloseSubOptions subOptions)
178
185
}
179
186
}
180
187
181
- private static async Task < int > CloseAndPublishReleaseAsync ( PublishSubOptions subOptions )
188
+ private static async Task < int > PublishReleaseAsync ( PublishSubOptions subOptions )
182
189
{
183
190
try
184
191
{
185
192
var github = subOptions . CreateGitHubClient ( ) ;
186
193
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 ) ;
190
195
191
196
return 0 ;
192
197
}
@@ -203,7 +208,7 @@ private static async Task<int> ExportReleasesAsync(ExportSubOptions subOptions,
203
208
try
204
209
{
205
210
var github = subOptions . CreateGitHubClient ( ) ;
206
- var configuration = ConfigurationProvider . Provide ( subOptions . TargetPath , fileSystem ) ;
211
+ var configuration = ConfigurationProvider . Provide ( subOptions . TargetDirectory , fileSystem ) ;
207
212
208
213
var releasesMarkdown = await ExportReleases ( github , subOptions . RepositoryOwner , subOptions . RepositoryName , configuration ) ;
209
214
@@ -222,7 +227,7 @@ private static async Task<int> ExportReleasesAsync(ExportSubOptions subOptions,
222
227
}
223
228
}
224
229
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 )
226
231
{
227
232
var releaseNotesBuilder = new ReleaseNotesBuilder ( new DefaultGitHubClient ( github , owner , repository ) , owner , repository , milestone , configuration ) ;
228
233
@@ -260,15 +265,56 @@ private static async Task CreateRelease(GitHubClient github, string owner, strin
260
265
}
261
266
}
262
267
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 )
264
310
{
265
311
var releases = await github . Release . GetAll ( owner , repository ) ;
266
312
267
- var release = releases . FirstOrDefault ( r => r . TagName == milestone ) ;
313
+ var release = releases . FirstOrDefault ( r => r . TagName == tagName ) ;
268
314
269
315
if ( release == null )
270
316
{
271
- Logger . WriteError ( "Unable to find Release with specified milestone " ) ;
317
+ Logger . WriteError ( "Unable to find Release with specified tagName " ) ;
272
318
return ;
273
319
}
274
320
@@ -312,17 +358,17 @@ private static async Task CloseMilestone(GitHubClient github, string owner, stri
312
358
await milestoneClient . Update ( owner , repository , milestone . Number , new MilestoneUpdate { State = ItemState . Closed } ) ;
313
359
}
314
360
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 )
316
362
{
317
363
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 ) ;
319
365
320
366
if ( release == null )
321
367
{
322
368
return ;
323
369
}
324
370
325
- var releaseUpdate = new ReleaseUpdate ( milestone )
371
+ var releaseUpdate = new ReleaseUpdate ( tagName )
326
372
{
327
373
Draft = false
328
374
} ;
0 commit comments