forked from pipeviz/pvgit
/
post_commit.go
43 lines (33 loc) · 919 Bytes
/
post_commit.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
package main
import (
"log"
"github.com/pipeviz/pvgit/Godeps/_workspace/src/github.com/pipeviz/pipeviz/ingest"
"github.com/pipeviz/pvgit/Godeps/_workspace/src/github.com/spf13/cobra"
)
func postCommitHookCommand() *cobra.Command {
cmd := &cobra.Command{
Use: "hook-post-commit",
Short: "Processes a git post-commit hook event.",
Run: runPostCommit,
}
return cmd
}
func runPostCommit(cmd *cobra.Command, args []string) {
repo := getRepoOrExit()
head, err := repo.Head()
if err != nil {
log.Fatalf("Could not get repo HEAD")
}
commit, err := repo.LookupCommit(head.Target())
if err != nil {
log.Fatalf("Could not find commit pointed at by HEAD")
}
ident, err := GetRepoIdent(repo)
if err != nil {
log.Fatalln("Failed to retrieve identifier for repository")
}
m := new(ingest.Message)
m.Add(commitToSemanticForm(commit, ident))
recordHead(m, repo)
sendMapToPipeviz(m, repo)
}