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

Method LoadNotifications

pkg/cmd/status/status.go:261–379  ·  view source on GitHub ↗

These are split up by endpoint since it is along that boundary we parallelize work Populate .Mentions

()

Source from the content-addressed store, hash-verified

259
260// Populate .Mentions
261func (s *StatusGetter) LoadNotifications() error {
262 perPage := 100
263 c := api.NewClientFromHTTP(s.Client)
264
265 fetchWorkers := 10
266 ctx, abortFetching := context.WithCancel(context.Background())
267 defer abortFetching()
268 toFetch := make(chan Notification)
269 fetched := make(chan StatusItem)
270
271 wg := new(errgroup.Group)
272 for range fetchWorkers {
273 wg.Go(func() error {
274 for {
275 select {
276 case <-ctx.Done():
277 return nil
278 case n, ok := <-toFetch:
279 if !ok {
280 return nil
281 }
282 actual, err := s.ActualMention(safeurl.NewImmutableSafeURL(n.Subject.LatestCommentURL))
283
284 if err != nil {
285 var httpErr api.HTTPError
286 httpStatusCode := -1
287
288 if errors.As(err, &httpErr) {
289 httpStatusCode = httpErr.StatusCode
290 }
291
292 switch httpStatusCode {
293 case 403:
294 s.addAuthError(httpErr.Message, factory.SSOURL())
295 case 404:
296 return nil
297 default:
298 abortFetching()
299 return fmt.Errorf("could not fetch comment: %w", err)
300 }
301 }
302
303 if actual != "" {
304 // I'm so sorry
305 split := strings.Split(n.Subject.URL, "/")
306 fetched <- StatusItem{
307 Repository: n.Repository.FullName,
308 Identifier: fmt.Sprintf("%s#%s", n.Repository.FullName, split[len(split)-1]),
309 preview: actual,
310 index: n.index,
311 }
312 }
313 }
314 }
315 })
316 }
317
318 doneCh := make(chan struct{})

Callers 1

statusRunFunction · 0.95

Calls 13

ActualMentionMethod · 0.95
addAuthErrorMethod · 0.95
hostnameMethod · 0.95
StringMethod · 0.95
ShouldExcludeMethod · 0.95
NewImmutableSafeURLFunction · 0.92
SSOURLFunction · 0.92
JoinPathFunction · 0.92
SetQueryMethod · 0.80
DoneMethod · 0.65
ErrorfMethod · 0.65
RESTWithNextMethod · 0.65

Tested by

no test coverage detected