MCPcopy
hub / github.com/cli/cli / unarchiveRun

Function unarchiveRun

pkg/cmd/repo/unarchive/unarchive.go:67–137  ·  view source on GitHub ↗
(opts *UnarchiveOptions)

Source from the content-addressed store, hash-verified

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

Callers 2

Test_UnarchiveRunFunction · 0.85
NewCmdUnarchiveFunction · 0.85

Calls 15

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

Tested by 1

Test_UnarchiveRunFunction · 0.68