|
|
|
@@ -39,6 +39,7 @@ func (h *Handler) RegisterRoutes(mux *http.ServeMux) {
|
|
|
|
|
// Issues.
|
|
|
|
|
mux.HandleFunc("GET /issues", h.ListIssues)
|
|
|
|
|
mux.HandleFunc("GET /issues/new", h.NewIssue)
|
|
|
|
|
mux.HandleFunc("GET /issues/new/labels", h.NewIssueLabels)
|
|
|
|
|
mux.HandleFunc("POST /issues", h.CreateIssue)
|
|
|
|
|
mux.HandleFunc("POST /issues/{owner}/{repo}/{index}/labels", h.ApplyLabels)
|
|
|
|
|
mux.HandleFunc("POST /issues/{owner}/{repo}/{index}/close", h.CloseIssue)
|
|
|
|
@@ -567,6 +568,38 @@ func (h *Handler) NewIssue(w http.ResponseWriter, r *http.Request) {
|
|
|
|
|
renderPage(w, r, "New Issue", "issues", buf.String())
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// NewIssueLabels handles GET /issues/new/labels — returns label checkboxes for a repo.
|
|
|
|
|
func (h *Handler) NewIssueLabels(w http.ResponseWriter, r *http.Request) {
|
|
|
|
|
token := getToken(r)
|
|
|
|
|
owner := r.URL.Query().Get("owner")
|
|
|
|
|
repo := r.URL.Query().Get("repo")
|
|
|
|
|
|
|
|
|
|
if owner == "" || repo == "" {
|
|
|
|
|
w.Header().Set("Content-Type", "text/html; charset=utf-8")
|
|
|
|
|
fmt.Fprint(w, `<span class="empty">Select a repository first.</span>`)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
labels, err := h.Client.GetRepoLabels(r.Context(), token, owner, repo)
|
|
|
|
|
if err != nil {
|
|
|
|
|
slog.Error("failed to fetch labels", "error", err, "owner", owner, "repo", repo)
|
|
|
|
|
w.Header().Set("Content-Type", "text/html; charset=utf-8")
|
|
|
|
|
fmt.Fprint(w, `<span class="empty">Error loading labels.</span>`)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
w.Header().Set("Content-Type", "text/html; charset=utf-8")
|
|
|
|
|
if len(labels) == 0 {
|
|
|
|
|
fmt.Fprint(w, `<span class="empty">No labels available for this repository.</span>`)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for _, l := range labels {
|
|
|
|
|
fmt.Fprintf(w, `<label style="display:inline-block;margin:0.25rem 0.5rem 0.25rem 0;cursor:pointer;"><input type="checkbox" name="label_ids" value="%d" style="margin-right:0.25rem;"> <span class="label" style="color:#%s;border:1px solid #%s">%s</span></label>`,
|
|
|
|
|
l.ID, template.HTMLEscapeString(l.Color), template.HTMLEscapeString(l.Color), template.HTMLEscapeString(l.Name))
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// CreateIssue handles POST /issues.
|
|
|
|
|
func (h *Handler) CreateIssue(w http.ResponseWriter, r *http.Request) {
|
|
|
|
|
token := getToken(r)
|
|
|
|
@@ -580,6 +613,15 @@ func (h *Handler) CreateIssue(w http.ResponseWriter, r *http.Request) {
|
|
|
|
|
title := r.FormValue("title")
|
|
|
|
|
body := r.FormValue("body")
|
|
|
|
|
|
|
|
|
|
// Parse label IDs from form checkboxes.
|
|
|
|
|
var labelIDs []int64
|
|
|
|
|
for _, idStr := range r.Form["label_ids"] {
|
|
|
|
|
id, err := strconv.ParseInt(idStr, 10, 64)
|
|
|
|
|
if err == nil {
|
|
|
|
|
labelIDs = append(labelIDs, id)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if owner == "" || repo == "" || title == "" {
|
|
|
|
|
if isHTMX(r) {
|
|
|
|
|
w.Header().Set("Content-Type", "text/html; charset=utf-8")
|
|
|
|
@@ -591,7 +633,7 @@ func (h *Handler) CreateIssue(w http.ResponseWriter, r *http.Request) {
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
issue, err := h.Client.CreateIssue(r.Context(), token, owner, repo, title, body, nil)
|
|
|
|
|
issue, err := h.Client.CreateIssue(r.Context(), token, owner, repo, title, body, labelIDs)
|
|
|
|
|
if err != nil {
|
|
|
|
|
slog.Error("failed to create issue", "error", err)
|
|
|
|
|
if isHTMX(r) {
|
|
|
|
|