feat: add close/reopen and comment actions to issue detail view
Add SetIssueState client method and handler for toggling issue state
between open and closed via PATCH API. Add AddComment client method
wrapping PostComment. Register new routes POST /issues/{owner}/{repo}/{index}/state
and POST /issues/{owner}/{repo}/{index}/comments. Update issue_detail.html
template with comment form (HTMX inline append) and close/reopen button
(HTMX inline swap of state badge).
Closes leeworks-agents/gitea-mobile#29
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -708,15 +708,20 @@ func (c *Client) SubmitReview(ctx context.Context, token, owner, repo string, in
|
||||
|
||||
// CloseIssue closes an issue by setting its state to "closed".
|
||||
func (c *Client) CloseIssue(ctx context.Context, token, owner, repo string, index int64) error {
|
||||
payload, err := json.Marshal(map[string]string{"state": "closed"})
|
||||
return c.SetIssueState(ctx, token, owner, repo, index, "closed")
|
||||
}
|
||||
|
||||
// SetIssueState sets an issue's state (e.g. "open" or "closed").
|
||||
func (c *Client) SetIssueState(ctx context.Context, token, owner, repo string, index int64, state string) error {
|
||||
payload, err := json.Marshal(map[string]string{"state": state})
|
||||
if err != nil {
|
||||
return fmt.Errorf("marshaling close request: %w", err)
|
||||
return fmt.Errorf("marshaling state change: %w", err)
|
||||
}
|
||||
|
||||
path := fmt.Sprintf("/repos/%s/%s/issues/%d", owner, repo, index)
|
||||
resp, err := c.doRequest(ctx, token, http.MethodPatch, path, strings.NewReader(string(payload)))
|
||||
if err != nil {
|
||||
return fmt.Errorf("closing issue: %w", err)
|
||||
return fmt.Errorf("setting issue state: %w", err)
|
||||
}
|
||||
resp.Body.Close()
|
||||
|
||||
@@ -724,6 +729,11 @@ func (c *Client) CloseIssue(ctx context.Context, token, owner, repo string, inde
|
||||
return nil
|
||||
}
|
||||
|
||||
// AddComment creates a comment on an issue and returns the created Comment.
|
||||
func (c *Client) AddComment(ctx context.Context, token, owner, repo string, index int64, body string) (*Comment, error) {
|
||||
return c.PostComment(ctx, token, owner, repo, index, body)
|
||||
}
|
||||
|
||||
// PostComment creates a comment on an issue and returns the created Comment.
|
||||
func (c *Client) PostComment(ctx context.Context, token, owner, repo string, index int64, body string) (*Comment, error) {
|
||||
payload, err := json.Marshal(map[string]string{"body": body})
|
||||
|
||||
Reference in New Issue
Block a user