aboutsummaryrefslogtreecommitdiff
path: root/http_handle_repo_contrib_index.go
diff options
context:
space:
mode:
authorRunxi Yu <me@runxiyu.org>2025-02-19 01:02:33 +0800
committerRunxi Yu <me@runxiyu.org>2025-02-19 01:02:33 +0800
commit2d3e888321baeae889c7c51f2312aafba1ec70d0 (patch)
tree030c79f59ac2f62cce1567fd3fc07607b224d2fd /http_handle_repo_contrib_index.go
parenthttp: Consistently use redirect_with{out,}_slash, never r.URL.Path (diff)
downloadforge-2d3e888321baeae889c7c51f2312aafba1ec70d0.tar.gz
forge-2d3e888321baeae889c7c51f2312aafba1ec70d0.tar.zst
forge-2d3e888321baeae889c7c51f2312aafba1ec70d0.zip
contrib: Add contrib/MR index page
Diffstat (limited to '')
-rw-r--r--http_handle_repo_contrib_index.go42
1 files changed, 42 insertions, 0 deletions
diff --git a/http_handle_repo_contrib_index.go b/http_handle_repo_contrib_index.go
new file mode 100644
index 0000000..632e8f2
--- /dev/null
+++ b/http_handle_repo_contrib_index.go
@@ -0,0 +1,42 @@
+package main
+
+import (
+ "net/http"
+
+ "github.com/go-git/go-git/v5"
+)
+
+type id_title_status_t struct {
+ ID int
+ Title string
+ Status string
+}
+
+func handle_repo_contrib_index(w http.ResponseWriter, r *http.Request, params map[string]any) {
+ _ = params["repo"].(*git.Repository)
+
+ rows, err := database.Query(r.Context(), "SELECT id, title, status FROM merge_requests WHERE repo_id = $1", params["repo_id"])
+ if err != nil {
+ http.Error(w, "Error querying merge requests: "+err.Error(), http.StatusInternalServerError)
+ return
+ }
+ defer rows.Close()
+
+ result := []id_title_status_t{}
+ for rows.Next() {
+ var id int
+ var title, status string
+ if err := rows.Scan(&id, &title, &status); err != nil {
+ http.Error(w, "Error scanning merge request: "+err.Error(), http.StatusInternalServerError)
+ return
+ }
+ result = append(result, id_title_status_t{id, title, status})
+ }
+ if err := rows.Err(); err != nil {
+ http.Error(w, "Error ranging over merge requests: "+err.Error(), http.StatusInternalServerError)
+ return
+ }
+ params["merge_requests"] = result
+
+ render_template(w, "repo_contrib_index", params)
+}