forked from mongodb/mongo-go-driver
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
84 lines (70 loc) · 1.68 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
// Copyright (C) MongoDB, Inc. 2023-present.
//
// Licensed under the Apache License, Version 2.0 (the "License"); you may
// not use this file except in compliance with the License. You may obtain
// a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
package main
import (
"bufio"
"fmt"
"log"
"os"
"strings"
)
func main() {
var line string
var suppress bool
var foundChange = false
var foundSummary = false
// open file to read
fRead, err := os.Open("api-report.txt")
if err != nil {
log.Fatal(err)
}
// remember to close the file at the end of the program
defer fRead.Close()
// open file to write
fWrite, err := os.Create("api-report.md")
if err != nil {
log.Fatal(err)
}
// remember to close the file at the end of the program
defer fWrite.Close()
fmt.Fprint(fWrite, "## API Change Report\n")
// read the file line by line using scanner
scanner := bufio.NewScanner(fRead)
for scanner.Scan() {
// do something with a line
line = scanner.Text()
if strings.Index(line, "## ") == 0 {
line = "##" + line
}
if strings.Contains(line, "/mongo/integration/") {
suppress = true
}
if strings.Index(line, "# summary") == 0 {
suppress = true
foundSummary = true
}
if strings.Contains(line, "go.mongodb.org/mongo-driver") {
line = strings.Replace(line, "go.mongodb.org/mongo-driver", ".", -1)
line = "##" + line
}
if !suppress {
fmt.Fprintf(fWrite, "%s\n", line)
foundChange = true
}
if len(line) == 0 {
suppress = false
}
}
if !foundChange {
fmt.Fprint(fWrite, "No changes found!\n")
}
if !foundSummary {
log.Fatal("Could not parse api summary")
}
if err := scanner.Err(); err != nil {
log.Fatal(err)
}
}