(client *http.Client, destination ghrepo.Interface, opts *cloneOptions)
| 110 | } |
| 111 | |
| 112 | func cloneLabels(client *http.Client, destination ghrepo.Interface, opts *cloneOptions) (successCount uint32, totalCount int, err error) { |
| 113 | successCount = 0 |
| 114 | labels, totalCount, err := listLabels(client, opts.SourceRepo, listQueryOptions{Limit: -1}) |
| 115 | if err != nil { |
| 116 | return |
| 117 | } |
| 118 | |
| 119 | workers := 10 |
| 120 | toCreate := make(chan createOptions) |
| 121 | |
| 122 | wg, ctx := errgroup.WithContext(context.Background()) |
| 123 | for i := 0; i < workers; i++ { |
| 124 | wg.Go(func() error { |
| 125 | for { |
| 126 | select { |
| 127 | case <-ctx.Done(): |
| 128 | return nil |
| 129 | case l, ok := <-toCreate: |
| 130 | if !ok { |
| 131 | return nil |
| 132 | } |
| 133 | err := createLabel(client, destination, &l) |
| 134 | if err != nil { |
| 135 | if !errors.Is(err, errLabelAlreadyExists) { |
| 136 | return err |
| 137 | } |
| 138 | } else { |
| 139 | atomic.AddUint32(&successCount, 1) |
| 140 | } |
| 141 | } |
| 142 | } |
| 143 | }) |
| 144 | } |
| 145 | |
| 146 | for _, label := range labels { |
| 147 | createOpts := createOptions{ |
| 148 | Name: label.Name, |
| 149 | Description: label.Description, |
| 150 | Color: label.Color, |
| 151 | Force: opts.Force, |
| 152 | } |
| 153 | toCreate <- createOpts |
| 154 | } |
| 155 | |
| 156 | close(toCreate) |
| 157 | err = wg.Wait() |
| 158 | |
| 159 | return |
| 160 | } |
no test coverage detected