func post()

in pkg/vul/import.go [79:110]


func post(ctx context.Context, list types.NoteOccurrencesMap, opt *types.VulnerabilityOptions) error {
	if list == nil {
		return errors.New("expected non-nil result")
	}

	var wg sync.WaitGroup

	ctx, cancel := context.WithCancel(ctx)
	defer cancel()

	for noteID, nocc := range list {
		wg.Add(1)
		go func(noteID string, nocc types.NoteOccurrences) {
			defer wg.Done()

			select {
			case <-ctx.Done():
				return
			default:
			}

			if err := postNoteOccurrences(ctx, opt.Project, noteID, nocc); err != nil {
				log.Error().Err(err).Msg("error posting notes & occurrences")
				cancel()
			}
		}(noteID, nocc)
	}

	wg.Wait()

	return nil
}