diff options
author | Runxi Yu <me@runxiyu.org> | 2025-02-19 21:34:10 +0800 |
---|---|---|
committer | Runxi Yu <me@runxiyu.org> | 2025-02-19 21:34:10 +0800 |
commit | 48edc5c95924de72a8bbe57f5644138998b0fbbc (patch) | |
tree | 9d637d3442e9629629c28adee2b8d85eedd497c7 /http_handle_repo_contrib_one.go | |
parent | hooks: Don't trim contrib/ when inserting MRs (diff) | |
download | forge-48edc5c95924de72a8bbe57f5644138998b0fbbc.tar.gz forge-48edc5c95924de72a8bbe57f5644138998b0fbbc.tar.zst forge-48edc5c95924de72a8bbe57f5644138998b0fbbc.zip |
repo/contrib/one: Handle when destination branch is null
Diffstat (limited to 'http_handle_repo_contrib_one.go')
-rw-r--r-- | http_handle_repo_contrib_one.go | 18 |
1 files changed, 13 insertions, 5 deletions
diff --git a/http_handle_repo_contrib_one.go b/http_handle_repo_contrib_one.go index 0691050..8926155 100644 --- a/http_handle_repo_contrib_one.go +++ b/http_handle_repo_contrib_one.go @@ -5,6 +5,7 @@ import ( "strconv" "github.com/go-git/go-git/v5" + "github.com/go-git/go-git/v5/plumbing" ) func handle_repo_contrib_one(w http.ResponseWriter, r *http.Request, params map[string]any) { @@ -21,7 +22,6 @@ func handle_repo_contrib_one(w http.ResponseWriter, r *http.Request, params map[ http.Error(w, "Error querying merge request: "+err.Error(), http.StatusInternalServerError) return } - params["mr_title"], params["mr_status"], params["mr_source_ref"], params["mr_destination_branch"] = title, status, source_ref, destination_branch repo := params["repo"].(*git.Repository) @@ -37,10 +37,16 @@ func handle_repo_contrib_one(w http.ResponseWriter, r *http.Request, params map[ } params["source_commit"] = source_commit - destination_branch_hash, err := get_ref_hash_from_type_and_name(repo, "branch", destination_branch) - if err != nil { - http.Error(w, "Error getting destination branch hash: "+err.Error(), http.StatusInternalServerError) - return + var destination_branch_hash plumbing.Hash + if destination_branch == "" { + destination_branch = "HEAD" + destination_branch_hash, err = get_ref_hash_from_type_and_name(repo, "", "") + } else { + destination_branch_hash, err = get_ref_hash_from_type_and_name(repo, "branch", destination_branch) + if err != nil { + http.Error(w, "Error getting destination branch hash: "+err.Error(), http.StatusInternalServerError) + return + } } destination_commit, err := repo.CommitObject(destination_branch_hash) if err != nil { @@ -56,5 +62,7 @@ func handle_repo_contrib_one(w http.ResponseWriter, r *http.Request, params map[ } params["file_patches"] = make_usable_file_patches(patch) + params["mr_title"], params["mr_status"], params["mr_source_ref"], params["mr_destination_branch"] = title, status, source_ref, destination_branch + render_template(w, "repo_contrib_one", params) } |