2025-12-08 09:49:07 +01:00
|
|
|
package cmd
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"fmt"
|
|
|
|
|
"os"
|
2025-12-16 12:38:19 +01:00
|
|
|
"os/exec"
|
|
|
|
|
"path/filepath"
|
2026-03-10 15:40:22 +01:00
|
|
|
"strings"
|
2025-12-08 09:49:07 +01:00
|
|
|
|
|
|
|
|
"code.gitea.io/sdk/gitea"
|
2026-04-26 08:16:52 -06:00
|
|
|
"forgejo.zerova.net/public/fj/internal/api"
|
|
|
|
|
"forgejo.zerova.net/public/fj/internal/config"
|
|
|
|
|
"forgejo.zerova.net/public/fj/internal/text"
|
2026-01-28 14:29:59 +01:00
|
|
|
"github.com/spf13/cobra"
|
2025-12-08 09:49:07 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
var repoCmd = &cobra.Command{
|
|
|
|
|
Use: "repo",
|
|
|
|
|
Short: "Manage repositories",
|
|
|
|
|
Long: "View and manage repositories.",
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var repoViewCmd = &cobra.Command{
|
|
|
|
|
Use: "view [owner/name]",
|
|
|
|
|
Short: "View repository details",
|
|
|
|
|
Long: "Display detailed information about a repository.",
|
|
|
|
|
Args: cobra.MaximumNArgs(1),
|
|
|
|
|
RunE: runRepoView,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var repoListCmd = &cobra.Command{
|
|
|
|
|
Use: "list",
|
|
|
|
|
Short: "List your repositories",
|
|
|
|
|
Long: "List repositories owned by the authenticated user.",
|
|
|
|
|
RunE: runRepoList,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var repoCloneCmd = &cobra.Command{
|
2025-12-16 12:38:19 +01:00
|
|
|
Use: "clone <owner/name> [destination]",
|
2025-12-08 09:49:07 +01:00
|
|
|
Short: "Clone a repository",
|
2025-12-16 12:38:19 +01:00
|
|
|
Long: "Clone a repository locally. If destination is not specified, the repository name is used.",
|
|
|
|
|
Args: cobra.RangeArgs(1, 2),
|
2025-12-08 09:49:07 +01:00
|
|
|
RunE: runRepoClone,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var repoForkCmd = &cobra.Command{
|
|
|
|
|
Use: "fork <owner/name>",
|
|
|
|
|
Short: "Fork a repository",
|
|
|
|
|
Long: "Create a fork of a repository.",
|
|
|
|
|
Args: cobra.ExactArgs(1),
|
|
|
|
|
RunE: runRepoFork,
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-10 15:40:22 +01:00
|
|
|
var repoCreateCmd = &cobra.Command{
|
|
|
|
|
Use: "create <name>",
|
|
|
|
|
Short: "Create a new repository",
|
|
|
|
|
Long: `Create a new repository on the Forgejo instance.
|
|
|
|
|
|
|
|
|
|
Name can be "reponame" (creates under your account) or "org/reponame"
|
|
|
|
|
(creates under an organization). Repositories are public by default; use --private to create a private one.`,
|
|
|
|
|
Args: cobra.ExactArgs(1),
|
|
|
|
|
RunE: runRepoCreate,
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-21 21:50:24 -06:00
|
|
|
var repoEditCmd = &cobra.Command{
|
|
|
|
|
Use: "edit [owner/name]",
|
|
|
|
|
Short: "Edit repository settings",
|
|
|
|
|
Long: "Edit settings of an existing repository such as visibility, description, homepage, and default branch.",
|
|
|
|
|
Example: ` # Make a repository private
|
2026-04-26 08:16:52 -06:00
|
|
|
fj repo edit owner/repo --private
|
2026-03-21 21:50:24 -06:00
|
|
|
|
|
|
|
|
# Make a repository public
|
2026-04-26 08:16:52 -06:00
|
|
|
fj repo edit owner/repo --public
|
2026-03-21 21:50:24 -06:00
|
|
|
|
|
|
|
|
# Update description and homepage
|
2026-04-26 08:16:52 -06:00
|
|
|
fj repo edit owner/repo -d "New description" --homepage https://example.com
|
2026-03-21 21:50:24 -06:00
|
|
|
|
|
|
|
|
# Change default branch
|
2026-04-26 08:16:52 -06:00
|
|
|
fj repo edit --default-branch develop
|
2026-03-21 21:50:24 -06:00
|
|
|
|
feat: v0.3.0d — add PR checks, iostreams, aliases, and broad enhancements
Add PR checks command, iostreams/text packages for colored table output,
top-level run/workflow aliases matching gh CLI structure. Enhance actions,
issues, PRs, releases, repos, labels, milestones, and wiki commands with
improved flags, JSON output, and error handling.
2026-03-23 11:42:44 -06:00
|
|
|
# Rename a repository
|
2026-04-26 08:16:52 -06:00
|
|
|
fj repo edit owner/repo --name new-name
|
feat: v0.3.0d — add PR checks, iostreams, aliases, and broad enhancements
Add PR checks command, iostreams/text packages for colored table output,
top-level run/workflow aliases matching gh CLI structure. Enhance actions,
issues, PRs, releases, repos, labels, milestones, and wiki commands with
improved flags, JSON output, and error handling.
2026-03-23 11:42:44 -06:00
|
|
|
|
2026-03-21 21:50:24 -06:00
|
|
|
# Edit current repo (auto-detected from git context)
|
2026-04-26 08:16:52 -06:00
|
|
|
fj repo edit --public`,
|
2026-03-21 21:50:24 -06:00
|
|
|
Args: cobra.MaximumNArgs(1),
|
|
|
|
|
RunE: runRepoEdit,
|
|
|
|
|
}
|
|
|
|
|
|
feat: v0.3.0d — add PR checks, iostreams, aliases, and broad enhancements
Add PR checks command, iostreams/text packages for colored table output,
top-level run/workflow aliases matching gh CLI structure. Enhance actions,
issues, PRs, releases, repos, labels, milestones, and wiki commands with
improved flags, JSON output, and error handling.
2026-03-23 11:42:44 -06:00
|
|
|
var repoRenameCmd = &cobra.Command{
|
|
|
|
|
Use: "rename <new-name>",
|
|
|
|
|
Short: "Rename a repository",
|
2026-04-26 08:16:52 -06:00
|
|
|
Long: "Rename an existing repository. This is a shorthand for `fj repo edit --name <new-name>`.",
|
feat: v0.3.0d — add PR checks, iostreams, aliases, and broad enhancements
Add PR checks command, iostreams/text packages for colored table output,
top-level run/workflow aliases matching gh CLI structure. Enhance actions,
issues, PRs, releases, repos, labels, milestones, and wiki commands with
improved flags, JSON output, and error handling.
2026-03-23 11:42:44 -06:00
|
|
|
Example: ` # Rename current repo
|
2026-04-26 08:16:52 -06:00
|
|
|
fj repo rename new-name
|
feat: v0.3.0d — add PR checks, iostreams, aliases, and broad enhancements
Add PR checks command, iostreams/text packages for colored table output,
top-level run/workflow aliases matching gh CLI structure. Enhance actions,
issues, PRs, releases, repos, labels, milestones, and wiki commands with
improved flags, JSON output, and error handling.
2026-03-23 11:42:44 -06:00
|
|
|
|
|
|
|
|
# Rename a specific repo
|
2026-04-26 08:16:52 -06:00
|
|
|
fj repo rename new-name -R owner/old-name`,
|
feat: v0.3.0d — add PR checks, iostreams, aliases, and broad enhancements
Add PR checks command, iostreams/text packages for colored table output,
top-level run/workflow aliases matching gh CLI structure. Enhance actions,
issues, PRs, releases, repos, labels, milestones, and wiki commands with
improved flags, JSON output, and error handling.
2026-03-23 11:42:44 -06:00
|
|
|
Args: cobra.ExactArgs(1),
|
|
|
|
|
RunE: runRepoRename,
|
|
|
|
|
}
|
|
|
|
|
|
2025-12-08 09:49:07 +01:00
|
|
|
func init() {
|
|
|
|
|
rootCmd.AddCommand(repoCmd)
|
|
|
|
|
repoCmd.AddCommand(repoCloneCmd)
|
2026-03-10 15:40:22 +01:00
|
|
|
repoCmd.AddCommand(repoCreateCmd)
|
2026-03-21 21:50:24 -06:00
|
|
|
repoCmd.AddCommand(repoEditCmd)
|
feat: v0.3.0d — add PR checks, iostreams, aliases, and broad enhancements
Add PR checks command, iostreams/text packages for colored table output,
top-level run/workflow aliases matching gh CLI structure. Enhance actions,
issues, PRs, releases, repos, labels, milestones, and wiki commands with
improved flags, JSON output, and error handling.
2026-03-23 11:42:44 -06:00
|
|
|
repoCmd.AddCommand(repoRenameCmd)
|
2025-12-08 09:49:07 +01:00
|
|
|
repoCmd.AddCommand(repoForkCmd)
|
2026-03-10 15:40:22 +01:00
|
|
|
repoCmd.AddCommand(repoListCmd)
|
|
|
|
|
repoCmd.AddCommand(repoViewCmd)
|
|
|
|
|
|
|
|
|
|
repoCreateCmd.Flags().StringP("description", "d", "", "Description of the repository")
|
|
|
|
|
repoCreateCmd.Flags().Bool("private", false, "Make the new repository private")
|
|
|
|
|
repoCreateCmd.Flags().Bool("public", false, "Make the new repository public")
|
|
|
|
|
repoCreateCmd.Flags().Bool("add-readme", false, "Add a README file to the new repository")
|
|
|
|
|
repoCreateCmd.Flags().StringP("gitignore", "g", "", "Gitignore template (e.g. Go, Python)")
|
|
|
|
|
repoCreateCmd.Flags().StringP("license", "l", "", "License template (e.g. MIT, Apache-2.0)")
|
|
|
|
|
repoCreateCmd.Flags().String("homepage", "", "Repository home page URL")
|
|
|
|
|
repoCreateCmd.Flags().BoolP("clone", "c", false, "Clone the new repository to the current directory")
|
|
|
|
|
repoCreateCmd.Flags().StringP("team", "t", "", "Team name to be granted access (org repos only)")
|
|
|
|
|
repoCreateCmd.MarkFlagsMutuallyExclusive("public", "private")
|
2025-12-08 09:49:07 +01:00
|
|
|
|
feat: v0.3.0d — add PR checks, iostreams, aliases, and broad enhancements
Add PR checks command, iostreams/text packages for colored table output,
top-level run/workflow aliases matching gh CLI structure. Enhance actions,
issues, PRs, releases, repos, labels, milestones, and wiki commands with
improved flags, JSON output, and error handling.
2026-03-23 11:42:44 -06:00
|
|
|
addJSONFlags(repoViewCmd, "Output repository as JSON")
|
|
|
|
|
repoViewCmd.Flags().BoolP("web", "w", false, "Open in web browser")
|
|
|
|
|
|
|
|
|
|
addJSONFlags(repoListCmd, "Output repositories as JSON")
|
2026-03-23 12:39:51 -06:00
|
|
|
repoListCmd.Flags().IntP("limit", "L", 0, "Maximum number of repositories to list (0 = no limit)")
|
feat: v0.3.0d — add PR checks, iostreams, aliases, and broad enhancements
Add PR checks command, iostreams/text packages for colored table output,
top-level run/workflow aliases matching gh CLI structure. Enhance actions,
issues, PRs, releases, repos, labels, milestones, and wiki commands with
improved flags, JSON output, and error handling.
2026-03-23 11:42:44 -06:00
|
|
|
|
2025-12-08 09:49:07 +01:00
|
|
|
repoCloneCmd.Flags().StringP("protocol", "p", "https", "Clone protocol: https or ssh")
|
2026-03-21 21:50:24 -06:00
|
|
|
|
|
|
|
|
repoEditCmd.Flags().StringP("repo", "R", "", "Repository in owner/name format")
|
feat: v0.3.0d — add PR checks, iostreams, aliases, and broad enhancements
Add PR checks command, iostreams/text packages for colored table output,
top-level run/workflow aliases matching gh CLI structure. Enhance actions,
issues, PRs, releases, repos, labels, milestones, and wiki commands with
improved flags, JSON output, and error handling.
2026-03-23 11:42:44 -06:00
|
|
|
repoEditCmd.Flags().String("name", "", "Rename the repository")
|
2026-03-21 21:50:24 -06:00
|
|
|
repoEditCmd.Flags().StringP("description", "d", "", "Repository description")
|
|
|
|
|
repoEditCmd.Flags().String("homepage", "", "Repository home page URL")
|
|
|
|
|
repoEditCmd.Flags().String("default-branch", "", "Default branch name")
|
|
|
|
|
repoEditCmd.Flags().Bool("private", false, "Make the repository private")
|
|
|
|
|
repoEditCmd.Flags().Bool("public", false, "Make the repository public")
|
feat: v0.3.0d — add PR checks, iostreams, aliases, and broad enhancements
Add PR checks command, iostreams/text packages for colored table output,
top-level run/workflow aliases matching gh CLI structure. Enhance actions,
issues, PRs, releases, repos, labels, milestones, and wiki commands with
improved flags, JSON output, and error handling.
2026-03-23 11:42:44 -06:00
|
|
|
addJSONFlags(repoEditCmd, "Output updated repository as JSON")
|
2026-03-21 21:50:24 -06:00
|
|
|
repoEditCmd.MarkFlagsMutuallyExclusive("public", "private")
|
feat: v0.3.0d — add PR checks, iostreams, aliases, and broad enhancements
Add PR checks command, iostreams/text packages for colored table output,
top-level run/workflow aliases matching gh CLI structure. Enhance actions,
issues, PRs, releases, repos, labels, milestones, and wiki commands with
improved flags, JSON output, and error handling.
2026-03-23 11:42:44 -06:00
|
|
|
|
|
|
|
|
repoRenameCmd.Flags().StringP("repo", "R", "", "Repository in owner/name format")
|
|
|
|
|
addJSONFlags(repoRenameCmd, "Output updated repository as JSON")
|
2025-12-08 09:49:07 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func runRepoView(cmd *cobra.Command, args []string) error {
|
|
|
|
|
var repo string
|
|
|
|
|
if len(args) > 0 {
|
|
|
|
|
repo = args[0]
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
owner, name, err := parseRepo(repo)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
cfg, err := config.Load()
|
|
|
|
|
if err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-23 12:39:51 -06:00
|
|
|
client, err := api.NewClientFromConfig(cfg, "", getDetectedHost(), getCwd())
|
2025-12-08 09:49:07 +01:00
|
|
|
if err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
|
feat: v0.3.0d — add PR checks, iostreams, aliases, and broad enhancements
Add PR checks command, iostreams/text packages for colored table output,
top-level run/workflow aliases matching gh CLI structure. Enhance actions,
issues, PRs, releases, repos, labels, milestones, and wiki commands with
improved flags, JSON output, and error handling.
2026-03-23 11:42:44 -06:00
|
|
|
ios.StartSpinner("Fetching repository...")
|
2025-12-08 09:49:07 +01:00
|
|
|
repository, _, err := client.GetRepo(owner, name)
|
feat: v0.3.0d — add PR checks, iostreams, aliases, and broad enhancements
Add PR checks command, iostreams/text packages for colored table output,
top-level run/workflow aliases matching gh CLI structure. Enhance actions,
issues, PRs, releases, repos, labels, milestones, and wiki commands with
improved flags, JSON output, and error handling.
2026-03-23 11:42:44 -06:00
|
|
|
ios.StopSpinner()
|
2025-12-08 09:49:07 +01:00
|
|
|
if err != nil {
|
|
|
|
|
return fmt.Errorf("failed to get repository: %w", err)
|
|
|
|
|
}
|
|
|
|
|
|
feat: v0.3.0d — add PR checks, iostreams, aliases, and broad enhancements
Add PR checks command, iostreams/text packages for colored table output,
top-level run/workflow aliases matching gh CLI structure. Enhance actions,
issues, PRs, releases, repos, labels, milestones, and wiki commands with
improved flags, JSON output, and error handling.
2026-03-23 11:42:44 -06:00
|
|
|
if web, _ := cmd.Flags().GetBool("web"); web {
|
|
|
|
|
return ios.OpenInBrowser(repository.HTMLURL)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if wantJSON(cmd) {
|
|
|
|
|
return outputJSON(cmd, repository)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
cs := ios.ColorScheme()
|
|
|
|
|
isTTY := ios.IsStdoutTTY()
|
|
|
|
|
|
|
|
|
|
fmt.Fprintf(ios.Out, "Repository: %s\n", cs.Bold(fmt.Sprintf("%s/%s", repository.Owner.UserName, repository.Name)))
|
|
|
|
|
fmt.Fprintf(ios.Out, "Description: %s\n", repository.Description)
|
|
|
|
|
fmt.Fprintf(ios.Out, "URL: %s\n", repository.HTMLURL)
|
|
|
|
|
fmt.Fprintf(ios.Out, "Clone URL (HTTPS): %s\n", repository.CloneURL)
|
|
|
|
|
fmt.Fprintf(ios.Out, "Clone URL (SSH): %s\n", repository.SSHURL)
|
|
|
|
|
fmt.Fprintf(ios.Out, "Default Branch: %s\n", repository.DefaultBranch)
|
|
|
|
|
fmt.Fprintf(ios.Out, "Stars: %d\n", repository.Stars)
|
|
|
|
|
fmt.Fprintf(ios.Out, "Forks: %d\n", repository.Forks)
|
|
|
|
|
fmt.Fprintf(ios.Out, "Open Issues: %d\n", repository.OpenIssues)
|
|
|
|
|
fmt.Fprintf(ios.Out, "Private: %v\n", repository.Private)
|
|
|
|
|
fmt.Fprintf(ios.Out, "Created: %s\n", text.FormatDate(repository.Created, isTTY))
|
|
|
|
|
fmt.Fprintf(ios.Out, "Updated: %s\n", text.FormatDate(repository.Updated, isTTY))
|
2025-12-08 09:49:07 +01:00
|
|
|
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func runRepoList(cmd *cobra.Command, args []string) error {
|
|
|
|
|
cfg, err := config.Load()
|
|
|
|
|
if err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-23 12:39:51 -06:00
|
|
|
client, err := api.NewClientFromConfig(cfg, "", getDetectedHost(), getCwd())
|
2025-12-08 09:49:07 +01:00
|
|
|
if err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
|
feat: v0.3.0d — add PR checks, iostreams, aliases, and broad enhancements
Add PR checks command, iostreams/text packages for colored table output,
top-level run/workflow aliases matching gh CLI structure. Enhance actions,
issues, PRs, releases, repos, labels, milestones, and wiki commands with
improved flags, JSON output, and error handling.
2026-03-23 11:42:44 -06:00
|
|
|
ios.StartSpinner("Fetching repositories...")
|
2025-12-08 09:49:07 +01:00
|
|
|
user, _, err := client.GetMyUserInfo()
|
|
|
|
|
if err != nil {
|
feat: v0.3.0d — add PR checks, iostreams, aliases, and broad enhancements
Add PR checks command, iostreams/text packages for colored table output,
top-level run/workflow aliases matching gh CLI structure. Enhance actions,
issues, PRs, releases, repos, labels, milestones, and wiki commands with
improved flags, JSON output, and error handling.
2026-03-23 11:42:44 -06:00
|
|
|
ios.StopSpinner()
|
2025-12-08 09:49:07 +01:00
|
|
|
return fmt.Errorf("failed to get user info: %w", err)
|
|
|
|
|
}
|
|
|
|
|
|
feat(cmd): pagination unification + `fj api --paginate`
Before this, only `release list` walked pages. `repo list`, `pr list` (the
non-filter branch), and `issue list` all passed `PageSize: limit` directly
to the gitea SDK — which silently caps PageSize at 50, so any request for
more than 50 results was truncated to 50 with no warning. `--limit` was
effectively a per-page hint, not a real limit.
## Changes
- New `cmd/paginate.go` — generic `paginateGitea[T any]` that walks pages
until the response is short or the limit is reached. Uses Go 1.20
generics so each list command keeps its existing typed slice without
conversion overhead.
- `repo list` — paginates ListUserRepos.
- `pr list` — paginates ListRepoPullRequests in both branches:
- With client-side filters (assignee, author, labels, search, draft,
head, base): pull all pages then filter+limit.
- Without filters: paginate up to limit.
- `issue list` — paginates ListRepoIssues. Overshoots 2x because the API
returns both issues AND PRs and we filter PRs out client-side; the
overshoot keeps us bounded but reduces the chance of returning fewer
results than `--limit`.
## `fj api --paginate`
Mirrors `gh api --paginate`:
- Follows RFC 5988 `Link: rel="next"` headers (Forgejo emits these on
list endpoints).
- Concatenates each page's JSON array into a single array via
`concatPaginatedJSON`. If a page is not a JSON array, errors with a
clear message — `--paginate` only makes sense for paginatable endpoints.
- GET-only (errors on POST/PUT/DELETE).
- Reuses the same auth and custom headers across pages; the body-size
limit applies per-page.
Refactored the request execution into a `doOnce` closure so the loop body
isn't a copy of the single-request path.
Verified live:
$ fj api 'repos/public/claude-code-proxy/commits?limit=2' \
--paginate --jq '. | length'
44
(44 = total commits in the repo, walked via Link headers from a 2-per-page
starting query.)
Out of scope for this commit, deferred:
- De-duplicating cmd/aliases.go ↔ cmd/actions.go subtrees (the type
mismatch they caused is already fixed in the prior commit; the
duplication itself is polish).
2026-05-02 15:46:22 -06:00
|
|
|
limit, _ := cmd.Flags().GetInt("limit")
|
|
|
|
|
repos, err := paginateGitea(limit, func(page, pageSize int) ([]*gitea.Repository, error) {
|
|
|
|
|
batch, _, err := client.ListUserRepos(user.UserName, gitea.ListReposOptions{
|
|
|
|
|
ListOptions: gitea.ListOptions{Page: page, PageSize: pageSize},
|
|
|
|
|
})
|
|
|
|
|
return batch, err
|
|
|
|
|
})
|
feat: v0.3.0d — add PR checks, iostreams, aliases, and broad enhancements
Add PR checks command, iostreams/text packages for colored table output,
top-level run/workflow aliases matching gh CLI structure. Enhance actions,
issues, PRs, releases, repos, labels, milestones, and wiki commands with
improved flags, JSON output, and error handling.
2026-03-23 11:42:44 -06:00
|
|
|
ios.StopSpinner()
|
2025-12-08 09:49:07 +01:00
|
|
|
if err != nil {
|
|
|
|
|
return fmt.Errorf("failed to list repositories: %w", err)
|
|
|
|
|
}
|
|
|
|
|
|
feat: v0.3.0d — add PR checks, iostreams, aliases, and broad enhancements
Add PR checks command, iostreams/text packages for colored table output,
top-level run/workflow aliases matching gh CLI structure. Enhance actions,
issues, PRs, releases, repos, labels, milestones, and wiki commands with
improved flags, JSON output, and error handling.
2026-03-23 11:42:44 -06:00
|
|
|
if wantJSON(cmd) {
|
|
|
|
|
return outputJSON(cmd, repos)
|
|
|
|
|
}
|
|
|
|
|
|
2025-12-08 09:49:07 +01:00
|
|
|
if len(repos) == 0 {
|
feat: v0.3.0d — add PR checks, iostreams, aliases, and broad enhancements
Add PR checks command, iostreams/text packages for colored table output,
top-level run/workflow aliases matching gh CLI structure. Enhance actions,
issues, PRs, releases, repos, labels, milestones, and wiki commands with
improved flags, JSON output, and error handling.
2026-03-23 11:42:44 -06:00
|
|
|
fmt.Fprintln(ios.Out, "No repositories found")
|
2025-12-08 09:49:07 +01:00
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
feat: v0.3.0d — add PR checks, iostreams, aliases, and broad enhancements
Add PR checks command, iostreams/text packages for colored table output,
top-level run/workflow aliases matching gh CLI structure. Enhance actions,
issues, PRs, releases, repos, labels, milestones, and wiki commands with
improved flags, JSON output, and error handling.
2026-03-23 11:42:44 -06:00
|
|
|
tp := ios.NewTablePrinter()
|
|
|
|
|
tp.AddHeader("NAME", "VISIBILITY", "DESCRIPTION")
|
2025-12-08 09:49:07 +01:00
|
|
|
for _, repo := range repos {
|
|
|
|
|
visibility := "public"
|
|
|
|
|
if repo.Private {
|
|
|
|
|
visibility = "private"
|
|
|
|
|
}
|
feat: v0.3.0d — add PR checks, iostreams, aliases, and broad enhancements
Add PR checks command, iostreams/text packages for colored table output,
top-level run/workflow aliases matching gh CLI structure. Enhance actions,
issues, PRs, releases, repos, labels, milestones, and wiki commands with
improved flags, JSON output, and error handling.
2026-03-23 11:42:44 -06:00
|
|
|
desc := text.Truncate(repo.Description, 50)
|
|
|
|
|
tp.AddRow(fmt.Sprintf("%s/%s", repo.Owner.UserName, repo.Name), visibility, desc)
|
2025-12-08 09:49:07 +01:00
|
|
|
}
|
feat: v0.3.0d — add PR checks, iostreams, aliases, and broad enhancements
Add PR checks command, iostreams/text packages for colored table output,
top-level run/workflow aliases matching gh CLI structure. Enhance actions,
issues, PRs, releases, repos, labels, milestones, and wiki commands with
improved flags, JSON output, and error handling.
2026-03-23 11:42:44 -06:00
|
|
|
return tp.Render()
|
2025-12-08 09:49:07 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func runRepoClone(cmd *cobra.Command, args []string) error {
|
|
|
|
|
repo := args[0]
|
|
|
|
|
protocol, _ := cmd.Flags().GetString("protocol")
|
|
|
|
|
|
|
|
|
|
owner, name, err := parseRepo(repo)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
cfg, err := config.Load()
|
|
|
|
|
if err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-23 12:39:51 -06:00
|
|
|
client, err := api.NewClientFromConfig(cfg, "", getDetectedHost(), getCwd())
|
2025-12-08 09:49:07 +01:00
|
|
|
if err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
|
feat: v0.3.0d — add PR checks, iostreams, aliases, and broad enhancements
Add PR checks command, iostreams/text packages for colored table output,
top-level run/workflow aliases matching gh CLI structure. Enhance actions,
issues, PRs, releases, repos, labels, milestones, and wiki commands with
improved flags, JSON output, and error handling.
2026-03-23 11:42:44 -06:00
|
|
|
ios.StartSpinner("Fetching repository info...")
|
2025-12-08 09:49:07 +01:00
|
|
|
repository, _, err := client.GetRepo(owner, name)
|
feat: v0.3.0d — add PR checks, iostreams, aliases, and broad enhancements
Add PR checks command, iostreams/text packages for colored table output,
top-level run/workflow aliases matching gh CLI structure. Enhance actions,
issues, PRs, releases, repos, labels, milestones, and wiki commands with
improved flags, JSON output, and error handling.
2026-03-23 11:42:44 -06:00
|
|
|
ios.StopSpinner()
|
2025-12-08 09:49:07 +01:00
|
|
|
if err != nil {
|
|
|
|
|
return fmt.Errorf("failed to get repository: %w", err)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var cloneURL string
|
|
|
|
|
if protocol == "ssh" {
|
|
|
|
|
cloneURL = repository.SSHURL
|
|
|
|
|
} else {
|
|
|
|
|
cloneURL = repository.CloneURL
|
|
|
|
|
}
|
|
|
|
|
|
2025-12-16 12:38:19 +01:00
|
|
|
// Determine destination path
|
|
|
|
|
var destination string
|
|
|
|
|
if len(args) > 1 {
|
|
|
|
|
destination = args[1]
|
|
|
|
|
} else {
|
|
|
|
|
destination = name
|
|
|
|
|
}
|
|
|
|
|
|
feat: v0.3.0d — add PR checks, iostreams, aliases, and broad enhancements
Add PR checks command, iostreams/text packages for colored table output,
top-level run/workflow aliases matching gh CLI structure. Enhance actions,
issues, PRs, releases, repos, labels, milestones, and wiki commands with
improved flags, JSON output, and error handling.
2026-03-23 11:42:44 -06:00
|
|
|
fmt.Fprintf(ios.Out, "Cloning %s/%s to %s...\n", owner, name, destination)
|
2025-12-16 12:38:19 +01:00
|
|
|
|
|
|
|
|
// Create parent directory if it doesn't exist
|
|
|
|
|
if dir := filepath.Dir(destination); dir != "." {
|
|
|
|
|
if err := os.MkdirAll(dir, 0755); err != nil {
|
|
|
|
|
return fmt.Errorf("failed to create destination directory: %w", err)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
feat: v0.3.0d — add PR checks, iostreams, aliases, and broad enhancements
Add PR checks command, iostreams/text packages for colored table output,
top-level run/workflow aliases matching gh CLI structure. Enhance actions,
issues, PRs, releases, repos, labels, milestones, and wiki commands with
improved flags, JSON output, and error handling.
2026-03-23 11:42:44 -06:00
|
|
|
ios.StartSpinner("Cloning repository...")
|
2025-12-16 12:38:19 +01:00
|
|
|
// Execute git clone
|
|
|
|
|
gitCmd := exec.Command("git", "clone", cloneURL, destination)
|
feat: v0.3.0d — add PR checks, iostreams, aliases, and broad enhancements
Add PR checks command, iostreams/text packages for colored table output,
top-level run/workflow aliases matching gh CLI structure. Enhance actions,
issues, PRs, releases, repos, labels, milestones, and wiki commands with
improved flags, JSON output, and error handling.
2026-03-23 11:42:44 -06:00
|
|
|
gitCmd.Stdout = ios.Out
|
|
|
|
|
gitCmd.Stderr = ios.ErrOut
|
|
|
|
|
gitCmd.Stdin = ios.In
|
2025-12-16 12:38:19 +01:00
|
|
|
|
|
|
|
|
if err := gitCmd.Run(); err != nil {
|
feat: v0.3.0d — add PR checks, iostreams, aliases, and broad enhancements
Add PR checks command, iostreams/text packages for colored table output,
top-level run/workflow aliases matching gh CLI structure. Enhance actions,
issues, PRs, releases, repos, labels, milestones, and wiki commands with
improved flags, JSON output, and error handling.
2026-03-23 11:42:44 -06:00
|
|
|
ios.StopSpinner()
|
2025-12-16 12:38:19 +01:00
|
|
|
return fmt.Errorf("failed to clone repository: %w", err)
|
|
|
|
|
}
|
feat: v0.3.0d — add PR checks, iostreams, aliases, and broad enhancements
Add PR checks command, iostreams/text packages for colored table output,
top-level run/workflow aliases matching gh CLI structure. Enhance actions,
issues, PRs, releases, repos, labels, milestones, and wiki commands with
improved flags, JSON output, and error handling.
2026-03-23 11:42:44 -06:00
|
|
|
ios.StopSpinner()
|
2025-12-08 09:49:07 +01:00
|
|
|
|
feat: v0.3.0d — add PR checks, iostreams, aliases, and broad enhancements
Add PR checks command, iostreams/text packages for colored table output,
top-level run/workflow aliases matching gh CLI structure. Enhance actions,
issues, PRs, releases, repos, labels, milestones, and wiki commands with
improved flags, JSON output, and error handling.
2026-03-23 11:42:44 -06:00
|
|
|
cs := ios.ColorScheme()
|
|
|
|
|
fmt.Fprintf(ios.Out, "%s Repository cloned successfully to %s\n", cs.SuccessIcon(), destination)
|
2025-12-08 09:49:07 +01:00
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func runRepoFork(cmd *cobra.Command, args []string) error {
|
|
|
|
|
repo := args[0]
|
|
|
|
|
|
|
|
|
|
owner, name, err := parseRepo(repo)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
cfg, err := config.Load()
|
|
|
|
|
if err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-23 12:39:51 -06:00
|
|
|
client, err := api.NewClientFromConfig(cfg, "", getDetectedHost(), getCwd())
|
2025-12-08 09:49:07 +01:00
|
|
|
if err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
|
feat: v0.3.0d — add PR checks, iostreams, aliases, and broad enhancements
Add PR checks command, iostreams/text packages for colored table output,
top-level run/workflow aliases matching gh CLI structure. Enhance actions,
issues, PRs, releases, repos, labels, milestones, and wiki commands with
improved flags, JSON output, and error handling.
2026-03-23 11:42:44 -06:00
|
|
|
ios.StartSpinner("Forking repository...")
|
2025-12-08 09:49:07 +01:00
|
|
|
fork, _, err := client.CreateFork(owner, name, gitea.CreateForkOption{})
|
feat: v0.3.0d — add PR checks, iostreams, aliases, and broad enhancements
Add PR checks command, iostreams/text packages for colored table output,
top-level run/workflow aliases matching gh CLI structure. Enhance actions,
issues, PRs, releases, repos, labels, milestones, and wiki commands with
improved flags, JSON output, and error handling.
2026-03-23 11:42:44 -06:00
|
|
|
ios.StopSpinner()
|
2025-12-08 09:49:07 +01:00
|
|
|
if err != nil {
|
|
|
|
|
return fmt.Errorf("failed to fork repository: %w", err)
|
|
|
|
|
}
|
|
|
|
|
|
feat: v0.3.0d — add PR checks, iostreams, aliases, and broad enhancements
Add PR checks command, iostreams/text packages for colored table output,
top-level run/workflow aliases matching gh CLI structure. Enhance actions,
issues, PRs, releases, repos, labels, milestones, and wiki commands with
improved flags, JSON output, and error handling.
2026-03-23 11:42:44 -06:00
|
|
|
cs := ios.ColorScheme()
|
|
|
|
|
fmt.Fprintf(ios.Out, "%s Repository forked successfully\n", cs.SuccessIcon())
|
|
|
|
|
fmt.Fprintf(ios.Out, "View at: %s\n", fork.HTMLURL)
|
|
|
|
|
fmt.Fprintf(ios.Out, "Clone URL: %s\n", fork.CloneURL)
|
2025-12-08 09:49:07 +01:00
|
|
|
|
|
|
|
|
return nil
|
|
|
|
|
}
|
2026-03-10 15:40:22 +01:00
|
|
|
|
|
|
|
|
func runRepoCreate(cmd *cobra.Command, args []string) error {
|
|
|
|
|
inputName := args[0]
|
|
|
|
|
org, repoName, isOrg, err := parseCreateName(inputName)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private, _ := cmd.Flags().GetBool("private")
|
2026-03-21 21:50:24 -06:00
|
|
|
public, _ := cmd.Flags().GetBool("public")
|
2026-03-10 15:40:22 +01:00
|
|
|
description, _ := cmd.Flags().GetString("description")
|
|
|
|
|
addReadme, _ := cmd.Flags().GetBool("add-readme")
|
|
|
|
|
gitignore, _ := cmd.Flags().GetString("gitignore")
|
|
|
|
|
license, _ := cmd.Flags().GetString("license")
|
|
|
|
|
homepage, _ := cmd.Flags().GetString("homepage")
|
|
|
|
|
doClone, _ := cmd.Flags().GetBool("clone")
|
|
|
|
|
team, _ := cmd.Flags().GetString("team")
|
|
|
|
|
|
2026-03-21 21:50:24 -06:00
|
|
|
// --public explicitly sets private=false (default behavior, but makes intent clear)
|
|
|
|
|
if public {
|
|
|
|
|
private = false
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-10 15:40:22 +01:00
|
|
|
cfg, err := config.Load()
|
|
|
|
|
if err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-23 12:39:51 -06:00
|
|
|
client, err := api.NewClientFromConfig(cfg, "", getDetectedHost(), getCwd())
|
2026-03-10 15:40:22 +01:00
|
|
|
if err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
opt := gitea.CreateRepoOption{
|
|
|
|
|
Name: repoName,
|
|
|
|
|
Description: description,
|
|
|
|
|
Private: private,
|
|
|
|
|
AutoInit: addReadme,
|
|
|
|
|
Gitignores: gitignore,
|
|
|
|
|
License: license,
|
|
|
|
|
}
|
|
|
|
|
|
feat: v0.3.0d — add PR checks, iostreams, aliases, and broad enhancements
Add PR checks command, iostreams/text packages for colored table output,
top-level run/workflow aliases matching gh CLI structure. Enhance actions,
issues, PRs, releases, repos, labels, milestones, and wiki commands with
improved flags, JSON output, and error handling.
2026-03-23 11:42:44 -06:00
|
|
|
ios.StartSpinner("Creating repository...")
|
2026-03-10 15:40:22 +01:00
|
|
|
var repo *gitea.Repository
|
|
|
|
|
if isOrg {
|
|
|
|
|
repo, _, err = client.CreateOrgRepo(org, opt)
|
|
|
|
|
} else {
|
|
|
|
|
repo, _, err = client.CreateRepo(opt)
|
|
|
|
|
}
|
feat: v0.3.0d — add PR checks, iostreams, aliases, and broad enhancements
Add PR checks command, iostreams/text packages for colored table output,
top-level run/workflow aliases matching gh CLI structure. Enhance actions,
issues, PRs, releases, repos, labels, milestones, and wiki commands with
improved flags, JSON output, and error handling.
2026-03-23 11:42:44 -06:00
|
|
|
ios.StopSpinner()
|
2026-03-10 15:40:22 +01:00
|
|
|
if err != nil {
|
|
|
|
|
return fmt.Errorf("failed to create repository: %w", err)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if homepage != "" {
|
|
|
|
|
ownerName := org
|
|
|
|
|
if !isOrg {
|
|
|
|
|
// For personal repos, get the owner from the created repo or fall back to API
|
|
|
|
|
if repo.Owner != nil {
|
|
|
|
|
ownerName = repo.Owner.UserName
|
|
|
|
|
} else {
|
|
|
|
|
user, _, userErr := client.GetMyUserInfo()
|
|
|
|
|
if userErr != nil {
|
feat: v0.3.0d — add PR checks, iostreams, aliases, and broad enhancements
Add PR checks command, iostreams/text packages for colored table output,
top-level run/workflow aliases matching gh CLI structure. Enhance actions,
issues, PRs, releases, repos, labels, milestones, and wiki commands with
improved flags, JSON output, and error handling.
2026-03-23 11:42:44 -06:00
|
|
|
fmt.Fprintf(ios.ErrOut, "warning: repository created but could not determine owner for homepage: %v\n", userErr)
|
2026-03-10 15:40:22 +01:00
|
|
|
homepage = "" // skip EditRepo
|
|
|
|
|
} else {
|
|
|
|
|
ownerName = user.UserName
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if homepage != "" {
|
|
|
|
|
_, _, err = client.EditRepo(ownerName, repo.Name, gitea.EditRepoOption{
|
|
|
|
|
Website: &homepage,
|
|
|
|
|
})
|
|
|
|
|
if err != nil {
|
feat: v0.3.0d — add PR checks, iostreams, aliases, and broad enhancements
Add PR checks command, iostreams/text packages for colored table output,
top-level run/workflow aliases matching gh CLI structure. Enhance actions,
issues, PRs, releases, repos, labels, milestones, and wiki commands with
improved flags, JSON output, and error handling.
2026-03-23 11:42:44 -06:00
|
|
|
fmt.Fprintf(ios.ErrOut, "warning: repository created but failed to set homepage: %v\n", err)
|
2026-03-10 15:40:22 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if team != "" {
|
|
|
|
|
if !isOrg {
|
feat: v0.3.0d — add PR checks, iostreams, aliases, and broad enhancements
Add PR checks command, iostreams/text packages for colored table output,
top-level run/workflow aliases matching gh CLI structure. Enhance actions,
issues, PRs, releases, repos, labels, milestones, and wiki commands with
improved flags, JSON output, and error handling.
2026-03-23 11:42:44 -06:00
|
|
|
fmt.Fprintln(ios.ErrOut, "warning: --team is only meaningful for organization repositories")
|
2026-03-10 15:40:22 +01:00
|
|
|
} else {
|
|
|
|
|
_, err = client.AddRepoTeam(org, repo.Name, team)
|
|
|
|
|
if err != nil {
|
feat: v0.3.0d — add PR checks, iostreams, aliases, and broad enhancements
Add PR checks command, iostreams/text packages for colored table output,
top-level run/workflow aliases matching gh CLI structure. Enhance actions,
issues, PRs, releases, repos, labels, milestones, and wiki commands with
improved flags, JSON output, and error handling.
2026-03-23 11:42:44 -06:00
|
|
|
fmt.Fprintf(ios.ErrOut, "warning: repository created but failed to add team %q: %v\n", team, err)
|
2026-03-10 15:40:22 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
feat: v0.3.0d — add PR checks, iostreams, aliases, and broad enhancements
Add PR checks command, iostreams/text packages for colored table output,
top-level run/workflow aliases matching gh CLI structure. Enhance actions,
issues, PRs, releases, repos, labels, milestones, and wiki commands with
improved flags, JSON output, and error handling.
2026-03-23 11:42:44 -06:00
|
|
|
cs := ios.ColorScheme()
|
|
|
|
|
fmt.Fprintf(ios.Out, "%s Repository created: %s\n", cs.SuccessIcon(), repo.HTMLURL)
|
2026-03-10 15:40:22 +01:00
|
|
|
|
|
|
|
|
if doClone {
|
|
|
|
|
cloneURL := repo.CloneURL
|
2026-03-23 12:39:51 -06:00
|
|
|
if hostCfg, hostErr := cfg.GetHost("", getDetectedHost(), getCwd()); hostErr == nil {
|
2026-03-10 15:40:22 +01:00
|
|
|
if hostCfg.GitProtocol == "ssh" {
|
|
|
|
|
cloneURL = repo.SSHURL
|
|
|
|
|
}
|
|
|
|
|
}
|
feat: v0.3.0d — add PR checks, iostreams, aliases, and broad enhancements
Add PR checks command, iostreams/text packages for colored table output,
top-level run/workflow aliases matching gh CLI structure. Enhance actions,
issues, PRs, releases, repos, labels, milestones, and wiki commands with
improved flags, JSON output, and error handling.
2026-03-23 11:42:44 -06:00
|
|
|
fmt.Fprintf(ios.Out, "Cloning into %s...\n", repo.Name)
|
2026-03-10 15:40:22 +01:00
|
|
|
gitCmd := exec.Command("git", "clone", cloneURL, repo.Name)
|
feat: v0.3.0d — add PR checks, iostreams, aliases, and broad enhancements
Add PR checks command, iostreams/text packages for colored table output,
top-level run/workflow aliases matching gh CLI structure. Enhance actions,
issues, PRs, releases, repos, labels, milestones, and wiki commands with
improved flags, JSON output, and error handling.
2026-03-23 11:42:44 -06:00
|
|
|
gitCmd.Stdout = ios.Out
|
|
|
|
|
gitCmd.Stderr = ios.ErrOut
|
|
|
|
|
gitCmd.Stdin = ios.In
|
2026-03-10 15:40:22 +01:00
|
|
|
if err := gitCmd.Run(); err != nil {
|
|
|
|
|
return fmt.Errorf("failed to clone repository: %w", err)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// parseCreateName parses the name argument for repo creation.
|
|
|
|
|
// Returns org, repoName, and whether it targets an org.
|
|
|
|
|
// Input: "reponame" → ("", "reponame", false)
|
|
|
|
|
// Input: "org/reponame" → ("org", "reponame", true)
|
|
|
|
|
func parseCreateName(name string) (org, repoName string, isOrg bool, err error) {
|
|
|
|
|
parts := strings.SplitN(name, "/", 2)
|
|
|
|
|
if len(parts) == 2 {
|
|
|
|
|
if parts[0] == "" || parts[1] == "" {
|
|
|
|
|
return "", "", false, fmt.Errorf("invalid repository name %q: org and repo name must not be empty", name)
|
|
|
|
|
}
|
|
|
|
|
return parts[0], parts[1], true, nil
|
|
|
|
|
}
|
|
|
|
|
if name == "" {
|
|
|
|
|
return "", "", false, fmt.Errorf("repository name must not be empty")
|
|
|
|
|
}
|
|
|
|
|
return "", name, false, nil
|
|
|
|
|
}
|
2026-03-21 21:50:24 -06:00
|
|
|
|
|
|
|
|
func runRepoEdit(cmd *cobra.Command, args []string) error {
|
|
|
|
|
var repo string
|
|
|
|
|
if len(args) > 0 {
|
|
|
|
|
repo = args[0]
|
|
|
|
|
}
|
|
|
|
|
if r, _ := cmd.Flags().GetString("repo"); r != "" {
|
|
|
|
|
repo = r
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
owner, name, err := parseRepo(repo)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
cfg, err := config.Load()
|
|
|
|
|
if err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-23 12:39:51 -06:00
|
|
|
client, err := api.NewClientFromConfig(cfg, "", getDetectedHost(), getCwd())
|
2026-03-21 21:50:24 -06:00
|
|
|
if err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
opt := gitea.EditRepoOption{}
|
|
|
|
|
changed := false
|
|
|
|
|
|
feat: v0.3.0d — add PR checks, iostreams, aliases, and broad enhancements
Add PR checks command, iostreams/text packages for colored table output,
top-level run/workflow aliases matching gh CLI structure. Enhance actions,
issues, PRs, releases, repos, labels, milestones, and wiki commands with
improved flags, JSON output, and error handling.
2026-03-23 11:42:44 -06:00
|
|
|
if cmd.Flags().Changed("name") {
|
|
|
|
|
n, _ := cmd.Flags().GetString("name")
|
|
|
|
|
opt.Name = &n
|
|
|
|
|
changed = true
|
|
|
|
|
}
|
2026-03-21 21:50:24 -06:00
|
|
|
if cmd.Flags().Changed("description") {
|
|
|
|
|
d, _ := cmd.Flags().GetString("description")
|
|
|
|
|
opt.Description = &d
|
|
|
|
|
changed = true
|
|
|
|
|
}
|
|
|
|
|
if cmd.Flags().Changed("homepage") {
|
|
|
|
|
h, _ := cmd.Flags().GetString("homepage")
|
|
|
|
|
opt.Website = &h
|
|
|
|
|
changed = true
|
|
|
|
|
}
|
|
|
|
|
if cmd.Flags().Changed("default-branch") {
|
|
|
|
|
b, _ := cmd.Flags().GetString("default-branch")
|
|
|
|
|
opt.DefaultBranch = &b
|
|
|
|
|
changed = true
|
|
|
|
|
}
|
|
|
|
|
if cmd.Flags().Changed("private") {
|
|
|
|
|
p := true
|
|
|
|
|
opt.Private = &p
|
|
|
|
|
changed = true
|
|
|
|
|
}
|
|
|
|
|
if cmd.Flags().Changed("public") {
|
|
|
|
|
p := false
|
|
|
|
|
opt.Private = &p
|
|
|
|
|
changed = true
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if !changed {
|
feat: v0.3.0d — add PR checks, iostreams, aliases, and broad enhancements
Add PR checks command, iostreams/text packages for colored table output,
top-level run/workflow aliases matching gh CLI structure. Enhance actions,
issues, PRs, releases, repos, labels, milestones, and wiki commands with
improved flags, JSON output, and error handling.
2026-03-23 11:42:44 -06:00
|
|
|
return fmt.Errorf("no changes specified; use flags like --name, --public, --private, --description, --homepage, or --default-branch")
|
2026-03-21 21:50:24 -06:00
|
|
|
}
|
|
|
|
|
|
feat: v0.3.0d — add PR checks, iostreams, aliases, and broad enhancements
Add PR checks command, iostreams/text packages for colored table output,
top-level run/workflow aliases matching gh CLI structure. Enhance actions,
issues, PRs, releases, repos, labels, milestones, and wiki commands with
improved flags, JSON output, and error handling.
2026-03-23 11:42:44 -06:00
|
|
|
ios.StartSpinner("Updating repository...")
|
2026-03-21 21:50:24 -06:00
|
|
|
repository, _, err := client.EditRepo(owner, name, opt)
|
feat: v0.3.0d — add PR checks, iostreams, aliases, and broad enhancements
Add PR checks command, iostreams/text packages for colored table output,
top-level run/workflow aliases matching gh CLI structure. Enhance actions,
issues, PRs, releases, repos, labels, milestones, and wiki commands with
improved flags, JSON output, and error handling.
2026-03-23 11:42:44 -06:00
|
|
|
ios.StopSpinner()
|
2026-03-21 21:50:24 -06:00
|
|
|
if err != nil {
|
|
|
|
|
return fmt.Errorf("failed to edit repository: %w", err)
|
|
|
|
|
}
|
|
|
|
|
|
feat: v0.3.0d — add PR checks, iostreams, aliases, and broad enhancements
Add PR checks command, iostreams/text packages for colored table output,
top-level run/workflow aliases matching gh CLI structure. Enhance actions,
issues, PRs, releases, repos, labels, milestones, and wiki commands with
improved flags, JSON output, and error handling.
2026-03-23 11:42:44 -06:00
|
|
|
if wantJSON(cmd) {
|
|
|
|
|
return outputJSON(cmd, repository)
|
2026-03-21 21:50:24 -06:00
|
|
|
}
|
|
|
|
|
|
feat: v0.3.0d — add PR checks, iostreams, aliases, and broad enhancements
Add PR checks command, iostreams/text packages for colored table output,
top-level run/workflow aliases matching gh CLI structure. Enhance actions,
issues, PRs, releases, repos, labels, milestones, and wiki commands with
improved flags, JSON output, and error handling.
2026-03-23 11:42:44 -06:00
|
|
|
cs := ios.ColorScheme()
|
|
|
|
|
fmt.Fprintf(ios.Out, "%s Repository updated: %s\n", cs.SuccessIcon(), repository.HTMLURL)
|
|
|
|
|
if opt.Name != nil {
|
|
|
|
|
fmt.Fprintf(ios.Out, "Renamed to: %s\n", repository.FullName)
|
|
|
|
|
}
|
2026-03-21 21:50:24 -06:00
|
|
|
if opt.Private != nil {
|
|
|
|
|
if *opt.Private {
|
feat: v0.3.0d — add PR checks, iostreams, aliases, and broad enhancements
Add PR checks command, iostreams/text packages for colored table output,
top-level run/workflow aliases matching gh CLI structure. Enhance actions,
issues, PRs, releases, repos, labels, milestones, and wiki commands with
improved flags, JSON output, and error handling.
2026-03-23 11:42:44 -06:00
|
|
|
fmt.Fprintln(ios.Out, "Visibility: private")
|
2026-03-21 21:50:24 -06:00
|
|
|
} else {
|
feat: v0.3.0d — add PR checks, iostreams, aliases, and broad enhancements
Add PR checks command, iostreams/text packages for colored table output,
top-level run/workflow aliases matching gh CLI structure. Enhance actions,
issues, PRs, releases, repos, labels, milestones, and wiki commands with
improved flags, JSON output, and error handling.
2026-03-23 11:42:44 -06:00
|
|
|
fmt.Fprintln(ios.Out, "Visibility: public")
|
2026-03-21 21:50:24 -06:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if opt.Description != nil {
|
feat: v0.3.0d — add PR checks, iostreams, aliases, and broad enhancements
Add PR checks command, iostreams/text packages for colored table output,
top-level run/workflow aliases matching gh CLI structure. Enhance actions,
issues, PRs, releases, repos, labels, milestones, and wiki commands with
improved flags, JSON output, and error handling.
2026-03-23 11:42:44 -06:00
|
|
|
fmt.Fprintf(ios.Out, "Description: %s\n", *opt.Description)
|
2026-03-21 21:50:24 -06:00
|
|
|
}
|
|
|
|
|
if opt.Website != nil {
|
feat: v0.3.0d — add PR checks, iostreams, aliases, and broad enhancements
Add PR checks command, iostreams/text packages for colored table output,
top-level run/workflow aliases matching gh CLI structure. Enhance actions,
issues, PRs, releases, repos, labels, milestones, and wiki commands with
improved flags, JSON output, and error handling.
2026-03-23 11:42:44 -06:00
|
|
|
fmt.Fprintf(ios.Out, "Homepage: %s\n", *opt.Website)
|
2026-03-21 21:50:24 -06:00
|
|
|
}
|
|
|
|
|
if opt.DefaultBranch != nil {
|
feat: v0.3.0d — add PR checks, iostreams, aliases, and broad enhancements
Add PR checks command, iostreams/text packages for colored table output,
top-level run/workflow aliases matching gh CLI structure. Enhance actions,
issues, PRs, releases, repos, labels, milestones, and wiki commands with
improved flags, JSON output, and error handling.
2026-03-23 11:42:44 -06:00
|
|
|
fmt.Fprintf(ios.Out, "Default branch: %s\n", *opt.DefaultBranch)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func runRepoRename(cmd *cobra.Command, args []string) error {
|
|
|
|
|
var repo string
|
|
|
|
|
if r, _ := cmd.Flags().GetString("repo"); r != "" {
|
|
|
|
|
repo = r
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
owner, name, err := parseRepo(repo)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
newName := args[0]
|
|
|
|
|
|
|
|
|
|
cfg, err := config.Load()
|
|
|
|
|
if err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-23 12:39:51 -06:00
|
|
|
client, err := api.NewClientFromConfig(cfg, "", getDetectedHost(), getCwd())
|
feat: v0.3.0d — add PR checks, iostreams, aliases, and broad enhancements
Add PR checks command, iostreams/text packages for colored table output,
top-level run/workflow aliases matching gh CLI structure. Enhance actions,
issues, PRs, releases, repos, labels, milestones, and wiki commands with
improved flags, JSON output, and error handling.
2026-03-23 11:42:44 -06:00
|
|
|
if err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
opt := gitea.EditRepoOption{
|
|
|
|
|
Name: &newName,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ios.StartSpinner("Renaming repository...")
|
|
|
|
|
repository, _, err := client.EditRepo(owner, name, opt)
|
|
|
|
|
ios.StopSpinner()
|
|
|
|
|
if err != nil {
|
|
|
|
|
return fmt.Errorf("failed to rename repository: %w", err)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if wantJSON(cmd) {
|
|
|
|
|
return outputJSON(cmd, repository)
|
2026-03-21 21:50:24 -06:00
|
|
|
}
|
|
|
|
|
|
feat: v0.3.0d — add PR checks, iostreams, aliases, and broad enhancements
Add PR checks command, iostreams/text packages for colored table output,
top-level run/workflow aliases matching gh CLI structure. Enhance actions,
issues, PRs, releases, repos, labels, milestones, and wiki commands with
improved flags, JSON output, and error handling.
2026-03-23 11:42:44 -06:00
|
|
|
cs := ios.ColorScheme()
|
|
|
|
|
fmt.Fprintf(ios.Out, "%s Renamed %s/%s to %s\n", cs.SuccessIcon(), owner, name, repository.FullName)
|
2026-03-21 21:50:24 -06:00
|
|
|
return nil
|
|
|
|
|
}
|