@@ -19,69 +19,74 @@ 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
- }
52
- if opts .format == "json" {
53
- data = jsonFormat (data )
47
+ func writeBacklog (issues []* github.Issue , outputFile * os.File ) error {
48
+ var issuesTable [][]string
49
+ for _ , issue := range issues {
50
+ issuesTable = append (issuesTable , []string {issue .GetTitle (), issue .GetURL (), issue .GetUser ().GetLogin ()})
54
51
}
55
- err = os .WriteFile (opts .outputPath + "backlog.json" , []byte (data ), 0644 )
52
+
53
+ markdownTable , err := markdown .NewTableFormatterBuilder ().
54
+ Build ("Title" , "Link to Body" , "Assignee" ).
55
+ Format (issuesTable )
56
56
if err != nil {
57
57
return err
58
58
}
59
- return nil
60
- }
59
+ result := fmt .Sprintf ("# Backlog\n \n There is **%d new open issues** in gnolang/gno since %s\n \n %s" , len (issues ), opts .since , markdownTable )
61
60
62
- func writeCuration (issues []* github.Issue ) error {
63
- err := createOutputDir ()
61
+ _ , err = outputFile .WriteString (result )
64
62
if err != nil {
65
63
return err
66
64
}
65
+ return nil
66
+ }
67
67
68
+ func writeCuration (issues []* github.Issue , outputFile * os.File ) error {
68
69
var issuesTable [][]string
69
70
for _ , issue := range issues {
70
- issuesTable = append (issuesTable , []string {fmt . Sprintf ( "%d" , * issue .Number ), * issue .Title , * issue . HTMLURL })
71
+ issuesTable = append (issuesTable , []string {issue . GetTitle (), issue .GetURL ( ), issue .GetUser (). GetLogin () })
71
72
}
72
- err = os .WriteFile (opts .outputPath + "curation.json" , []byte ("data" ), 0644 )
73
+
74
+ markdownTable , err := markdown .NewTableFormatterBuilder ().
75
+ Build ("Title" , "Link to Body" , "Assignee" ).
76
+ Format (issuesTable )
73
77
if err != nil {
74
78
return err
75
79
}
76
- return nil
77
- }
80
+ result := fmt .Sprintf ("# Curation\n \n There is **%d new issues** in gnolang/awesome-gno since %s\n \n %s" , len (issues ), opts .since , markdownTable )
78
81
79
- func writeTips (data string ) error {
80
- err := createOutputDir ()
82
+ _ , err = outputFile .WriteString (result )
81
83
if err != nil {
82
84
return err
83
85
}
86
+ return nil
87
+ }
84
88
89
+ func writeTips (data string , outputFile * os.File ) error {
85
90
// Format at Markdown format
86
91
var table [][]string
87
92
var tweets TweetSearch
@@ -92,7 +97,7 @@ func writeTips(data string) error {
92
97
authors [user .Id ] = user .Username
93
98
}
94
99
for _ , tweet := range tweets .Data {
95
- table = append (table , []string {authors [tweet .AuthorId ], strings .Replace (tweet .Text , "\n " , "" , - 1 ), tweet .CreatedAt })
100
+ table = append (table , []string {authors [tweet .AuthorId ], strings .Replace (tweet .Text , "\n " , " " , - 1 ), tweet .CreatedAt })
96
101
}
97
102
98
103
//Maybe build our own table formatter
@@ -102,9 +107,9 @@ func writeTips(data string) error {
102
107
if err != nil {
103
108
return err
104
109
}
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 )
110
+ 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
111
107
- err = os . WriteFile ( opts . outputPath + "report.md" , [] byte ( result ), 0644 )
112
+ _ , err = outputFile . WriteString ( result )
108
113
if err != nil {
109
114
return err
110
115
}
0 commit comments