lockRun will lock or unlock a conversation.
(state string, opts *LockOptions)
| 225 | |
| 226 | // lockRun will lock or unlock a conversation. |
| 227 | func 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 |