The new Ripple frontend.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

loadchangelog.go 1.1KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. package main
  2. import (
  3. "bufio"
  4. "os"
  5. "strconv"
  6. "strings"
  7. "time"
  8. )
  9. type commit struct {
  10. Hash string
  11. UnixTimestamp time.Time
  12. Username string
  13. Subject string
  14. Repository string
  15. }
  16. func createFromString(s string) (c commit) {
  17. var r = strings.SplitN(s, "|", 5)
  18. for i, v := range r {
  19. switch i {
  20. case 0:
  21. c.Hash = v
  22. case 1:
  23. i, err := strconv.ParseInt(v, 10, 64)
  24. if err != nil {
  25. continue
  26. }
  27. c.UnixTimestamp = time.Unix(i, 0)
  28. case 2:
  29. c.Username = v
  30. case 3:
  31. c.Subject = v
  32. case 4:
  33. c.Repository = v
  34. }
  35. }
  36. return
  37. }
  38. func loadChangelog(page int) []commit {
  39. f, err := os.Open(config.MainRippleFolder + "/ci-system/ci-system/changelog.txt")
  40. defer f.Close()
  41. if err != nil {
  42. return nil
  43. }
  44. r := bufio.NewScanner(f)
  45. if page < 0 {
  46. page = 0
  47. } else if page > 50000 {
  48. page = 50000
  49. }
  50. times := (page - 1) * 50
  51. if times < 0 {
  52. times = 0
  53. }
  54. for i := 0; i < times; i++ {
  55. // Discard n lines
  56. r.Scan()
  57. }
  58. comms := make([]commit, 0, 50)
  59. for i := 0; r.Scan() && i < 50; i++ {
  60. s := r.Text()
  61. comms = append(comms, createFromString(s))
  62. }
  63. return comms
  64. }