MCPcopy
hub / github.com/cli/cli / cloneLabels

Function cloneLabels

pkg/cmd/label/clone.go:112–160  ·  view source on GitHub ↗
(client *http.Client, destination ghrepo.Interface, opts *cloneOptions)

Source from the content-addressed store, hash-verified

110}
111
112func 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}

Callers 1

cloneRunFunction · 0.85

Calls 4

listLabelsFunction · 0.85
createLabelFunction · 0.85
DoneMethod · 0.65
WaitMethod · 0.65

Tested by

no test coverage detected