From f947e4d7e72c45e9a4199ed191a4396db2ac3c60 Mon Sep 17 00:00:00 2001 From: Runxi Yu Date: Thu, 20 Feb 2025 11:32:52 +0800 Subject: hooks, ssh: Indicate URL of newly-created MRs --- git_hooks_handle.go | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'git_hooks_handle.go') diff --git a/git_hooks_handle.go b/git_hooks_handle.go index 9d037b7..3a8a031 100644 --- a/git_hooks_handle.go +++ b/git_hooks_handle.go @@ -10,6 +10,7 @@ import ( "net" "os" "path/filepath" + "strconv" "strings" "syscall" @@ -131,14 +132,16 @@ func hooks_handle_connection(conn net.Conn) { if strings.HasPrefix(ref_name, "refs/heads/contrib/") { if all_zero_num_string(old_oid) { // New branch fmt.Fprintln(ssh_stderr, ansiec.Blue + "POK" + ansiec.Reset, ref_name) - _, err = database.Exec(ctx, - "INSERT INTO merge_requests (repo_id, creator, source_ref, status) VALUES ($1, $2, $3, 'open')", + var new_mr_id int + err = database.QueryRow(ctx, + "INSERT INTO merge_requests (repo_id, creator, source_ref, status) VALUES ($1, $2, $3, 'open') RETURNING id", pack_to_hook.repo_id, pack_to_hook.user_id, strings.TrimPrefix(ref_name, "refs/heads/"), - ) + ).Scan(&new_mr_id) if err != nil { wf_error(ssh_stderr, "Error creating merge request: %v", err) return 1 } + fmt.Fprintln(ssh_stderr, ansiec.Blue + "Created merge request at", generate_http_remote_url(pack_to_hook.group_name, pack_to_hook.repo_name) + "/contrib/" + strconv.FormatUint(uint64(new_mr_id), 10) + "/" + ansiec.Reset) } else { // Existing contrib branch var existing_merge_request_user_id int err = database.QueryRow(ctx, -- cgit v1.2.3