mirror of
https://gitea.com/gitea/tea.git
synced 2026-10-26 19:11:25 +01:00
repo list and search repo printed bare names. They now render a table with NAME, DESCRIPTION, INFO (public or private, fork, mirror, template, archived, empty) and UPDATED under "Showing N of M repositories ...", an empty-state message on stderr, and tab-separated rows with the URL when piped. --type, --sort and --order complete and validate their values. repo view shows the visibility and kind badges, stars, forks, open issues and pull requests, the parent of a fork, the source of a mirror, the default branch and the clone URLs, followed by the README of the default branch (or --branch), rendered on a terminal. The repository JSON gains empty, stars_count, forks_count, open_issues_count, open_pr_count, topics and updated_at. Signed-off-by: bircni <bircni@icloud.com>
69 lines
2.6 KiB
Go
69 lines
2.6 KiB
Go
// Copyright 2026 The Gitea Authors. All rights reserved.
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
package services
|
|
|
|
import gitea "gitea.dev/sdk"
|
|
|
|
// convertAll maps SDK items onto tea results as a non-nil slice, skipping absent items.
|
|
func convertAll[S, T any](items []*S, convert func(*S) T) []T {
|
|
result := make([]T, 0, len(items))
|
|
for _, item := range items {
|
|
if item != nil {
|
|
result = append(result, convert(item))
|
|
}
|
|
}
|
|
return result
|
|
}
|
|
|
|
func labelFrom(label *gitea.Label) Label {
|
|
return Label{ID: label.ID, Name: label.Name, Color: label.Color, Description: label.Description, Exclusive: label.Exclusive, Archived: label.IsArchived}
|
|
}
|
|
|
|
func repositoryFrom(repo *gitea.Repository) Repository {
|
|
result := Repository{
|
|
ActionsEnabled: repo.HasActions, Website: repo.Website, ID: repo.ID, Name: repo.Name,
|
|
FullName: repo.FullName, Description: repo.Description, URL: repo.HTMLURL, Private: repo.Private,
|
|
DefaultBranch: repo.DefaultBranch, CloneURL: repo.CloneURL, SSHURL: repo.SSHURL,
|
|
Archived: repo.Archived, Template: repo.Template, Fork: repo.Fork, Mirror: repo.Mirror, OriginalURL: repo.OriginalURL,
|
|
Empty: repo.Empty, Stars: repo.Stars, Forks: repo.Forks, OpenIssues: repo.OpenIssues, OpenPulls: repo.OpenPulls,
|
|
Topics: repo.Topics, UpdatedAt: timestamp(repo.Updated),
|
|
}
|
|
if repo.Parent != nil {
|
|
parent := repositoryFrom(repo.Parent)
|
|
result.Parent = &parent
|
|
}
|
|
return result
|
|
}
|
|
|
|
func organizationFrom(org *gitea.Organization) Organization {
|
|
name := org.Name
|
|
if name == "" {
|
|
name = org.UserName
|
|
}
|
|
return Organization{
|
|
ID: org.ID, Name: name, FullName: org.FullName, Description: org.Description, Website: org.Website,
|
|
Location: org.Location, Visibility: org.Visibility, RepoAdminChangeTeamAccess: org.RepoAdminChangeTeamAccess,
|
|
}
|
|
}
|
|
|
|
func memberFrom(user *gitea.User) OrganizationMember {
|
|
return OrganizationMember{ID: user.ID, Username: user.UserName, FullName: user.FullName}
|
|
}
|
|
|
|
func issueMilestoneFrom(milestone *gitea.Milestone) *IssueMilestone {
|
|
if milestone == nil {
|
|
return nil
|
|
}
|
|
return &IssueMilestone{ID: milestone.ID, Title: milestone.Title}
|
|
}
|
|
|
|
func issueFrom(issue *gitea.Issue) Issue {
|
|
return Issue{
|
|
Author: login(issue.Poster), Labels: convertAll(issue.Labels, labelFrom), Ref: issue.Ref, ID: issue.ID, Number: issue.Index,
|
|
Title: issue.Title, Body: issue.Body, URL: issue.HTMLURL, State: string(issue.State),
|
|
CreatedAt: timestamp(issue.Created), UpdatedAt: timestamp(issue.Updated), Deadline: optionalTimestamp(issue.Deadline),
|
|
Assignees: convertAll(issue.Assignees, login), Milestone: issueMilestoneFrom(issue.Milestone), Comments: int64(issue.Comments),
|
|
}
|
|
}
|