MCPcopy
hub / github.com/cli/cli / checkRun

Function checkRun

pkg/cmd/ruleset/check/check.go:104–163  ·  view source on GitHub ↗
(opts *CheckOptions)

Source from the content-addressed store, hash-verified

102}
103
104func checkRun(opts *CheckOptions) error {
105 httpClient, err := opts.HttpClient()
106 if err != nil {
107 return err
108 }
109 client := api.NewClientFromHTTP(httpClient)
110
111 repoI, err := opts.BaseRepo()
112 if err != nil {
113 return fmt.Errorf("could not determine repo to use: %w", err)
114 }
115
116 git := opts.Git
117
118 if opts.Default {
119 repo, err := api.GitHubRepo(client, repoI)
120 if err != nil {
121 return fmt.Errorf("could not get repository information: %w", err)
122 }
123 opts.Branch = repo.DefaultBranchRef.Name
124 }
125
126 if opts.Branch == "" {
127 opts.Branch, err = git.CurrentBranch(context.Background())
128 if err != nil {
129 return fmt.Errorf("could not determine current branch: %w", err)
130 }
131 }
132
133 if opts.WebMode {
134 // the query string parameter may have % signs in it, so it must be carefully used with Printf functions
135 queryString := fmt.Sprintf("?ref=%s", url.QueryEscape("refs/heads/"+opts.Branch))
136 rawUrl := ghrepo.GenerateRepoURL(repoI, "rules")
137
138 if opts.IO.IsStdoutTTY() {
139 fmt.Fprintf(opts.IO.Out, "Opening %s in your browser.\n", text.DisplayURL(rawUrl))
140 }
141
142 return opts.Browser.Browse(rawUrl + queryString)
143 }
144
145 var rules []shared.RulesetRule
146
147 endpoint := fmt.Sprintf("repos/%s/%s/rules/branches/%s", repoI.RepoOwner(), repoI.RepoName(), url.PathEscape(opts.Branch))
148
149 if err = client.REST(repoI.RepoHost(), "GET", endpoint, nil, &rules); err != nil {
150 return fmt.Errorf("GET %s failed: %w", endpoint, err)
151 }
152
153 w := opts.IO.Out
154
155 fmt.Fprintf(w, "%d rules apply to branch %s in repo %s/%s\n", len(rules), opts.Branch, repoI.RepoOwner(), repoI.RepoName())
156
157 if len(rules) > 0 {
158 fmt.Fprint(w, "\n")
159 fmt.Fprint(w, shared.ParseRulesForDisplay(rules))
160 }
161

Callers 2

Test_checkRunFunction · 0.85
NewCmdCheckFunction · 0.85

Calls 14

NewClientFromHTTPFunction · 0.92
GitHubRepoFunction · 0.92
GenerateRepoURLFunction · 0.92
DisplayURLFunction · 0.92
ParseRulesForDisplayFunction · 0.92
IsStdoutTTYMethod · 0.80
BaseRepoMethod · 0.65
ErrorfMethod · 0.65
CurrentBranchMethod · 0.65
BrowseMethod · 0.65
RepoOwnerMethod · 0.65
RepoNameMethod · 0.65

Tested by 1

Test_checkRunFunction · 0.68