summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorxengineering <me@xengineering.eu>2023-08-30 21:19:41 +0200
committerxengineering <me@xengineering.eu>2023-09-02 21:24:20 +0200
commite182282eb387d8c73d82e81d2e1fc1aaf5734810 (patch)
treed421fc69fefd71495d6f9d4fadaa8bd7decdf680
parentaee359703596eb7e25abb25062e35396bd4dc352 (diff)
downloadcraft-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.go39
1 files changed, 39 insertions, 0 deletions
diff --git a/main.go b/main.go
new file mode 100644
index 0000000..ae97800
--- /dev/null
+++ b/main.go
@@ -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
+}