...
1
2
3
4
5
6
7 package main
8
9 import (
10 "bufio"
11 "fmt"
12 "log"
13 "os"
14 "strings"
15 )
16
17 func main() {
18 var line string
19 var suppress bool
20 var foundChange = false
21 var foundSummary = false
22
23
24 fRead, err := os.Open("api-report.txt")
25 if err != nil {
26 log.Fatal(err)
27 }
28
29 defer fRead.Close()
30
31
32 fWrite, err := os.Create("api-report.md")
33 if err != nil {
34 log.Fatal(err)
35 }
36
37 defer fWrite.Close()
38
39 fmt.Fprint(fWrite, "## API Change Report\n")
40
41
42 scanner := bufio.NewScanner(fRead)
43
44 for scanner.Scan() {
45
46 line = scanner.Text()
47 if strings.Index(line, "## ") == 0 {
48 line = "##" + line
49 }
50
51 if strings.Contains(line, "/mongo/integration/") {
52 suppress = true
53 }
54 if strings.Index(line, "# summary") == 0 {
55 suppress = true
56 foundSummary = true
57 }
58
59 if strings.Contains(line, "go.mongodb.org/mongo-driver") {
60 line = strings.Replace(line, "go.mongodb.org/mongo-driver", ".", -1)
61 line = "##" + line
62 }
63 if !suppress {
64 fmt.Fprintf(fWrite, "%s\n", line)
65 foundChange = true
66 }
67 if len(line) == 0 {
68 suppress = false
69 }
70 }
71
72 if !foundChange {
73 fmt.Fprint(fWrite, "No changes found!\n")
74 }
75
76 if !foundSummary {
77 log.Fatal("Could not parse api summary")
78 }
79
80 if err := scanner.Err(); err != nil {
81 log.Fatal(err)
82 }
83
84 }
85
View as plain text