aboutsummaryrefslogtreecommitdiff
path: root/http_handle_repo_contrib_one.go
diff options
context:
space:
mode:
authorRunxi Yu <me@runxiyu.org>2025-03-05 09:32:40 +0800
committerRunxi Yu <me@runxiyu.org>2025-03-05 09:47:01 +0800
commit134b84f2672a9fe3e2e8a92b712261b47c4bd022 (patch)
tree5d666a509384f210a78b0e691d8f531b71b04875 /http_handle_repo_contrib_one.go
parent*: Replace some := with var (diff)
downloadforge-134b84f2672a9fe3e2e8a92b712261b47c4bd022.tar.gz
forge-134b84f2672a9fe3e2e8a92b712261b47c4bd022.tar.zst
forge-134b84f2672a9fe3e2e8a92b712261b47c4bd022.zip
repo/*: Use var instead of :=
Diffstat (limited to 'http_handle_repo_contrib_one.go')
-rw-r--r--http_handle_repo_contrib_one.go29
1 files changed, 19 insertions, 10 deletions
diff --git a/http_handle_repo_contrib_one.go b/http_handle_repo_contrib_one.go
index 43c8996..91acfea 100644
--- a/http_handle_repo_contrib_one.go
+++ b/http_handle_repo_contrib_one.go
@@ -9,32 +9,41 @@ import (
"github.com/go-git/go-git/v5"
"github.com/go-git/go-git/v5/plumbing"
+ "github.com/go-git/go-git/v5/plumbing/object"
)
func handle_repo_contrib_one(w http.ResponseWriter, r *http.Request, params map[string]any) {
- mr_id_string := params["mr_id"].(string)
- mr_id, err := strconv.ParseInt(mr_id_string, 10, strconv.IntSize)
+ var mr_id_string string
+ var mr_id int
+ var err error
+ var title, status, source_ref, destination_branch string
+ var repo *git.Repository
+ var source_ref_hash plumbing.Hash
+ var source_commit *object.Commit
+
+ mr_id_string = params["mr_id"].(string)
+ mr_id_int64, err := strconv.ParseInt(mr_id_string, 10, strconv.IntSize)
if err != nil {
http.Error(w, "Merge request ID not an integer: "+err.Error(), http.StatusBadRequest)
return
}
+ mr_id = int(mr_id_int64)
- var title, status, source_ref, destination_branch string
- err = database.QueryRow(r.Context(), "SELECT COALESCE(title, ''), status, source_ref, COALESCE(destination_branch, '') FROM merge_requests WHERE id = $1", mr_id).Scan(&title, &status, &source_ref, &destination_branch)
- if err != nil {
+ if err = database.QueryRow(r.Context(),
+ "SELECT COALESCE(title, ''), status, source_ref, COALESCE(destination_branch, '') FROM merge_requests WHERE id = $1",
+ mr_id,
+ ).Scan(&title, &status, &source_ref, &destination_branch); err != nil {
http.Error(w, "Error querying merge request: "+err.Error(), http.StatusInternalServerError)
return
}
- repo := params["repo"].(*git.Repository)
+ repo = params["repo"].(*git.Repository)
- source_ref_hash, err := get_ref_hash_from_type_and_name(repo, "branch", source_ref)
- if err != nil {
+ if source_ref_hash, err = get_ref_hash_from_type_and_name(repo, "branch", source_ref); err != nil {
http.Error(w, "Error getting source ref hash: "+err.Error(), http.StatusInternalServerError)
return
}
- source_commit, err := repo.CommitObject(source_ref_hash)
- if err != nil {
+ if source_commit, err = repo.CommitObject(source_ref_hash); err != nil {
http.Error(w, "Error getting source commit: "+err.Error(), http.StatusInternalServerError)
return
}