Repository: cli/cli
File: pkg/cmd/pr/edit/edit.go (Go)

Code before:
}

func updatePullRequestReviews(httpClient *http.Client, repo ghrepo.Interface, number int, editable shared.Editable) error {
	if !editable.Reviewers.Edited {
		return nil
	}

	// Rebuild the Value slice from non-interactive flag input.
	if len(editable.Reviewers.Add) != 0 || len(editable.Reviewers.Remove) != 0 {
		s := set.NewStringSet()
		s.AddValues(editable.Reviewers.Add)
		s.AddValues(editable.Reviewers.Default)
		s.RemoveValues(editable.Reviewers.Remove)
		editable.Reviewers.Value = s.ToSlice()
	}

	var addUsers []string
	var addTeams []string
	for _, r := range editable.Reviewers.Value {
		if strings.ContainsRune(r, '/') {
			teamSlug := strings.Split(r, "/")[1]
			addTeams = append(addTeams, teamSlug)
		} else {
			addUsers = append(addUsers, r)
		}
	}

	// Reviewers in Default but not in the Value have been removed interactively.
	var toRemove []string
	for _, r := range editable.Reviewers.Default {
		if !slices.Contains(editable.Reviewers.Value, r) {
			toRemove = append(toRemove, r)
		}
	}
	var removeUsers []string
	var removeTeams []string
	for _, r := range toRemove {
		if strings.ContainsRune(r, '/') {
			teamSlug := strings.Split(r, "/")[1]
			removeTeams = append(removeTeams, teamSlug)
		} else {
			removeUsers = append(removeUsers, r)
		}
	}

	client := api.NewClientFromHTTP(httpClient)
	wg := errgroup.Group{}
	wg.Go(func() error {
		return api.AddPullRequestReviews(client, repo, number, addUsers, addTeams)
	})
	wg.Go(func() error {

Review comment (refactor):
**nitpick:** This piece can be extracted as a small helper function and be reused here twice:


```go
func partitionUsersAndTeams(values []string) (users []string, teams []string) {
	for _, r := range values {
		if strings.ContainsRune(r, '/') {
			teamSlug := strings.Split(r, "/")[1]
			teams = append(teams, teamSlug)
		} else {
			users = append(users, r)
		}
	}
    return users, teams
}
```



Code after:
		return nil
	}

	// Rebuild the Value slice from non-interactive flag input.
	if len(editable.Reviewers.Add) != 0 || len(editable.Reviewers.Remove) != 0 {
		s := set.NewStringSet()
		s.AddValues(editable.Reviewers.Add)
		s.AddValues(editable.Reviewers.Default)
		s.RemoveValues(editable.Reviewers.Remove)
		editable.Reviewers.Value = s.ToSlice()
	}

	addUsers, addTeams := partitionUsersAndTeams(editable.Reviewers.Value)

	// Reviewers in Default but not in the Value have been removed interactively.
	var toRemove []string
	for _, r := range editable.Reviewers.Default {
		if !slices.Contains(editable.Reviewers.Value, r) {
			toRemove = append(toRemove, r)
		}
	}
	removeUsers, removeTeams := partitionUsersAndTeams(toRemove)

	client := api.NewClientFromHTTP(httpClient)
	wg := errgroup.Group{}
	wg.Go(func() error {
		return api.AddPullRequestReviews(client, repo, number, addUsers, addTeams)
	})
	wg.Go(func() error {
		return api.RemovePullRequestReviews(client, repo, number, removeUsers, removeTeams)
	})
	return wg.Wait()
}

type Surveyor interface {
	FieldsToEdit(*shared.Editable) error
	EditFields(*shared.Editable, string) error
}

type surveyor struct {
	P shared.EditPrompter
}

func (s surveyor) FieldsToEdit(editable *shared.Editable) error {
	return shared.FieldsToEditSurvey(s.P, editable)
}

func (s surveyor) EditFields(editable *shared.Editable, editorCmd string) error {
	return shared.EditFieldsSurvey(s.P, editable, editorCmd)
}