@@ -22,14 +22,14 @@ type EditOptions struct {
2222 BaseRepo func () (ghrepo.Interface , error )
2323
2424 DetermineEditor func () (string , error )
25- FieldsToEditSurvey func (* prShared.EditableOptions ) error
26- EditableSurvey func (string , * prShared.EditableOptions ) error
27- FetchOptions func (* api.Client , ghrepo.Interface , * prShared.EditableOptions ) error
25+ FieldsToEditSurvey func (* prShared.Editable ) error
26+ EditFieldsSurvey func (* prShared.Editable , string ) error
27+ FetchOptions func (* api.Client , ghrepo.Interface , * prShared.Editable ) error
2828
2929 SelectorArg string
3030 Interactive bool
3131
32- prShared.EditableOptions
32+ prShared.Editable
3333}
3434
3535func NewCmdEdit (f * cmdutil.Factory , runF func (* EditOptions ) error ) * cobra.Command {
@@ -38,7 +38,7 @@ func NewCmdEdit(f *cmdutil.Factory, runF func(*EditOptions) error) *cobra.Comman
3838 HttpClient : f .HttpClient ,
3939 DetermineEditor : func () (string , error ) { return cmdutil .DetermineEditor (f .Config ) },
4040 FieldsToEditSurvey : prShared .FieldsToEditSurvey ,
41- EditableSurvey : prShared .EditableSurvey ,
41+ EditFieldsSurvey : prShared .EditFieldsSurvey ,
4242 FetchOptions : prShared .FetchOptions ,
4343 }
4444
@@ -62,25 +62,25 @@ func NewCmdEdit(f *cmdutil.Factory, runF func(*EditOptions) error) *cobra.Comman
6262
6363 flags := cmd .Flags ()
6464 if flags .Changed ("title" ) {
65- opts .EditableOptions .TitleEdited = true
65+ opts .Editable .TitleEdited = true
6666 }
6767 if flags .Changed ("body" ) {
68- opts .EditableOptions .BodyEdited = true
68+ opts .Editable .BodyEdited = true
6969 }
7070 if flags .Changed ("assignee" ) {
71- opts .EditableOptions .AssigneesEdited = true
71+ opts .Editable .AssigneesEdited = true
7272 }
7373 if flags .Changed ("label" ) {
74- opts .EditableOptions .LabelsEdited = true
74+ opts .Editable .LabelsEdited = true
7575 }
7676 if flags .Changed ("project" ) {
77- opts .EditableOptions .ProjectsEdited = true
77+ opts .Editable .ProjectsEdited = true
7878 }
7979 if flags .Changed ("milestone" ) {
80- opts .EditableOptions .MilestoneEdited = true
80+ opts .Editable .MilestoneEdited = true
8181 }
8282
83- if ! opts .EditableOptions .Dirty () {
83+ if ! opts .Editable .Dirty () {
8484 opts .Interactive = true
8585 }
8686
@@ -96,12 +96,12 @@ func NewCmdEdit(f *cmdutil.Factory, runF func(*EditOptions) error) *cobra.Comman
9696 },
9797 }
9898
99- cmd .Flags ().StringVarP (& opts .EditableOptions .Title , "title" , "t" , "" , "Revise the issue title." )
100- cmd .Flags ().StringVarP (& opts .EditableOptions .Body , "body" , "b" , "" , "Revise the issue body." )
101- cmd .Flags ().StringSliceVarP (& opts .EditableOptions .Assignees , "assignee" , "a" , nil , "Set assigned people by their `login`. Use \" @me\" to self-assign." )
102- cmd .Flags ().StringSliceVarP (& opts .EditableOptions .Labels , "label" , "l" , nil , "Set the issue labels by `name`" )
103- cmd .Flags ().StringSliceVarP (& opts .EditableOptions .Projects , "project" , "p" , nil , "Set the projects the issue belongs to by `name`" )
104- cmd .Flags ().StringVarP (& opts .EditableOptions .Milestone , "milestone" , "m" , "" , "Set the milestone the issue belongs to by `name`" )
99+ cmd .Flags ().StringVarP (& opts .Editable .Title , "title" , "t" , "" , "Revise the issue title." )
100+ cmd .Flags ().StringVarP (& opts .Editable .Body , "body" , "b" , "" , "Revise the issue body." )
101+ cmd .Flags ().StringSliceVarP (& opts .Editable .Assignees , "assignee" , "a" , nil , "Set assigned people by their `login`. Use \" @me\" to self-assign." )
102+ cmd .Flags ().StringSliceVarP (& opts .Editable .Labels , "label" , "l" , nil , "Set the issue labels by `name`" )
103+ cmd .Flags ().StringSliceVarP (& opts .Editable .Projects , "project" , "p" , nil , "Set the projects the issue belongs to by `name`" )
104+ cmd .Flags ().StringVarP (& opts .Editable .Milestone , "milestone" , "m" , "" , "Set the milestone the issue belongs to by `name`" )
105105
106106 return cmd
107107}
@@ -118,23 +118,23 @@ func editRun(opts *EditOptions) error {
118118 return err
119119 }
120120
121- editOptions := opts .EditableOptions
122- editOptions .TitleDefault = issue .Title
123- editOptions .BodyDefault = issue .Body
124- editOptions .AssigneesDefault = issue .Assignees
125- editOptions .LabelsDefault = issue .Labels
126- editOptions .ProjectsDefault = issue .ProjectCards
127- editOptions .MilestoneDefault = issue .Milestone
121+ editable := opts .Editable
122+ editable .TitleDefault = issue .Title
123+ editable .BodyDefault = issue .Body
124+ editable .AssigneesDefault = issue .Assignees
125+ editable .LabelsDefault = issue .Labels
126+ editable .ProjectsDefault = issue .ProjectCards
127+ editable .MilestoneDefault = issue .Milestone
128128
129129 if opts .Interactive {
130- err = opts .FieldsToEditSurvey (& editOptions )
130+ err = opts .FieldsToEditSurvey (& editable )
131131 if err != nil {
132132 return err
133133 }
134134 }
135135
136136 opts .IO .StartProgressIndicator ()
137- err = opts .FetchOptions (apiClient , repo , & editOptions )
137+ err = opts .FetchOptions (apiClient , repo , & editable )
138138 opts .IO .StopProgressIndicator ()
139139 if err != nil {
140140 return err
@@ -145,14 +145,14 @@ func editRun(opts *EditOptions) error {
145145 if err != nil {
146146 return err
147147 }
148- err = opts .EditableSurvey ( editorCommand , & editOptions )
148+ err = opts .EditFieldsSurvey ( & editable , editorCommand )
149149 if err != nil {
150150 return err
151151 }
152152 }
153153
154154 opts .IO .StartProgressIndicator ()
155- err = updateIssue (apiClient , repo , issue .ID , editOptions )
155+ err = updateIssue (apiClient , repo , issue .ID , editable )
156156 opts .IO .StopProgressIndicator ()
157157 if err != nil {
158158 return err
@@ -163,61 +163,28 @@ func editRun(opts *EditOptions) error {
163163 return nil
164164}
165165
166- func updateIssue (client * api.Client , repo ghrepo.Interface , id string , options prShared.EditableOptions ) error {
167- params := githubv4.UpdateIssueInput {ID : id }
168- if options .TitleEdited {
169- title := githubv4 .String (options .Title )
170- params .Title = & title
166+ func updateIssue (client * api.Client , repo ghrepo.Interface , id string , options prShared.Editable ) error {
167+ var err error
168+ params := githubv4.UpdateIssueInput {
169+ ID : id ,
170+ Title : options .TitleParam (),
171+ Body : options .BodyParam (),
171172 }
172- if options .BodyEdited {
173- body := githubv4 .String (options .Body )
174- params .Body = & body
175- }
176- if options .AssigneesEdited {
177- meReplacer := prShared .NewMeReplacer (client , repo .RepoHost ())
178- assignees , err := meReplacer .ReplaceSlice (options .Assignees )
179- if err != nil {
180- return err
181- }
182- ids , err := options .Metadata .MembersToIDs (assignees )
183- if err != nil {
184- return err
185- }
186- assigneeIDs := make ([]githubv4.ID , len (ids ))
187- for i , v := range ids {
188- assigneeIDs [i ] = v
189- }
190- params .AssigneeIDs = & assigneeIDs
173+ params .AssigneeIDs , err = options .AssigneesParam (client , repo )
174+ if err != nil {
175+ return err
191176 }
192- if options .LabelsEdited {
193- ids , err := options .Metadata .LabelsToIDs (options .Labels )
194- if err != nil {
195- return err
196- }
197- labelIDs := make ([]githubv4.ID , len (ids ))
198- for i , v := range ids {
199- labelIDs [i ] = v
200- }
201- params .LabelIDs = & labelIDs
177+ params .LabelIDs , err = options .LabelsParam ()
178+ if err != nil {
179+ return err
202180 }
203- if options .ProjectsEdited {
204- ids , err := options .Metadata .ProjectsToIDs (options .Projects )
205- if err != nil {
206- return err
207- }
208- projectIDs := make ([]githubv4.ID , len (ids ))
209- for i , v := range ids {
210- projectIDs [i ] = v
211- }
212- params .ProjectIDs = & projectIDs
181+ params .ProjectIDs , err = options .ProjectsParam ()
182+ if err != nil {
183+ return err
213184 }
214- if options .MilestoneEdited {
215- id , err := options .Metadata .MilestoneToID (options .Milestone )
216- if err != nil {
217- return err
218- }
219- milestoneID := githubv4 .ID (id )
220- params .MilestoneID = & milestoneID
185+ params .MilestoneID , err = options .MilestoneParam ()
186+ if err != nil {
187+ return err
221188 }
222189 return api .IssueUpdate (client , repo , params )
223190}
0 commit comments