MCPcopy
hub / github.com/cli/cli / lockRun

Function lockRun

pkg/cmd/issue/lock/lock.go:227–305  ·  view source on GitHub ↗

lockRun will lock or unlock a conversation.

(state string, opts *LockOptions)

Source from the content-addressed store, hash-verified

225
226// lockRun will lock or unlock a conversation.
227func lockRun(state string, opts *LockOptions) error {
228 cs := opts.IO.ColorScheme()
229
230 httpClient, err := opts.HttpClient()
231 if err != nil {
232 return err
233 }
234
235 baseRepo, err := opts.BaseRepo()
236 if err != nil {
237 return err
238 }
239
240 issuePr, err := issueShared.FindIssueOrPR(httpClient, baseRepo, opts.IssueNumber, fields())
241 if err != nil {
242 return err
243 }
244
245 parent := alias[opts.ParentCmd]
246 if parent.Typename != issuePr.Typename {
247 currentType := alias[parent.Typename]
248 correctType := alias[issuePr.Typename]
249
250 return fmt.Errorf("%s %s %s#%d not found, but found %s %s#%d. Use `gh %s %s %d` instead",
251 cs.FailureIconWithColor(cs.Red),
252 currentType.FullName, ghrepo.FullName(baseRepo), issuePr.Number,
253 strings.ToLower(correctType.FullName), ghrepo.FullName(baseRepo), issuePr.Number,
254 correctType.Name, strings.ToLower(state), issuePr.Number)
255 }
256
257 if opts.Interactive {
258 options := []string{"None", "Off topic", "Resolved", "Spam", "Too heated"}
259 selected, err := opts.Prompter.Select("Lock reason?", "", options)
260 if err != nil {
261 return err
262 }
263 if selected > 0 {
264 opts.Reason = reasons[selected-1]
265 }
266 }
267
268 successMsg := fmt.Sprintf("%s %s\n",
269 cs.SuccessIconWithColor(cs.Green), status(state, issuePr, baseRepo, opts))
270
271 switch state {
272 case Lock:
273 if !issuePr.Locked {
274 err = lockLockable(httpClient, baseRepo, issuePr, opts)
275 } else {
276 var relocked bool
277 relocked, err = relockLockable(httpClient, baseRepo, issuePr, opts)
278
279 if !relocked {
280 successMsg = fmt.Sprintf("%s %s#%d already locked%s. Nothing changed.\n",
281 parent.FullName, ghrepo.FullName(baseRepo), issuePr.Number, reason(issuePr.ActiveLockReason))
282 }
283 }
284

Callers 3

Test_runLockFunction · 0.85
NewCmdLockFunction · 0.85
NewCmdUnlockFunction · 0.85

Calls 14

FullNameFunction · 0.92
statusFunction · 0.85
lockLockableFunction · 0.85
relockLockableFunction · 0.85
reasonFunction · 0.85
unlockLockableFunction · 0.85
ColorSchemeMethod · 0.80
FailureIconWithColorMethod · 0.80
SuccessIconWithColorMethod · 0.80
IsStdoutTTYMethod · 0.80
fieldsFunction · 0.70
BaseRepoMethod · 0.65

Tested by 1

Test_runLockFunction · 0.68