diff options
author | xengineering <me@xengineering.eu> | 2023-08-30 21:19:41 +0200 |
---|---|---|
committer | xengineering <me@xengineering.eu> | 2023-09-02 21:24:20 +0200 |
commit | e182282eb387d8c73d82e81d2e1fc1aaf5734810 (patch) | |
tree | d421fc69fefd71495d6f9d4fadaa8bd7decdf680 | |
parent | aee359703596eb7e25abb25062e35396bd4dc352 (diff) | |
download | craft-e182282eb387d8c73d82e81d2e1fc1aaf5734810.tar craft-e182282eb387d8c73d82e81d2e1fc1aaf5734810.tar.zst craft-e182282eb387d8c73d82e81d2e1fc1aaf5734810.zip |
Add stdin parsing for Git post-receive hook
The first program for this repsoitory will be a Git post-receive hook
which will be used at any source repository which is registered for
automated builds.
-rw-r--r-- | main.go | 39 |
1 files changed, 39 insertions, 0 deletions
@@ -0,0 +1,39 @@ +package main + +// see `man 5 githooks` for details + +import ( + "errors" + "fmt" + "io" + "log" + "os" +) + +func main() { + for { + fmt.Println(getUpdate()) + } +} + +type update struct { + old, updated, ref string +} + +func (u update) String() string { + ret := fmt.Sprintf("'%s' updated from '%s' to '%s'", u.ref, u.old, u.updated) + return ret +} + +func getUpdate() update { + var u update + _, err := fmt.Scanf("%s %s %s\n", &u.old, &u.updated, &u.ref) + if err != nil { + if errors.Is(err, io.EOF) { + os.Exit(0) + } else { + log.Fatal(err) + } + } + return u +} |