@@ -19,69 +19,64 @@ func jsonFormat(data string) string {
19
19
return out .String ()
20
20
}
21
21
22
- func createOutputDir () error {
22
+ func createOutputFile () ( * os. File , error ) {
23
23
if _ , err := os .Stat (opts .outputPath ); os .IsNotExist (err ) {
24
24
err = os .MkdirAll (opts .outputPath , os .ModePerm )
25
25
if err != nil {
26
- return err
26
+ return nil , err
27
27
}
28
28
}
29
- return nil
30
- }
31
-
32
- func writeChangelog (data string ) error {
33
- err := createOutputDir ()
29
+ outputFile , err := os .Create (opts .outputPath + "report.md" )
34
30
if err != nil {
35
- return err
31
+ return nil , err
36
32
}
33
+ return outputFile , nil
34
+ }
35
+
36
+ func writeChangelog (data string , outputFile * os.File ) error {
37
37
if opts .format == "json" {
38
38
data = jsonFormat (data )
39
39
}
40
- err = os . WriteFile ( opts . outputPath + "changelog.json" , [] byte ( data ), 0644 )
40
+ _ , err := outputFile . WriteString ( data )
41
41
if err != nil {
42
42
return err
43
43
}
44
44
return nil
45
45
}
46
46
47
- func writeBacklog (data string ) error {
48
- err := createOutputDir ()
49
- if err != nil {
50
- return err
51
- }
47
+ func writeBacklog (data string , outputFile * os.File ) error {
52
48
if opts .format == "json" {
53
49
data = jsonFormat (data )
54
50
}
55
- err = os . WriteFile ( opts . outputPath + "backlog.json" , [] byte ( data ), 0644 )
51
+ _ , err := outputFile . WriteString ( data )
56
52
if err != nil {
57
53
return err
58
54
}
59
55
return nil
60
56
}
61
57
62
- func writeCuration (issues []* github.Issue ) error {
63
- err := createOutputDir ()
64
- if err != nil {
65
- return err
66
- }
67
-
58
+ func writeCuration (issues []* github.Issue , outputFile * os.File ) error {
68
59
var issuesTable [][]string
69
60
for _ , issue := range issues {
70
- issuesTable = append (issuesTable , []string {fmt . Sprintf ( "%d" , * issue .Number ), * issue .Title , * issue . HTMLURL })
61
+ issuesTable = append (issuesTable , []string {issue . GetTitle (), issue .GetURL ( ), issue .GetUser (). GetLogin () })
71
62
}
72
- err = os .WriteFile (opts .outputPath + "curation.json" , []byte ("data" ), 0644 )
63
+
64
+ markdownTable , err := markdown .NewTableFormatterBuilder ().
65
+ Build ("Title" , "Link to Body" , "Assignee" ).
66
+ Format (issuesTable )
73
67
if err != nil {
74
68
return err
75
69
}
76
- return nil
77
- }
70
+ result := fmt .Sprintf ("# Curation\n \n There is **%d new issues** in gno/awesome-gno since %s\n \n %s" , len (issues ), opts .since , markdownTable )
78
71
79
- func writeTips (data string ) error {
80
- err := createOutputDir ()
72
+ _ , err = outputFile .WriteString (result )
81
73
if err != nil {
82
74
return err
83
75
}
76
+ return nil
77
+ }
84
78
79
+ func writeTips (data string , outputFile * os.File ) error {
85
80
// Format at Markdown format
86
81
var table [][]string
87
82
var tweets TweetSearch
@@ -92,7 +87,7 @@ func writeTips(data string) error {
92
87
authors [user .Id ] = user .Username
93
88
}
94
89
for _ , tweet := range tweets .Data {
95
- table = append (table , []string {authors [tweet .AuthorId ], strings .Replace (tweet .Text , "\n " , "" , - 1 ), tweet .CreatedAt })
90
+ table = append (table , []string {authors [tweet .AuthorId ], strings .Replace (tweet .Text , "\n " , " " , - 1 ), tweet .CreatedAt })
96
91
}
97
92
98
93
//Maybe build our own table formatter
@@ -102,9 +97,9 @@ func writeTips(data string) error {
102
97
if err != nil {
103
98
return err
104
99
}
105
- result := fmt .Sprintf ("# Tips\n \n There is **%d new tweet** about gno since %s\n \n %s" , tweets .Meta .ResultCount , opts .since , markdownTable )
100
+ result := fmt .Sprintf ("# Tips\n \n There is **%d new tweet** about gnotips since %s\n \n %s" , tweets .Meta .ResultCount , opts .since , markdownTable )
106
101
107
- err = os . WriteFile ( opts . outputPath + "report.md" , [] byte ( result ), 0644 )
102
+ _ , err = outputFile . WriteString ( result )
108
103
if err != nil {
109
104
return err
110
105
}
0 commit comments