@@ -15,7 +15,6 @@ import (
1515 "time"
1616
1717 "github.com/google/uuid"
18- "github.com/pb33f/libopenapi/index"
1918 "github.com/pb33f/openapi-changes/git"
2019 htmlReport "github.com/pb33f/openapi-changes/html-report"
2120 "github.com/pb33f/openapi-changes/model"
@@ -180,18 +179,7 @@ func GetHTMLReportCommand() *cobra.Command {
180179 if len (report ) <= 0 && er != nil {
181180 return er [0 ]
182181 }
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 )
195183 }
196184
197185 } else {
@@ -243,15 +231,9 @@ func GetHTMLReportCommand() *cobra.Command {
243231 return er [0 ]
244232 }
245233
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
255237
256238 } else {
257239 go listenForUpdates (updateChan , errorChan )
@@ -279,11 +261,7 @@ func GetHTMLReportCommand() *cobra.Command {
279261 return errors .New ("unable to process specifications" )
280262 }
281263
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 )
287265 }
288266 }
289267 pterm .Error .Println ("wrong number of arguments, expecting two (2)" )
@@ -297,6 +275,18 @@ func GetHTMLReportCommand() *cobra.Command {
297275 return cmd
298276}
299277
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+
300290func ExtractGithubDetailsFromURL (url * url.URL ) (string , string , string , error ) {
301291 path := url .Path
302292 dir , file := filepath .Split (path )
0 commit comments