diff options
author | Runxi Yu <me@runxiyu.org> | 2025-02-20 11:32:52 +0800 |
---|---|---|
committer | Runxi Yu <me@runxiyu.org> | 2025-02-20 11:32:52 +0800 |
commit | f947e4d7e72c45e9a4199ed191a4396db2ac3c60 (patch) | |
tree | 3496900b0c11e67f5f38d0cc58b58e58173e3e32 /git_hooks_handle.go | |
parent | hooks: Clarify the last ACK/NAK being overall (diff) | |
download | forge-f947e4d7e72c45e9a4199ed191a4396db2ac3c60.tar.gz forge-f947e4d7e72c45e9a4199ed191a4396db2ac3c60.tar.zst forge-f947e4d7e72c45e9a4199ed191a4396db2ac3c60.zip |
hooks, ssh: Indicate URL of newly-created MRs
Diffstat (limited to 'git_hooks_handle.go')
-rw-r--r-- | git_hooks_handle.go | 9 |
1 files changed, 6 insertions, 3 deletions
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, |