MCPcopy
hub / github.com/cli/cli / runView

Function runView

pkg/cmd/workflow/view/view.go:99–157  ·  view source on GitHub ↗
(opts *ViewOptions)

Source from the content-addressed store, hash-verified

97}
98
99func runView(opts *ViewOptions) error {
100 c, err := opts.HttpClient()
101 if err != nil {
102 return fmt.Errorf("could not build http client: %w", err)
103 }
104 client := api.NewClientFromHTTP(c)
105
106 repo, err := opts.BaseRepo()
107 if err != nil {
108 return err
109 }
110
111 var workflow *shared.Workflow
112 states := []shared.WorkflowState{shared.Active}
113 workflow, err = shared.ResolveWorkflow(opts.Prompter, opts.IO, client, repo, opts.Prompt, opts.Selector, states)
114 if err != nil {
115 return err
116 }
117
118 if opts.Web {
119 var address string
120 if opts.YAML {
121 ref := opts.Ref
122 if ref == "" {
123 opts.IO.StartProgressIndicator()
124 ref, err = api.RepoDefaultBranch(client, repo)
125 opts.IO.StopProgressIndicator()
126 if err != nil {
127 return err
128 }
129 }
130 address = ghrepo.GenerateRepoURL(repo, "blob/%s/%s", url.QueryEscape(ref), url.QueryEscape(workflow.Path))
131 } else {
132 address = ghrepo.GenerateRepoURL(repo, "actions/workflows/%s", url.QueryEscape(workflow.Base()))
133 }
134 if opts.IO.IsStdoutTTY() {
135 fmt.Fprintf(opts.IO.Out, "Opening %s in your browser.\n", text.DisplayURL(address))
136 }
137 return opts.Browser.Browse(address)
138 }
139
140 opts.IO.DetectTerminalTheme()
141 if err := opts.IO.StartPager(); err == nil {
142 defer opts.IO.StopPager()
143 } else {
144 fmt.Fprintf(opts.IO.ErrOut, "failed to start pager: %v\n", err)
145 }
146
147 if opts.YAML {
148 err = viewWorkflowContent(opts, client, repo, workflow, opts.Ref)
149 } else {
150 err = viewWorkflowInfo(opts, client, repo, workflow)
151 }
152 if err != nil {
153 return err
154 }
155
156 return nil

Callers 2

TestViewRunFunction · 0.70
NewCmdViewFunction · 0.70

Calls 15

BaseMethod · 0.95
NewClientFromHTTPFunction · 0.92
ResolveWorkflowFunction · 0.92
RepoDefaultBranchFunction · 0.92
GenerateRepoURLFunction · 0.92
DisplayURLFunction · 0.92
viewWorkflowContentFunction · 0.85
viewWorkflowInfoFunction · 0.85
IsStdoutTTYMethod · 0.80
DetectTerminalThemeMethod · 0.80
StartPagerMethod · 0.80
StopPagerMethod · 0.80

Tested by 1

TestViewRunFunction · 0.56