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

Method LoadNotifications

pkg/cmd/status/status.go:265–383  ·  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

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