| 146 | } |
| 147 | |
| 148 | func checksRun(opts *ChecksOptions) error { |
| 149 | if opts.WebMode { |
| 150 | return checksRunWebMode(opts) |
| 151 | } |
| 152 | |
| 153 | findOptions := shared.FindOptions{ |
| 154 | Selector: opts.SelectorArg, |
| 155 | Fields: []string{"number", "headRefName"}, |
| 156 | } |
| 157 | |
| 158 | var pr *api.PullRequest |
| 159 | pr, repo, findErr := opts.Finder.Find(findOptions) |
| 160 | if findErr != nil { |
| 161 | return findErr |
| 162 | } |
| 163 | |
| 164 | client, clientErr := opts.HttpClient() |
| 165 | if clientErr != nil { |
| 166 | return clientErr |
| 167 | } |
| 168 | |
| 169 | var checks []check |
| 170 | var counts checkCounts |
| 171 | var err error |
| 172 | var includeEvent bool |
| 173 | |
| 174 | if opts.Detector == nil { |
| 175 | cachedClient := api.NewCachedHTTPClient(client, time.Hour*24) |
| 176 | opts.Detector = fd.NewDetector(cachedClient, repo.RepoHost()) |
| 177 | } |
| 178 | if features, featuresErr := opts.Detector.PullRequestFeatures(); featuresErr != nil { |
| 179 | return featuresErr |
| 180 | } else { |
| 181 | includeEvent = features.CheckRunEvent |
| 182 | } |
| 183 | |
| 184 | checks, counts, err = populateStatusChecks(client, repo, pr, opts.Required, includeEvent) |
| 185 | if err != nil { |
| 186 | return err |
| 187 | } |
| 188 | |
| 189 | if opts.Exporter != nil { |
| 190 | return opts.Exporter.Write(opts.IO, checks) |
| 191 | } |
| 192 | |
| 193 | if opts.Watch { |
| 194 | opts.IO.StartAlternateScreenBuffer() |
| 195 | } else { |
| 196 | // Only start pager in non-watch mode |
| 197 | if err := opts.IO.StartPager(); err == nil { |
| 198 | defer opts.IO.StopPager() |
| 199 | } else { |
| 200 | fmt.Fprintf(opts.IO.ErrOut, "failed to start pager: %v\n", err) |
| 201 | } |
| 202 | } |
| 203 | |
| 204 | // Do not return err until we can StopAlternateScreenBuffer() |
| 205 | for { |