cli/pkg/cmd/pr/shared/state.go
Kynan Ware 3c00ffdade refactor(pr shared): consolidate ActorAssignees and ActorReviewers into ApiActorsSupported
The CLI had two per-entity flags (ActorAssignees on EditableAssignees and
IssueMetadataState, ActorReviewers on IssueMetadataState) threaded through
different layers of the stack to distinguish github.com from GHES. Both
flags were always set from the same source (issueFeatures.ActorIsAssignable)
and never had different values, but they were carried independently on
different structs. This led to a confusing asymmetry where:

- EditableAssignees had ActorAssignees but EditableReviewers had nothing
- The PR edit flow piggybacked on editable.Assignees.ActorAssignees to
  make reviewer mutation decisions, which was misleading
- RepoMetadataInput only had ActorAssignees with no reviewer equivalent

This commit replaces all per-entity flags with a single ApiActorsSupported
bool hoisted to the shared level on Editable, IssueMetadataState, and
RepoMetadataInput. Both assignees and reviewers now key off the same signal.

Every branch site is marked with // TODO ApiActorsSupported so we can grep
for cleanup sites when GHES eventually supports the actor-based mutations
(replaceActorsForAssignable, requestReviewsByLogin).

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-03-24 21:04:41 -06:00

77 lines
1.6 KiB
Go

package shared
import (
"encoding/json"
"fmt"
"github.com/cli/cli/v2/api"
"github.com/cli/cli/v2/pkg/iostreams"
)
type metadataStateType int
const (
IssueMetadata metadataStateType = iota
PRMetadata
)
type IssueMetadataState struct {
Type metadataStateType
Draft bool
// TODO ApiActorsSupported
// ApiActorsSupported indicates the host supports actor-based APIs (github.com, ghe.com).
// When true, mutations use logins directly instead of resolving node IDs.
// Remove this flag (and collapse to actor-only paths) once GHES supports
// replaceActorsForAssignable and requestReviewsByLogin mutations.
ApiActorsSupported bool
Body string
Title string
Template string
Metadata []string
Reviewers []string
Assignees []string
Labels []string
ProjectTitles []string
Milestones []string
MetadataResult *api.RepoMetadataResult
dirty bool // whether user i/o has modified this
}
func (tb *IssueMetadataState) MarkDirty() {
tb.dirty = true
}
func (tb *IssueMetadataState) IsDirty() bool {
return tb.dirty || tb.HasMetadata()
}
func (tb *IssueMetadataState) HasMetadata() bool {
return len(tb.Reviewers) > 0 ||
len(tb.Assignees) > 0 ||
len(tb.Labels) > 0 ||
len(tb.ProjectTitles) > 0 ||
len(tb.Milestones) > 0
}
func FillFromJSON(io *iostreams.IOStreams, recoverFile string, state *IssueMetadataState) error {
var data []byte
var err error
data, err = io.ReadUserFile(recoverFile)
if err != nil {
return fmt.Errorf("failed to read file %s: %w", recoverFile, err)
}
err = json.Unmarshal(data, state)
if err != nil {
return fmt.Errorf("JSON parsing failure: %w", err)
}
return nil
}