-
Notifications
You must be signed in to change notification settings - Fork 54
/
loadchangelog.go
71 lines (64 loc) · 1.09 KB
/
loadchangelog.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
package main
import (
"bufio"
"os"
"strconv"
"strings"
"time"
)
type commit struct {
Hash string
UnixTimestamp time.Time
Username string
Subject string
Repository string
}
func createFromString(s string) (c commit) {
var r = strings.SplitN(s, "|", 5)
for i, v := range r {
switch i {
case 0:
c.Hash = v
case 1:
i, err := strconv.ParseInt(v, 10, 64)
if err != nil {
continue
}
c.UnixTimestamp = time.Unix(i, 0)
case 2:
c.Username = v
case 3:
c.Subject = v
case 4:
c.Repository = v
}
}
return
}
func loadChangelog(page int) []commit {
f, err := os.Open(config.MainRippleFolder + "/ci-system/ci-system/changelog.txt")
defer f.Close()
if err != nil {
return nil
}
r := bufio.NewScanner(f)
if page < 0 {
page = 0
} else if page > 50000 {
page = 50000
}
times := (page - 1) * 50
if times < 0 {
times = 0
}
for i := 0; i < times; i++ {
// Discard n lines
r.Scan()
}
comms := make([]commit, 0, 50)
for i := 0; r.Scan() && i < 50; i++ {
s := r.Text()
comms = append(comms, createFromString(s))
}
return comms
}