Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 485aa3f853 |
@@ -753,6 +753,49 @@ func (c *Client) ApplyLabel(ctx context.Context, token, owner, repo string, inde
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ListCollaborators fetches the list of collaborators (users with access) for a repo.
|
||||||
|
func (c *Client) ListCollaborators(ctx context.Context, token, owner, repo string) ([]string, error) {
|
||||||
|
path := fmt.Sprintf("/repos/%s/%s/collaborators?limit=50", owner, repo)
|
||||||
|
resp, err := c.doRequest(ctx, token, http.MethodGet, path, nil)
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("fetching collaborators: %w", err)
|
||||||
|
}
|
||||||
|
defer resp.Body.Close()
|
||||||
|
|
||||||
|
var users []struct {
|
||||||
|
Login string `json:"login"`
|
||||||
|
}
|
||||||
|
if err := json.NewDecoder(resp.Body).Decode(&users); err != nil {
|
||||||
|
return nil, fmt.Errorf("decoding collaborators: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
var logins []string
|
||||||
|
for _, u := range users {
|
||||||
|
logins = append(logins, u.Login)
|
||||||
|
}
|
||||||
|
return logins, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// AssignIssue sets the assignees on an issue.
|
||||||
|
func (c *Client) AssignIssue(ctx context.Context, token, owner, repo string, index int64, assignees []string) error {
|
||||||
|
payload, err := json.Marshal(map[string]interface{}{
|
||||||
|
"assignees": assignees,
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("marshaling assignees: %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("assigning issue: %w", err)
|
||||||
|
}
|
||||||
|
resp.Body.Close()
|
||||||
|
|
||||||
|
c.InvalidateAll()
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
// SubmitReview submits a review on a pull request.
|
// SubmitReview submits a review on a pull request.
|
||||||
func (c *Client) SubmitReview(ctx context.Context, token, owner, repo string, index int64, reviewType, body string) error {
|
func (c *Client) SubmitReview(ctx context.Context, token, owner, repo string, index int64, reviewType, body string) error {
|
||||||
payload := map[string]interface{}{
|
payload := map[string]interface{}{
|
||||||
|
|||||||
@@ -39,9 +39,9 @@ func (h *Handler) RegisterRoutes(mux *http.ServeMux) {
|
|||||||
// Issues.
|
// Issues.
|
||||||
mux.HandleFunc("GET /issues", h.ListIssues)
|
mux.HandleFunc("GET /issues", h.ListIssues)
|
||||||
mux.HandleFunc("GET /issues/new", h.NewIssue)
|
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", h.CreateIssue)
|
||||||
mux.HandleFunc("POST /issues/{owner}/{repo}/{index}/labels", h.ApplyLabels)
|
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}/close", h.CloseIssue)
|
||||||
mux.HandleFunc("POST /issues/{owner}/{repo}/{index}/state", h.SetIssueState)
|
mux.HandleFunc("POST /issues/{owner}/{repo}/{index}/state", h.SetIssueState)
|
||||||
mux.HandleFunc("POST /issues/{owner}/{repo}/{index}/comments", h.AddComment)
|
mux.HandleFunc("POST /issues/{owner}/{repo}/{index}/comments", h.AddComment)
|
||||||
@@ -430,6 +430,12 @@ func (h *Handler) IssueDetail(w http.ResponseWriter, r *http.Request) {
|
|||||||
labels = nil
|
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.
|
// Render markdown body if present.
|
||||||
var renderedBody template.HTML
|
var renderedBody template.HTML
|
||||||
if issue.Body != "" {
|
if issue.Body != "" {
|
||||||
@@ -454,6 +460,7 @@ func (h *Handler) IssueDetail(w http.ResponseWriter, r *http.Request) {
|
|||||||
RenderedBody template.HTML
|
RenderedBody template.HTML
|
||||||
Comments []giteaclient.Comment
|
Comments []giteaclient.Comment
|
||||||
AvailableLabels []giteaclient.Label
|
AvailableLabels []giteaclient.Label
|
||||||
|
Collaborators []string
|
||||||
}
|
}
|
||||||
|
|
||||||
data := templateData{
|
data := templateData{
|
||||||
@@ -461,6 +468,7 @@ func (h *Handler) IssueDetail(w http.ResponseWriter, r *http.Request) {
|
|||||||
RenderedBody: renderedBody,
|
RenderedBody: renderedBody,
|
||||||
Comments: comments,
|
Comments: comments,
|
||||||
AvailableLabels: labels,
|
AvailableLabels: labels,
|
||||||
|
Collaborators: collaborators,
|
||||||
}
|
}
|
||||||
|
|
||||||
var buf strings.Builder
|
var buf strings.Builder
|
||||||
@@ -568,38 +576,6 @@ func (h *Handler) NewIssue(w http.ResponseWriter, r *http.Request) {
|
|||||||
renderPage(w, r, "New Issue", "issues", buf.String())
|
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.
|
// CreateIssue handles POST /issues.
|
||||||
func (h *Handler) CreateIssue(w http.ResponseWriter, r *http.Request) {
|
func (h *Handler) CreateIssue(w http.ResponseWriter, r *http.Request) {
|
||||||
token := getToken(r)
|
token := getToken(r)
|
||||||
@@ -613,15 +589,6 @@ func (h *Handler) CreateIssue(w http.ResponseWriter, r *http.Request) {
|
|||||||
title := r.FormValue("title")
|
title := r.FormValue("title")
|
||||||
body := r.FormValue("body")
|
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 owner == "" || repo == "" || title == "" {
|
||||||
if isHTMX(r) {
|
if isHTMX(r) {
|
||||||
w.Header().Set("Content-Type", "text/html; charset=utf-8")
|
w.Header().Set("Content-Type", "text/html; charset=utf-8")
|
||||||
@@ -633,7 +600,7 @@ func (h *Handler) CreateIssue(w http.ResponseWriter, r *http.Request) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
issue, err := h.Client.CreateIssue(r.Context(), token, owner, repo, title, body, labelIDs)
|
issue, err := h.Client.CreateIssue(r.Context(), token, owner, repo, title, body, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
slog.Error("failed to create issue", "error", err)
|
slog.Error("failed to create issue", "error", err)
|
||||||
if isHTMX(r) {
|
if isHTMX(r) {
|
||||||
@@ -702,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)
|
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.
|
// CloseIssue handles POST /issues/{owner}/{repo}/{index}/close.
|
||||||
func (h *Handler) CloseIssue(w http.ResponseWriter, r *http.Request) {
|
func (h *Handler) CloseIssue(w http.ResponseWriter, r *http.Request) {
|
||||||
token := getToken(r)
|
token := getToken(r)
|
||||||
|
|||||||
@@ -20,11 +20,6 @@
|
|||||||
<input type="hidden" name="repo" id="repo-input">
|
<input type="hidden" name="repo" id="repo-input">
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="form-group" id="label-section" style="display:none;">
|
|
||||||
<label>Labels</label>
|
|
||||||
<div id="label-list"></div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label for="title">Title</label>
|
<label for="title">Title</label>
|
||||||
<input type="text" id="title" name="title" placeholder="Issue title" required>
|
<input type="text" id="title" name="title" placeholder="Issue title" required>
|
||||||
@@ -57,19 +52,7 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
repoSelect.addEventListener('change', function() {
|
repoSelect.addEventListener('change', splitOwnerRepo);
|
||||||
splitOwnerRepo();
|
|
||||||
var labelSection = document.getElementById('label-section');
|
|
||||||
var labelList = document.getElementById('label-list');
|
|
||||||
if (ownerInput.value && repoInput.value) {
|
|
||||||
labelList.innerHTML = '<span class="empty">Loading labels...</span>';
|
|
||||||
labelSection.style.display = 'block';
|
|
||||||
htmx.ajax('GET', '/issues/new/labels?owner=' + encodeURIComponent(ownerInput.value) + '&repo=' + encodeURIComponent(repoInput.value), {target: '#label-list', swap: 'innerHTML'});
|
|
||||||
} else {
|
|
||||||
labelSection.style.display = 'none';
|
|
||||||
labelList.innerHTML = '';
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
// Validate before HTMX submit.
|
// Validate before HTMX submit.
|
||||||
document.getElementById('create-issue-form').addEventListener('htmx:configRequest', function(evt) {
|
document.getElementById('create-issue-form').addEventListener('htmx:configRequest', function(evt) {
|
||||||
|
|||||||
@@ -51,6 +51,18 @@
|
|||||||
|
|
||||||
<div class="card" style="margin-top:1rem;">
|
<div class="card" style="margin-top:1rem;">
|
||||||
<h2>Actions</h2>
|
<h2>Actions</h2>
|
||||||
|
{{if .Collaborators}}
|
||||||
|
<form hx-post="/issues/{{.Issue.RepoOwner}}/{{.Issue.RepoName}}/{{.Issue.Number}}/assignees" hx-swap="outerHTML" style="margin-bottom:0.5rem;">
|
||||||
|
<div class="filter-bar" style="margin-bottom:0.5rem;">
|
||||||
|
<select name="assignee">
|
||||||
|
{{range .Collaborators}}
|
||||||
|
<option value="{{.}}">{{.}}</option>
|
||||||
|
{{end}}
|
||||||
|
</select>
|
||||||
|
<button type="submit" class="btn btn-secondary" style="width:auto;padding:0.5rem 1rem;">Assign</button>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
{{end}}
|
||||||
<form hx-post="/issues/{{.Issue.RepoOwner}}/{{.Issue.RepoName}}/{{.Issue.Number}}/labels" hx-swap="outerHTML" style="margin-bottom:0.5rem;">
|
<form hx-post="/issues/{{.Issue.RepoOwner}}/{{.Issue.RepoName}}/{{.Issue.Number}}/labels" hx-swap="outerHTML" style="margin-bottom:0.5rem;">
|
||||||
<div class="filter-bar" style="margin-bottom:0.5rem;">
|
<div class="filter-bar" style="margin-bottom:0.5rem;">
|
||||||
<select name="label_id">
|
<select name="label_id">
|
||||||
|
|||||||
Reference in New Issue
Block a user