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

Function viewRun

pkg/cmd/ruleset/view/view.go:110–258  ·  view source on GitHub ↗
(opts *ViewOptions)

Source from the content-addressed store, hash-verified

108}
109
110func viewRun(opts *ViewOptions) error {
111 httpClient, err := opts.HttpClient()
112 if err != nil {
113 return err
114 }
115
116 var repoI ghrepo.Interface
117
118 // only one of the repo or org context is necessary
119 if opts.Organization == "" {
120 var repoErr error
121 repoI, repoErr = opts.BaseRepo()
122 if repoErr != nil {
123 return repoErr
124 }
125 }
126
127 hostname, _ := ghauth.DefaultHost()
128 cs := opts.IO.ColorScheme()
129
130 if opts.InteractiveMode {
131 var rsList *shared.RulesetList
132 limit := 30
133 if opts.Organization != "" {
134 rsList, err = shared.ListOrgRulesets(httpClient, opts.Organization, limit, hostname, opts.IncludeParents)
135 } else {
136 rsList, err = shared.ListRepoRulesets(httpClient, repoI, limit, opts.IncludeParents)
137 }
138
139 if err != nil {
140 return err
141 }
142
143 if rsList.TotalCount == 0 {
144 return shared.NoRulesetsFoundError(opts.Organization, repoI, opts.IncludeParents)
145 }
146
147 rs, err := selectRulesetID(rsList, opts.Prompter, cs)
148 if err != nil {
149 return err
150 }
151
152 if rs != nil {
153 opts.ID = strconv.Itoa(rs.DatabaseId)
154
155 // can't get a ruleset lower in the chain than what was queried, so no need to handle repos here
156 if rs.Source.TypeName == "Organization" {
157 opts.Organization = rs.Source.Owner
158 }
159 }
160 }
161
162 var rs *shared.RulesetREST
163 if opts.Organization != "" {
164 rs, err = viewOrgRuleset(httpClient, opts.Organization, opts.ID, hostname)
165 } else {
166 rs, err = viewRepoRuleset(httpClient, repoI, opts.ID)
167 }

Callers 2

Test_viewRunFunction · 0.70
NewCmdViewFunction · 0.70

Calls 15

ListOrgRulesetsFunction · 0.92
ListRepoRulesetsFunction · 0.92
NoRulesetsFoundErrorFunction · 0.92
DisplayURLFunction · 0.92
ParseRulesForDisplayFunction · 0.92
selectRulesetIDFunction · 0.85
viewOrgRulesetFunction · 0.85
viewRepoRulesetFunction · 0.85
ColorSchemeMethod · 0.80
IsStdoutTTYMethod · 0.80
BoldMethod · 0.80
CyanMethod · 0.80

Tested by 1

Test_viewRunFunction · 0.56