From b818e495b996c3b797f82973254adcede1246431 Mon Sep 17 00:00:00 2001 From: dusk Date: Sun, 27 Jul 2025 12:43:04 +0300 Subject: [PATCH] hook: get push options and pass them Signed-off-by: dusk --- hook/hook.go | 10 ++++++++++ hook/setup.go | 7 ++++++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/hook/hook.go b/hook/hook.go index f43b594..3383671 100644 --- a/hook/hook.go +++ b/hook/hook.go @@ -36,6 +36,10 @@ func Command() *cli.Command { Usage: "endpoint for the internal API", Value: "http://localhost:5444", }, + &cli.StringSliceFlag{ + Name: "push-option", + Usage: "any push option from git", + }, }, Commands: []*cli.Command{ { @@ -52,6 +56,7 @@ func postRecieve(ctx context.Context, cmd *cli.Command) error { userDid := cmd.String("user-did") userHandle := cmd.String("user-handle") endpoint := cmd.String("internal-api") + pushOptions := cmd.StringSlice("push-option") payloadReader := bufio.NewReader(os.Stdin) payload, _ := payloadReader.ReadString('\n') @@ -67,6 +72,11 @@ func postRecieve(ctx context.Context, cmd *cli.Command) error { req.Header.Set("X-Git-Dir", gitDir) req.Header.Set("X-Git-User-Did", userDid) req.Header.Set("X-Git-User-Handle", userHandle) + if pushOptions != nil { + for _, option := range pushOptions { + req.Header.Add("X-Git-Push-Option", option) + } + } resp, err := client.Do(req) if err != nil { diff --git a/hook/setup.go b/hook/setup.go index 3e6b302..2949560 100644 --- a/hook/setup.go +++ b/hook/setup.go @@ -133,7 +133,12 @@ func mkHook(config config, hookPath string) error { hookContent := fmt.Sprintf(`#!/usr/bin/env bash # AUTO GENERATED BY KNOT, DO NOT MODIFY -%s hook -git-dir "$GIT_DIR" -user-did "$GIT_USER_DID" -user-handle "$GIT_USER_HANDLE" -internal-api "%s" post-recieve +push_options=() +for ((i=0; i Date: Sun, 27 Jul 2025 12:44:58 +0300 Subject: [PATCH] knotserver: internal: extract push options from the headers, and implement skipping ci if skip-ci or ci-skip is passed Signed-off-by: dusk --- knotserver/internal.go | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/knotserver/internal.go b/knotserver/internal.go index 9450e87..143a517 100644 --- a/knotserver/internal.go +++ b/knotserver/internal.go @@ -64,6 +64,10 @@ func (h *InternalHandle) InternalKeys(w http.ResponseWriter, r *http.Request) { return } +type PushOptions struct { + skipCi bool +} + func (h *InternalHandle) PostReceiveHook(w http.ResponseWriter, r *http.Request) { l := h.l.With("handler", "PostReceiveHook") @@ -90,6 +94,15 @@ func (h *InternalHandle) PostReceiveHook(w http.ResponseWriter, r *http.Request) // non-fatal } + // extract any push options + pushOptionsRaw := r.Header.Values("X-Git-Push-Option") + pushOptions := PushOptions{} + for _, option := range pushOptionsRaw { + if option == "skip-ci" || option == "ci-skip" { + pushOptions.skipCi = true + } + } + for _, line := range lines { err := h.insertRefUpdate(line, gitUserDid, repoDid, repoName) if err != nil { @@ -97,7 +110,7 @@ func (h *InternalHandle) PostReceiveHook(w http.ResponseWriter, r *http.Request) // non-fatal } - err = h.triggerPipeline(line, gitUserDid, repoDid, repoName) + err = h.triggerPipeline(line, gitUserDid, repoDid, repoName, pushOptions) if err != nil { l.Error("failed to trigger pipeline", "err", err, "line", line, "did", gitUserDid, "repo", gitRelativeDir) // non-fatal @@ -148,7 +161,11 @@ func (h *InternalHandle) insertRefUpdate(line git.PostReceiveLine, gitUserDid, r return h.db.InsertEvent(event, h.n) } -func (h *InternalHandle) triggerPipeline(line git.PostReceiveLine, gitUserDid, repoDid, repoName string) error { +func (h *InternalHandle) triggerPipeline(line git.PostReceiveLine, gitUserDid, repoDid, repoName string, pushOptions PushOptions) error { + if pushOptions.skipCi { + return nil + } + didSlashRepo, err := securejoin.SecureJoin(repoDid, repoName) if err != nil { return err -- 2.43.0