From c27412e76ea6627d03a57818e116c13ae8687e36 Mon Sep 17 00:00:00 2001 From: Runxi Yu Date: Tue, 18 Feb 2025 22:59:22 +0800 Subject: http: Refactor more handler code duplication into the router --- http_handle_repo_commit.go | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) (limited to 'http_handle_repo_commit.go') diff --git a/http_handle_repo_commit.go b/http_handle_repo_commit.go index f6b73d5..11f16e4 100644 --- a/http_handle_repo_commit.go +++ b/http_handle_repo_commit.go @@ -5,6 +5,7 @@ import ( "net/http" "strings" + "github.com/go-git/go-git/v5" "github.com/go-git/go-git/v5/plumbing" "github.com/go-git/go-git/v5/plumbing/filemode" "github.com/go-git/go-git/v5/plumbing/format/diff" @@ -25,13 +26,8 @@ type usable_chunk struct { } func handle_repo_commit(w http.ResponseWriter, r *http.Request, params map[string]any) { - group_name, repo_name, commit_id_specified_string := params["group_name"].(string), params["repo_name"].(string), params["commit_id"].(string) - repo, description, err := open_git_repo(r.Context(), group_name, repo_name) - if err != nil { - http.Error(w, "Error opening repo: "+err.Error(), http.StatusInternalServerError) - return - } - params["repo_description"] = description + repo, commit_id_specified_string := params["repo"].(*git.Repository), params["commit_id"].(string) + commit_id_specified_string_without_suffix := strings.TrimSuffix(commit_id_specified_string, ".patch") commit_id := plumbing.NewHash(commit_id_specified_string_without_suffix) commit_object, err := repo.CommitObject(commit_id) -- cgit v1.2.3