MCPcopy
hub / github.com/cli/cli / viewRun

Function viewRun

pkg/cmd/repo/view/view.go:80–216  ·  view source on GitHub ↗
(opts *ViewOptions)

Source from the content-addressed store, hash-verified

78var defaultFields = []string{"name", "owner", "description"}
79
80func viewRun(opts *ViewOptions) error {
81 httpClient, err := opts.HttpClient()
82 if err != nil {
83 return err
84 }
85
86 var toView ghrepo.Interface
87 apiClient := api.NewClientFromHTTP(httpClient)
88 if opts.RepoArg == "" {
89 var err error
90 toView, err = opts.BaseRepo()
91 if err != nil {
92 return err
93 }
94 } else {
95 viewURL := opts.RepoArg
96 if !strings.Contains(viewURL, "/") {
97 cfg, err := opts.Config()
98 if err != nil {
99 return err
100 }
101 hostname, _ := cfg.Authentication().DefaultHost()
102 currentUser, err := api.CurrentLoginName(apiClient, hostname)
103 if err != nil {
104 return err
105 }
106 viewURL = currentUser + "/" + viewURL
107 }
108 toView, err = ghrepo.FromFullName(viewURL)
109 if err != nil {
110 return fmt.Errorf("argument error: %w", err)
111 }
112 }
113
114 var readme *RepoReadme
115 fields := defaultFields
116 if opts.Exporter != nil {
117 fields = opts.Exporter.Fields()
118 }
119
120 repo, err := api.FetchRepository(apiClient, toView, fields)
121 if err != nil {
122 return err
123 }
124
125 if !opts.Web && opts.Exporter == nil {
126 readme, err = RepositoryReadme(httpClient, toView, opts.Branch)
127 if err != nil && !errors.Is(err, NotFoundError) {
128 return err
129 }
130 }
131
132 openURL := generateBranchURL(toView, opts.Branch)
133 if opts.Web {
134 if opts.IO.IsStdoutTTY() {
135 fmt.Fprintf(opts.IO.ErrOut, "Opening %s in your browser.\n", text.DisplayURL(openURL))
136 }
137 return opts.Browser.Browse(openURL)

Callers 9

Test_RepoView_WebFunction · 0.70
Test_ViewRunFunction · 0.70
Test_ViewRun_NoReadmeFunction · 0.70
Test_viewRun_jsonFunction · 0.70
NewCmdViewFunction · 0.70

Calls 15

NewClientFromHTTPFunction · 0.92
CurrentLoginNameFunction · 0.92
FromFullNameFunction · 0.92
FetchRepositoryFunction · 0.92
DisplayURLFunction · 0.92
FullNameFunction · 0.92
RenderFunction · 0.92
WithThemeFunction · 0.92
WithWrapFunction · 0.92
WithBaseURLFunction · 0.92
RepositoryReadmeFunction · 0.85
generateBranchURLFunction · 0.85

Tested by 8

Test_RepoView_WebFunction · 0.56
Test_ViewRunFunction · 0.56
Test_ViewRun_NoReadmeFunction · 0.56
Test_viewRun_jsonFunction · 0.56