aboutsummaryrefslogtreecommitdiff
path: root/git_hooks_handle.go
diff options
context:
space:
mode:
authorRunxi Yu <me@runxiyu.org>2025-02-19 21:24:47 +0800
committerRunxi Yu <me@runxiyu.org>2025-02-19 21:24:47 +0800
commit114dd59d703d00efe86ad02eb956aa5343daa08e (patch)
tree937eb5579864e6da5a4210fdcf943a7fb15acf07 /git_hooks_handle.go
parentssh/recv, hooks: Create MRs on push, reject pushes to others' MRs (diff)
downloadforge-114dd59d703d00efe86ad02eb956aa5343daa08e.tar.gz
forge-114dd59d703d00efe86ad02eb956aa5343daa08e.tar.zst
forge-114dd59d703d00efe86ad02eb956aa5343daa08e.zip
all: Use COALESCE to handle some nullable database fields
Diffstat (limited to 'git_hooks_handle.go')
-rw-r--r--git_hooks_handle.go7
1 files changed, 6 insertions, 1 deletions
diff --git a/git_hooks_handle.go b/git_hooks_handle.go
index 9dc3ed6..24f8077 100644
--- a/git_hooks_handle.go
+++ b/git_hooks_handle.go
@@ -139,7 +139,7 @@ func hooks_handle_connection(conn net.Conn) {
} else { // Existing contrib branch
var existing_merge_request_user_id int
err = database.QueryRow(ctx,
- "SELECT creator FROM merge_requests WHERE source_ref = $1 AND repo_id = $2",
+ "SELECT COALESCE(creator, 0) FROM merge_requests WHERE source_ref = $1 AND repo_id = $2",
strings.TrimPrefix(ref_name, "refs/heads/contrib/"), pack_to_hook.repo_id,
).Scan(&existing_merge_request_user_id)
if err != nil {
@@ -150,6 +150,11 @@ func hooks_handle_connection(conn net.Conn) {
}
return 1
}
+ if existing_merge_request_user_id == 0 {
+ all_ok = false
+ fmt.Fprintln(ssh_stderr, "Rejecting push to merge request with no owner", ref_name)
+ continue
+ }
if existing_merge_request_user_id != pack_to_hook.user_id {
all_ok = false