feat: add Assign action to issue detail view
Add the ability to assign users to issues from the mobile app:
- New ListCollaborators client method fetches repo collaborators
- New AssignIssue client method sets assignees via PATCH API
- New POST /issues/{owner}/{repo}/{index}/assignees handler
- Assignee dropdown populated with repo collaborators in issue detail
- HTMX inline response confirms assignment without page reload
Closes leeworks-agents/gitea-mobile#50
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -41,6 +41,7 @@ func (h *Handler) RegisterRoutes(mux *http.ServeMux) {
|
||||
mux.HandleFunc("GET /issues/new", h.NewIssue)
|
||||
mux.HandleFunc("POST /issues", h.CreateIssue)
|
||||
mux.HandleFunc("POST /issues/{owner}/{repo}/{index}/labels", h.ApplyLabels)
|
||||
mux.HandleFunc("POST /issues/{owner}/{repo}/{index}/assignees", h.AssignIssue)
|
||||
mux.HandleFunc("POST /issues/{owner}/{repo}/{index}/close", h.CloseIssue)
|
||||
mux.HandleFunc("POST /issues/{owner}/{repo}/{index}/state", h.SetIssueState)
|
||||
mux.HandleFunc("POST /issues/{owner}/{repo}/{index}/comments", h.AddComment)
|
||||
@@ -429,6 +430,12 @@ func (h *Handler) IssueDetail(w http.ResponseWriter, r *http.Request) {
|
||||
labels = nil
|
||||
}
|
||||
|
||||
collaborators, err := h.Client.ListCollaborators(r.Context(), token, owner, repo)
|
||||
if err != nil {
|
||||
slog.Error("failed to get collaborators", "error", err)
|
||||
collaborators = nil
|
||||
}
|
||||
|
||||
// Render markdown body if present.
|
||||
var renderedBody template.HTML
|
||||
if issue.Body != "" {
|
||||
@@ -453,6 +460,7 @@ func (h *Handler) IssueDetail(w http.ResponseWriter, r *http.Request) {
|
||||
RenderedBody template.HTML
|
||||
Comments []giteaclient.Comment
|
||||
AvailableLabels []giteaclient.Label
|
||||
Collaborators []string
|
||||
}
|
||||
|
||||
data := templateData{
|
||||
@@ -460,6 +468,7 @@ func (h *Handler) IssueDetail(w http.ResponseWriter, r *http.Request) {
|
||||
RenderedBody: renderedBody,
|
||||
Comments: comments,
|
||||
AvailableLabels: labels,
|
||||
Collaborators: collaborators,
|
||||
}
|
||||
|
||||
var buf strings.Builder
|
||||
@@ -660,6 +669,45 @@ func (h *Handler) ApplyLabels(w http.ResponseWriter, r *http.Request) {
|
||||
http.Redirect(w, r, fmt.Sprintf("/issues/%s/%s/%d", owner, repo, index), http.StatusSeeOther)
|
||||
}
|
||||
|
||||
// AssignIssue handles POST /issues/{owner}/{repo}/{index}/assignees.
|
||||
func (h *Handler) AssignIssue(w http.ResponseWriter, r *http.Request) {
|
||||
token := getToken(r)
|
||||
owner := r.PathValue("owner")
|
||||
repo := r.PathValue("repo")
|
||||
indexStr := r.PathValue("index")
|
||||
|
||||
index, err := strconv.ParseInt(indexStr, 10, 64)
|
||||
if err != nil {
|
||||
http.Error(w, "invalid issue index", http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
|
||||
if err := r.ParseForm(); err != nil {
|
||||
http.Error(w, "bad request", http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
|
||||
assignee := r.FormValue("assignee")
|
||||
if assignee == "" {
|
||||
http.Error(w, "assignee is required", http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
|
||||
if err := h.Client.AssignIssue(r.Context(), token, owner, repo, index, []string{assignee}); err != nil {
|
||||
slog.Error("failed to assign issue", "error", err, "owner", owner, "repo", repo, "index", index, "assignee", assignee)
|
||||
http.Error(w, "failed to assign issue", http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
if isHTMX(r) {
|
||||
w.Header().Set("Content-Type", "text/html; charset=utf-8")
|
||||
fmt.Fprintf(w, `<span style="color:#3fb950">Assigned to %s</span>`, template.HTMLEscapeString(assignee))
|
||||
return
|
||||
}
|
||||
|
||||
http.Redirect(w, r, fmt.Sprintf("/issues/%s/%s/%d", owner, repo, index), http.StatusSeeOther)
|
||||
}
|
||||
|
||||
// CloseIssue handles POST /issues/{owner}/{repo}/{index}/close.
|
||||
func (h *Handler) CloseIssue(w http.ResponseWriter, r *http.Request) {
|
||||
token := getToken(r)
|
||||
|
||||
Reference in New Issue
Block a user