MCPcopy Create free account
hub / github.com/cli/cli / checkRun

Function checkRun

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

Source from the content-addressed store, hash-verified

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

Callers 2

Test_checkRunFunction · 0.85
NewCmdCheckFunction · 0.85

Calls 15

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

Tested by 1

Test_checkRunFunction · 0.68