1package git
2
3import (
4 "bufio"
5 "io"
6 "strings"
7)
8
9type PostReceiveLine struct {
10 OldSha string // old sha of reference being updated
11 NewSha string // new sha of reference being updated
12 Ref string // the reference being updated
13}
14
15func ParsePostReceive(buf io.Reader) ([]PostReceiveLine, error) {
16 scanner := bufio.NewScanner(buf)
17 var lines []PostReceiveLine
18 for scanner.Scan() {
19 line := scanner.Text()
20 parts := strings.SplitN(line, " ", 3)
21 if len(parts) != 3 {
22 continue
23 }
24
25 oldSha := parts[0]
26 newSha := parts[1]
27 ref := parts[2]
28
29 lines = append(lines, PostReceiveLine{
30 OldSha: oldSha,
31 NewSha: newSha,
32 Ref: ref,
33 })
34 }
35
36 if err := scanner.Err(); err != nil {
37 return nil, err
38 }
39
40 return lines, nil
41}