MCPcopy Create free account
hub / github.com/cli/cli / archiveRun

Function archiveRun

pkg/cmd/repo/archive/archive.go:68–141  ·  view source on GitHub ↗
(opts *ArchiveOptions)

Source from the content-addressed store, hash-verified

66}
67
68func archiveRun(opts *ArchiveOptions) error {
69 cs := opts.IO.ColorScheme()
70 httpClient, err := opts.HttpClient()
71 if err != nil {
72 return err
73 }
74 apiClient := api.NewClientFromHTTP(httpClient)
75
76 var toArchive ghrepo.Interface
77
78 if opts.RepoArg == "" {
79 toArchive, err = opts.BaseRepo()
80 if err != nil {
81 return err
82 }
83 } else {
84 repoSelector := opts.RepoArg
85 if !strings.Contains(repoSelector, "/") {
86 cfg, err := opts.Config()
87 if err != nil {
88 return err
89 }
90
91 hostname, _ := cfg.Authentication().DefaultHost()
92
93 currentUser, err := api.CurrentLoginName(apiClient, hostname)
94 if err != nil {
95 return err
96 }
97 repoSelector = currentUser + "/" + repoSelector
98 }
99
100 toArchive, err = ghrepo.FromFullName(repoSelector)
101 if err != nil {
102 return err
103 }
104 }
105
106 fields := []string{"name", "owner", "isArchived", "id"}
107 repo, err := api.FetchRepository(apiClient, toArchive, fields)
108 if err != nil {
109 return err
110 }
111
112 fullName := ghrepo.FullName(toArchive)
113 if repo.IsArchived {
114 fmt.Fprintf(opts.IO.ErrOut, "%s Repository %s is already archived\n", cs.WarningIcon(), fullName)
115 return nil
116 }
117
118 if !opts.Confirmed {
119 confirmed, err := opts.Prompter.Confirm(fmt.Sprintf("Archive %s?", fullName), false)
120 if err != nil {
121 return fmt.Errorf("failed to prompt: %w", err)
122 }
123 if !confirmed {
124 return cmdutil.CancelError
125 }

Callers 2

NewCmdArchiveFunction · 0.85
Test_ArchiveRunFunction · 0.85

Calls 15

NewClientFromHTTPFunction · 0.92
CurrentLoginNameFunction · 0.92
FromFullNameFunction · 0.92
FetchRepositoryFunction · 0.92
FullNameFunction · 0.92
archiveRepoFunction · 0.85
ColorSchemeMethod · 0.80
ContainsMethod · 0.80
WarningIconMethod · 0.80
IsStdoutTTYMethod · 0.80
SuccessIconMethod · 0.80
BaseRepoMethod · 0.65

Tested by 1

Test_ArchiveRunFunction · 0.68