2026-02-21 21:45:58 +00:00
|
|
|
package dev
|
|
|
|
|
|
|
|
|
|
import (
|
refactor: modernise to Go 1.26 — iterators, slices, maps, strings
- Add ParsePlaybookIter, ParseTasksIter, GetHostsIter, AllHostsIter (ansible)
- Add ListTemplatesIter (container), TargetsIter (build), LanguagesIter (sdk)
- Replace sort.Slice with slices.SortFunc across cmd/dev, cmd/qa, cmd/monitor, cmd/setup
- Replace manual map-key-sort with slices.Sorted(maps.Keys(...))
- Replace strings.Split with strings.SplitSeq where result is iterated (devkit)
- Replace range-over-int in complexity_test, ansible/modules, devops
- Remove redundant manual min() in favour of built-in
- 22 files, all tests pass
Co-Authored-By: Gemini <noreply@google.com>
Co-Authored-By: Virgil <virgil@lethean.io>
2026-02-23 06:24:26 +00:00
|
|
|
"slices"
|
2026-02-21 21:45:58 +00:00
|
|
|
"strings"
|
|
|
|
|
"time"
|
|
|
|
|
|
2026-03-12 19:04:41 +00:00
|
|
|
"code.gitea.io/sdk/gitea"
|
|
|
|
|
|
2026-02-22 23:27:33 +00:00
|
|
|
"forge.lthn.ai/core/cli/pkg/cli"
|
2026-03-22 00:04:10 +00:00
|
|
|
"dappco.re/go/core/i18n"
|
2026-02-21 21:45:58 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
// Issue-specific styles (aliases to shared)
|
|
|
|
|
var (
|
|
|
|
|
issueRepoStyle = cli.DimStyle
|
|
|
|
|
issueNumberStyle = cli.TitleStyle
|
|
|
|
|
issueTitleStyle = cli.ValueStyle
|
|
|
|
|
issueLabelStyle = cli.WarningStyle
|
|
|
|
|
issueAssigneeStyle = cli.SuccessStyle
|
|
|
|
|
issueAgeStyle = cli.DimStyle
|
|
|
|
|
)
|
|
|
|
|
|
2026-03-12 19:04:41 +00:00
|
|
|
// ForgeIssue holds display data for an issue.
|
|
|
|
|
type ForgeIssue struct {
|
|
|
|
|
Number int64
|
|
|
|
|
Title string
|
|
|
|
|
Author string
|
|
|
|
|
Assignees []string
|
|
|
|
|
Labels []string
|
|
|
|
|
CreatedAt time.Time
|
|
|
|
|
URL string
|
|
|
|
|
RepoName string
|
2026-02-21 21:45:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Issues command flags
|
|
|
|
|
var (
|
|
|
|
|
issuesRegistryPath string
|
|
|
|
|
issuesLimit int
|
|
|
|
|
issuesAssignee string
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
// addIssuesCommand adds the 'issues' command to the given parent command.
|
|
|
|
|
func addIssuesCommand(parent *cli.Command) {
|
|
|
|
|
issuesCmd := &cli.Command{
|
|
|
|
|
Use: "issues",
|
|
|
|
|
Short: i18n.T("cmd.dev.issues.short"),
|
|
|
|
|
Long: i18n.T("cmd.dev.issues.long"),
|
|
|
|
|
RunE: func(cmd *cli.Command, args []string) error {
|
|
|
|
|
limit := issuesLimit
|
|
|
|
|
if limit == 0 {
|
|
|
|
|
limit = 10
|
|
|
|
|
}
|
|
|
|
|
return runIssues(issuesRegistryPath, limit, issuesAssignee)
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
issuesCmd.Flags().StringVar(&issuesRegistryPath, "registry", "", i18n.T("common.flag.registry"))
|
|
|
|
|
issuesCmd.Flags().IntVarP(&issuesLimit, "limit", "l", 10, i18n.T("cmd.dev.issues.flag.limit"))
|
|
|
|
|
issuesCmd.Flags().StringVarP(&issuesAssignee, "assignee", "a", "", i18n.T("cmd.dev.issues.flag.assignee"))
|
|
|
|
|
|
|
|
|
|
parent.AddCommand(issuesCmd)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func runIssues(registryPath string, limit int, assignee string) error {
|
2026-03-12 19:04:41 +00:00
|
|
|
client, err := forgeAPIClient()
|
|
|
|
|
if err != nil {
|
|
|
|
|
return err
|
2026-02-21 21:45:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Find or use provided registry
|
|
|
|
|
reg, _, err := loadRegistryWithConfig(registryPath)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-12 19:04:41 +00:00
|
|
|
// Fetch issues sequentially
|
|
|
|
|
var allIssues []ForgeIssue
|
2026-02-21 21:45:58 +00:00
|
|
|
var fetchErrors []error
|
|
|
|
|
|
|
|
|
|
repoList := reg.List()
|
|
|
|
|
for i, repo := range repoList {
|
|
|
|
|
cli.Print("\033[2K\r%s %d/%d %s", dimStyle.Render(i18n.T("i18n.progress.fetch")), i+1, len(repoList), repo.Name)
|
|
|
|
|
|
2026-03-12 19:04:41 +00:00
|
|
|
owner, apiRepo := forgeRepoIdentity(repo.Path, reg.Org, repo.Name)
|
|
|
|
|
issues, err := fetchIssues(client, owner, apiRepo, repo.Name, limit, assignee)
|
2026-02-21 21:45:58 +00:00
|
|
|
if err != nil {
|
|
|
|
|
fetchErrors = append(fetchErrors, cli.Wrap(err, repo.Name))
|
|
|
|
|
continue
|
|
|
|
|
}
|
|
|
|
|
allIssues = append(allIssues, issues...)
|
|
|
|
|
}
|
|
|
|
|
cli.Print("\033[2K\r") // Clear progress line
|
|
|
|
|
|
|
|
|
|
// Sort by created date (newest first)
|
2026-03-12 19:04:41 +00:00
|
|
|
slices.SortFunc(allIssues, func(a, b ForgeIssue) int {
|
refactor: modernise to Go 1.26 — iterators, slices, maps, strings
- Add ParsePlaybookIter, ParseTasksIter, GetHostsIter, AllHostsIter (ansible)
- Add ListTemplatesIter (container), TargetsIter (build), LanguagesIter (sdk)
- Replace sort.Slice with slices.SortFunc across cmd/dev, cmd/qa, cmd/monitor, cmd/setup
- Replace manual map-key-sort with slices.Sorted(maps.Keys(...))
- Replace strings.Split with strings.SplitSeq where result is iterated (devkit)
- Replace range-over-int in complexity_test, ansible/modules, devops
- Remove redundant manual min() in favour of built-in
- 22 files, all tests pass
Co-Authored-By: Gemini <noreply@google.com>
Co-Authored-By: Virgil <virgil@lethean.io>
2026-02-23 06:24:26 +00:00
|
|
|
return b.CreatedAt.Compare(a.CreatedAt)
|
2026-02-21 21:45:58 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
|
|
// Print issues
|
|
|
|
|
if len(allIssues) == 0 {
|
|
|
|
|
cli.Text(i18n.T("cmd.dev.issues.no_issues"))
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
2026-02-24 15:37:42 +00:00
|
|
|
cli.Print("\n%s\n\n", i18n.T("cmd.dev.issues.open_issues", map[string]any{"Count": len(allIssues)}))
|
2026-02-21 21:45:58 +00:00
|
|
|
|
|
|
|
|
for _, issue := range allIssues {
|
|
|
|
|
printIssue(issue)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Print any errors
|
|
|
|
|
if len(fetchErrors) > 0 {
|
|
|
|
|
cli.Blank()
|
|
|
|
|
for _, err := range fetchErrors {
|
|
|
|
|
cli.Print("%s %s\n", errorStyle.Render(i18n.Label("error")), err)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-12 19:04:41 +00:00
|
|
|
func fetchIssues(client *gitea.Client, owner, apiRepo, displayName string, limit int, assignee string) ([]ForgeIssue, error) {
|
|
|
|
|
opts := gitea.ListIssueOption{
|
|
|
|
|
ListOptions: gitea.ListOptions{Page: 1, PageSize: limit},
|
|
|
|
|
State: gitea.StateOpen,
|
|
|
|
|
Type: gitea.IssueTypeIssue,
|
2026-02-21 21:45:58 +00:00
|
|
|
}
|
|
|
|
|
if assignee != "" {
|
2026-03-12 19:04:41 +00:00
|
|
|
opts.AssignedBy = assignee
|
2026-02-21 21:45:58 +00:00
|
|
|
}
|
|
|
|
|
|
2026-03-12 19:04:41 +00:00
|
|
|
issues, _, err := client.ListRepoIssues(owner, apiRepo, opts)
|
2026-02-21 21:45:58 +00:00
|
|
|
if err != nil {
|
2026-03-12 19:04:41 +00:00
|
|
|
errMsg := err.Error()
|
|
|
|
|
if strings.Contains(errMsg, "404") || strings.Contains(errMsg, "Not Found") {
|
|
|
|
|
return nil, nil
|
2026-02-21 21:45:58 +00:00
|
|
|
}
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-12 19:04:41 +00:00
|
|
|
var result []ForgeIssue
|
|
|
|
|
for _, issue := range issues {
|
|
|
|
|
fi := ForgeIssue{
|
|
|
|
|
Number: issue.Index,
|
|
|
|
|
Title: issue.Title,
|
|
|
|
|
CreatedAt: issue.Created,
|
|
|
|
|
URL: issue.HTMLURL,
|
|
|
|
|
RepoName: displayName,
|
|
|
|
|
}
|
|
|
|
|
if issue.Poster != nil {
|
|
|
|
|
fi.Author = issue.Poster.UserName
|
|
|
|
|
}
|
|
|
|
|
for _, a := range issue.Assignees {
|
|
|
|
|
fi.Assignees = append(fi.Assignees, a.UserName)
|
|
|
|
|
}
|
|
|
|
|
for _, l := range issue.Labels {
|
|
|
|
|
fi.Labels = append(fi.Labels, l.Name)
|
|
|
|
|
}
|
|
|
|
|
result = append(result, fi)
|
2026-02-21 21:45:58 +00:00
|
|
|
}
|
|
|
|
|
|
2026-03-12 19:04:41 +00:00
|
|
|
return result, nil
|
2026-02-21 21:45:58 +00:00
|
|
|
}
|
|
|
|
|
|
2026-03-12 19:04:41 +00:00
|
|
|
func printIssue(issue ForgeIssue) {
|
2026-02-21 21:45:58 +00:00
|
|
|
// #42 [core-bio] Fix avatar upload
|
|
|
|
|
num := issueNumberStyle.Render(cli.Sprintf("#%d", issue.Number))
|
|
|
|
|
repo := issueRepoStyle.Render(cli.Sprintf("[%s]", issue.RepoName))
|
|
|
|
|
title := issueTitleStyle.Render(cli.Truncate(issue.Title, 60))
|
|
|
|
|
|
|
|
|
|
line := cli.Sprintf(" %s %s %s", num, repo, title)
|
|
|
|
|
|
|
|
|
|
// Add labels if any
|
2026-03-12 19:04:41 +00:00
|
|
|
if len(issue.Labels) > 0 {
|
|
|
|
|
line += " " + issueLabelStyle.Render("["+strings.Join(issue.Labels, ", ")+"]")
|
2026-02-21 21:45:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Add assignee if any
|
2026-03-12 19:04:41 +00:00
|
|
|
if len(issue.Assignees) > 0 {
|
|
|
|
|
var tagged []string
|
|
|
|
|
for _, a := range issue.Assignees {
|
|
|
|
|
tagged = append(tagged, "@"+a)
|
2026-02-21 21:45:58 +00:00
|
|
|
}
|
2026-03-12 19:04:41 +00:00
|
|
|
line += " " + issueAssigneeStyle.Render(strings.Join(tagged, ", "))
|
2026-02-21 21:45:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Add age
|
|
|
|
|
age := cli.FormatAge(issue.CreatedAt)
|
|
|
|
|
line += " " + issueAgeStyle.Render(age)
|
|
|
|
|
|
|
|
|
|
cli.Text(line)
|
|
|
|
|
}
|