@@ -15,7 +15,6 @@ import (
15
15
"time"
16
16
17
17
"github.com/google/uuid"
18
- "github.com/pb33f/libopenapi/index"
19
18
"github.com/pb33f/openapi-changes/git"
20
19
htmlReport "github.com/pb33f/openapi-changes/html-report"
21
20
"github.com/pb33f/openapi-changes/model"
@@ -180,18 +179,7 @@ func GetHTMLReportCommand() *cobra.Command {
180
179
if len (report ) <= 0 && er != nil {
181
180
return er [0 ]
182
181
}
183
- if len (report ) > 0 {
184
- err = os .WriteFile (reportFile , report , 0664 )
185
- if err != nil {
186
- pterm .Error .Println (err .Error ())
187
- return err
188
- }
189
- pterm .Success .Printf ("%s report written to file '%s' (%s)" , reportFile , specUrl .String (),
190
- index .HumanFileSize (float64 (len (report ))))
191
- pterm .Println ()
192
- pterm .Println ()
193
- }
194
- return nil
182
+ return writeReportFile (err , reportFile , report )
195
183
}
196
184
197
185
} else {
@@ -243,15 +231,9 @@ func GetHTMLReportCommand() *cobra.Command {
243
231
return er [0 ]
244
232
}
245
233
246
- err = os .WriteFile (reportFile , report , 0744 )
247
- if err != nil {
248
- pterm .Error .Println (err .Error ())
249
- return err
250
- }
251
- pterm .Success .Printf ("report written to file '%s' (%dkb)" , reportFile , len (report )/ 1024 )
252
- pterm .Println ()
253
- pterm .Println ()
254
- return nil
234
+ err1 := writeReportFile (err , reportFile , report )
235
+
236
+ return err1
255
237
256
238
} else {
257
239
go listenForUpdates (updateChan , errorChan )
@@ -279,11 +261,7 @@ func GetHTMLReportCommand() *cobra.Command {
279
261
return errors .New ("unable to process specifications" )
280
262
}
281
263
282
- err = os .WriteFile (reportFile , report , 0744 )
283
- pterm .Success .Printf ("report written to file '%s' (%dkb)" , reportFile , len (report )/ 1024 )
284
- pterm .Println ()
285
- pterm .Println ()
286
- return nil
264
+ return writeReportFile (err , reportFile , report )
287
265
}
288
266
}
289
267
pterm .Error .Println ("wrong number of arguments, expecting two (2)" )
@@ -297,6 +275,18 @@ func GetHTMLReportCommand() *cobra.Command {
297
275
return cmd
298
276
}
299
277
278
+ func writeReportFile (err error , reportFile string , report []byte ) error {
279
+ err = os .WriteFile (reportFile , report , 0744 )
280
+ if err != nil {
281
+ pterm .Error .Println (err .Error ())
282
+ return err
283
+ }
284
+ pterm .Success .Printf ("report written to file '%s' (%dkb)" , reportFile , len (report )/ 1024 )
285
+ pterm .Println ()
286
+ pterm .Println ()
287
+ return nil
288
+ }
289
+
300
290
func ExtractGithubDetailsFromURL (url * url.URL ) (string , string , string , error ) {
301
291
path := url .Path
302
292
dir , file := filepath .Split (path )
0 commit comments