|
|
|
@@ -180,158 +180,155 @@ func (h *Handler) Dashboard(w http.ResponseWriter, r *http.Request) {
|
|
|
|
|
token := getToken(r)
|
|
|
|
|
orgs := h.getUserOrgs(r)
|
|
|
|
|
|
|
|
|
|
type dashboardData struct {
|
|
|
|
|
Items []giteaclient.TriageItem
|
|
|
|
|
Error string
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var data dashboardData
|
|
|
|
|
|
|
|
|
|
if len(orgs) == 0 {
|
|
|
|
|
renderPage(w, r, "Dashboard", "dashboard",
|
|
|
|
|
`<h1>Dashboard</h1><p class="empty">No organizations found. Check your token permissions.</p>`)
|
|
|
|
|
return
|
|
|
|
|
data.Error = "No organizations found. Check your token permissions."
|
|
|
|
|
} else {
|
|
|
|
|
queue, err := h.Client.GetTriageQueue(r.Context(), token, orgs)
|
|
|
|
|
if err != nil {
|
|
|
|
|
slog.Error("failed to get triage queue", "error", err)
|
|
|
|
|
data.Error = "Error loading triage queue."
|
|
|
|
|
} else {
|
|
|
|
|
data.Items = queue
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
queue, err := h.Client.GetTriageQueue(r.Context(), token, orgs)
|
|
|
|
|
tmpl, err := template.ParseFiles("internal/templates/dashboard.html")
|
|
|
|
|
if err != nil {
|
|
|
|
|
slog.Error("failed to get triage queue", "error", err)
|
|
|
|
|
renderPage(w, r, "Dashboard", "dashboard",
|
|
|
|
|
`<h1>Dashboard</h1><p class="empty">Error loading triage queue.</p>`)
|
|
|
|
|
slog.Error("failed to parse dashboard template", "error", err)
|
|
|
|
|
http.Error(w, "template error", http.StatusInternalServerError)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if len(queue) == 0 {
|
|
|
|
|
renderPage(w, r, "Dashboard", "dashboard",
|
|
|
|
|
`<h1>Dashboard</h1><p class="empty">No items need attention. Nice work!</p>`)
|
|
|
|
|
var buf strings.Builder
|
|
|
|
|
if err := tmpl.ExecuteTemplate(&buf, "content", data); err != nil {
|
|
|
|
|
slog.Error("failed to execute dashboard template", "error", err)
|
|
|
|
|
http.Error(w, "template error", http.StatusInternalServerError)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
content := `<h1>Dashboard</h1>`
|
|
|
|
|
for _, item := range queue {
|
|
|
|
|
typeBadge := `<span class="type-badge type-issue">issue</span>`
|
|
|
|
|
if item.Type == "pull" {
|
|
|
|
|
typeBadge = `<span class="type-badge type-pull">PR</span>`
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
labels := ""
|
|
|
|
|
for _, l := range item.Labels {
|
|
|
|
|
color := "#8b949e"
|
|
|
|
|
switch l {
|
|
|
|
|
case "P1":
|
|
|
|
|
color = "#f85149"
|
|
|
|
|
case "P2":
|
|
|
|
|
color = "#d29922"
|
|
|
|
|
case "P3":
|
|
|
|
|
color = "#58a6ff"
|
|
|
|
|
}
|
|
|
|
|
labels += fmt.Sprintf(`<span class="label" style="color:%s;border:1px solid %s">%s</span>`, color, color, template.HTMLEscapeString(l))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
content += fmt.Sprintf(`<div class="card">
|
|
|
|
|
<div class="card-title">%s %s</div>
|
|
|
|
|
<div class="card-meta">%s/%s #%d %s</div>
|
|
|
|
|
</div>`, typeBadge, template.HTMLEscapeString(item.Title),
|
|
|
|
|
template.HTMLEscapeString(item.RepoOwner),
|
|
|
|
|
template.HTMLEscapeString(item.RepoName),
|
|
|
|
|
item.Number, labels)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
renderPage(w, r, "Dashboard", "dashboard", content)
|
|
|
|
|
renderPage(w, r, "Dashboard", "dashboard", buf.String())
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// ListIssues handles GET /issues.
|
|
|
|
|
func (h *Handler) ListIssues(w http.ResponseWriter, r *http.Request) {
|
|
|
|
|
token := getToken(r)
|
|
|
|
|
orgs := h.getUserOrgs(r)
|
|
|
|
|
orgNames := h.getUserOrgs(r)
|
|
|
|
|
|
|
|
|
|
if len(orgs) == 0 {
|
|
|
|
|
renderPage(w, r, "Issues", "issues",
|
|
|
|
|
`<h1>Issues</h1><p class="empty">No organizations found.</p>`)
|
|
|
|
|
return
|
|
|
|
|
type issuesData struct {
|
|
|
|
|
Issues []giteaclient.Issue
|
|
|
|
|
Orgs []string
|
|
|
|
|
SelectedOrg string
|
|
|
|
|
SelectedState string
|
|
|
|
|
HasMore bool
|
|
|
|
|
NextPage int
|
|
|
|
|
Error string
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
issues, err := h.Client.ListAllIssues(r.Context(), token, orgs)
|
|
|
|
|
selectedOrg := r.URL.Query().Get("org")
|
|
|
|
|
selectedState := r.URL.Query().Get("state")
|
|
|
|
|
if selectedState == "" {
|
|
|
|
|
selectedState = "open"
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
data := issuesData{
|
|
|
|
|
Orgs: orgNames,
|
|
|
|
|
SelectedOrg: selectedOrg,
|
|
|
|
|
SelectedState: selectedState,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if len(orgNames) == 0 {
|
|
|
|
|
data.Error = "No organizations found."
|
|
|
|
|
} else {
|
|
|
|
|
// Filter to selected org if specified.
|
|
|
|
|
queryOrgs := orgNames
|
|
|
|
|
if selectedOrg != "" {
|
|
|
|
|
queryOrgs = []string{selectedOrg}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
issues, err := h.Client.ListAllIssues(r.Context(), token, queryOrgs)
|
|
|
|
|
if err != nil {
|
|
|
|
|
slog.Error("failed to list issues", "error", err)
|
|
|
|
|
data.Error = "Error loading issues."
|
|
|
|
|
} else {
|
|
|
|
|
data.Issues = issues
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
tmpl, err := template.ParseFiles("internal/templates/issues.html")
|
|
|
|
|
if err != nil {
|
|
|
|
|
slog.Error("failed to list issues", "error", err)
|
|
|
|
|
renderPage(w, r, "Issues", "issues",
|
|
|
|
|
`<h1>Issues</h1><p class="empty">Error loading issues.</p>`)
|
|
|
|
|
slog.Error("failed to parse issues template", "error", err)
|
|
|
|
|
http.Error(w, "template error", http.StatusInternalServerError)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if len(issues) == 0 {
|
|
|
|
|
renderPage(w, r, "Issues", "issues",
|
|
|
|
|
`<h1>Issues</h1><p class="empty">No open issues found.</p>`)
|
|
|
|
|
var buf strings.Builder
|
|
|
|
|
if err := tmpl.ExecuteTemplate(&buf, "content", data); err != nil {
|
|
|
|
|
slog.Error("failed to execute issues template", "error", err)
|
|
|
|
|
http.Error(w, "template error", http.StatusInternalServerError)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
content := `<h1>Issues</h1>`
|
|
|
|
|
for _, issue := range issues {
|
|
|
|
|
labels := ""
|
|
|
|
|
for _, l := range issue.Labels {
|
|
|
|
|
labels += fmt.Sprintf(`<span class="label" style="color:#%s;border:1px solid #%s">%s</span>`,
|
|
|
|
|
l.Color, l.Color, template.HTMLEscapeString(l.Name))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
assignee := ""
|
|
|
|
|
if issue.Assignee != nil {
|
|
|
|
|
assignee = fmt.Sprintf(` · %s`, template.HTMLEscapeString(issue.Assignee.Login))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
content += fmt.Sprintf(`<div class="card">
|
|
|
|
|
<div class="card-title">%s</div>
|
|
|
|
|
<div class="card-meta">%s/%s #%d %s%s</div>
|
|
|
|
|
</div>`, template.HTMLEscapeString(issue.Title),
|
|
|
|
|
template.HTMLEscapeString(issue.RepoOwner),
|
|
|
|
|
template.HTMLEscapeString(issue.RepoName),
|
|
|
|
|
issue.Number, labels, assignee)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
renderPage(w, r, "Issues", "issues", content)
|
|
|
|
|
renderPage(w, r, "Issues", "issues", buf.String())
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// ListPulls handles GET /pulls.
|
|
|
|
|
func (h *Handler) ListPulls(w http.ResponseWriter, r *http.Request) {
|
|
|
|
|
token := getToken(r)
|
|
|
|
|
orgs := h.getUserOrgs(r)
|
|
|
|
|
orgNames := h.getUserOrgs(r)
|
|
|
|
|
|
|
|
|
|
if len(orgs) == 0 {
|
|
|
|
|
renderPage(w, r, "Pull Requests", "pulls",
|
|
|
|
|
`<h1>Pull Requests</h1><p class="empty">No organizations found.</p>`)
|
|
|
|
|
return
|
|
|
|
|
type pullsData struct {
|
|
|
|
|
Pulls []giteaclient.PullRequest
|
|
|
|
|
Orgs []string
|
|
|
|
|
SelectedOrg string
|
|
|
|
|
Error string
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
prs, err := h.Client.ListAllPullRequests(r.Context(), token, orgs)
|
|
|
|
|
selectedOrg := r.URL.Query().Get("org")
|
|
|
|
|
|
|
|
|
|
data := pullsData{
|
|
|
|
|
Orgs: orgNames,
|
|
|
|
|
SelectedOrg: selectedOrg,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if len(orgNames) == 0 {
|
|
|
|
|
data.Error = "No organizations found."
|
|
|
|
|
} else {
|
|
|
|
|
queryOrgs := orgNames
|
|
|
|
|
if selectedOrg != "" {
|
|
|
|
|
queryOrgs = []string{selectedOrg}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
prs, err := h.Client.ListAllPullRequests(r.Context(), token, queryOrgs)
|
|
|
|
|
if err != nil {
|
|
|
|
|
slog.Error("failed to list pull requests", "error", err)
|
|
|
|
|
data.Error = "Error loading pull requests."
|
|
|
|
|
} else {
|
|
|
|
|
data.Pulls = prs
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
tmpl, err := template.ParseFiles("internal/templates/pulls.html")
|
|
|
|
|
if err != nil {
|
|
|
|
|
slog.Error("failed to list pull requests", "error", err)
|
|
|
|
|
renderPage(w, r, "Pull Requests", "pulls",
|
|
|
|
|
`<h1>Pull Requests</h1><p class="empty">Error loading pull requests.</p>`)
|
|
|
|
|
slog.Error("failed to parse pulls template", "error", err)
|
|
|
|
|
http.Error(w, "template error", http.StatusInternalServerError)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if len(prs) == 0 {
|
|
|
|
|
renderPage(w, r, "Pull Requests", "pulls",
|
|
|
|
|
`<h1>Pull Requests</h1><p class="empty">No open pull requests found.</p>`)
|
|
|
|
|
var buf strings.Builder
|
|
|
|
|
if err := tmpl.ExecuteTemplate(&buf, "content", data); err != nil {
|
|
|
|
|
slog.Error("failed to execute pulls template", "error", err)
|
|
|
|
|
http.Error(w, "template error", http.StatusInternalServerError)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
content := `<h1>Pull Requests</h1>`
|
|
|
|
|
for _, pr := range prs {
|
|
|
|
|
labels := ""
|
|
|
|
|
for _, l := range pr.Labels {
|
|
|
|
|
labels += fmt.Sprintf(`<span class="label" style="color:#%s;border:1px solid #%s">%s</span>`,
|
|
|
|
|
l.Color, l.Color, template.HTMLEscapeString(l.Name))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
stats := fmt.Sprintf(`<span style="color:#3fb950">+%d</span> <span style="color:#f85149">-%d</span>`, pr.Additions, pr.Deletions)
|
|
|
|
|
mergeStatus := ""
|
|
|
|
|
if pr.Mergeable {
|
|
|
|
|
mergeStatus = `<span style="color:#3fb950;font-size:0.7rem;">mergeable</span>`
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
content += fmt.Sprintf(`<div class="card">
|
|
|
|
|
<div class="card-title"><span class="type-badge type-pull">PR</span> %s</div>
|
|
|
|
|
<div class="card-meta">%s/%s #%d %s %s %s</div>
|
|
|
|
|
</div>`, template.HTMLEscapeString(pr.Title),
|
|
|
|
|
template.HTMLEscapeString(pr.RepoOwner),
|
|
|
|
|
template.HTMLEscapeString(pr.RepoName),
|
|
|
|
|
pr.Number, labels, stats, mergeStatus)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
renderPage(w, r, "Pull Requests", "pulls", content)
|
|
|
|
|
renderPage(w, r, "Pull Requests", "pulls", buf.String())
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// IssueDetail handles GET /issues/{owner}/{repo}/{index}.
|
|
|
|
@@ -367,17 +364,6 @@ func (h *Handler) IssueDetail(w http.ResponseWriter, r *http.Request) {
|
|
|
|
|
labels = nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Render markdown body if present.
|
|
|
|
|
var renderedBody template.HTML
|
|
|
|
|
if issue.Body != "" {
|
|
|
|
|
rendered, err := h.Client.RenderMarkdown(r.Context(), token, issue.Body)
|
|
|
|
|
if err != nil {
|
|
|
|
|
slog.Warn("failed to render issue body markdown, using plain text", "error", err)
|
|
|
|
|
} else {
|
|
|
|
|
renderedBody = template.HTML(rendered)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Build the content HTML using the template.
|
|
|
|
|
tmpl, err := template.ParseFiles("internal/templates/issue_detail.html")
|
|
|
|
|
if err != nil {
|
|
|
|
@@ -388,14 +374,12 @@ func (h *Handler) IssueDetail(w http.ResponseWriter, r *http.Request) {
|
|
|
|
|
|
|
|
|
|
type templateData struct {
|
|
|
|
|
Issue *giteaclient.Issue
|
|
|
|
|
RenderedBody template.HTML
|
|
|
|
|
Comments []giteaclient.Comment
|
|
|
|
|
AvailableLabels []giteaclient.Label
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
data := templateData{
|
|
|
|
|
Issue: issue,
|
|
|
|
|
RenderedBody: renderedBody,
|
|
|
|
|
Comments: comments,
|
|
|
|
|
AvailableLabels: labels,
|
|
|
|
|
}
|
|
|
|
@@ -431,17 +415,6 @@ func (h *Handler) PullDetail(w http.ResponseWriter, r *http.Request) {
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Render markdown body if present.
|
|
|
|
|
var renderedBody template.HTML
|
|
|
|
|
if pr.Body != "" {
|
|
|
|
|
rendered, err := h.Client.RenderMarkdown(r.Context(), token, pr.Body)
|
|
|
|
|
if err != nil {
|
|
|
|
|
slog.Warn("failed to render PR body markdown, using plain text", "error", err)
|
|
|
|
|
} else {
|
|
|
|
|
renderedBody = template.HTML(rendered)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Build the content HTML using the template.
|
|
|
|
|
tmpl, err := template.ParseFiles("internal/templates/pull_detail.html")
|
|
|
|
|
if err != nil {
|
|
|
|
@@ -451,13 +424,11 @@ func (h *Handler) PullDetail(w http.ResponseWriter, r *http.Request) {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type templateData struct {
|
|
|
|
|
Pull *giteaclient.PullRequest
|
|
|
|
|
RenderedBody template.HTML
|
|
|
|
|
Pull *giteaclient.PullRequest
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
data := templateData{
|
|
|
|
|
Pull: pr,
|
|
|
|
|
RenderedBody: renderedBody,
|
|
|
|
|
Pull: pr,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var buf strings.Builder
|
|
|
|
|