(f *cmdutil.Factory, runF func(*PinOptions) error)
| 24 | } |
| 25 | |
| 26 | func NewCmdPin(f *cmdutil.Factory, runF func(*PinOptions) error) *cobra.Command { |
| 27 | opts := &PinOptions{ |
| 28 | IO: f.IOStreams, |
| 29 | HttpClient: f.HttpClient, |
| 30 | Config: f.Config, |
| 31 | BaseRepo: f.BaseRepo, |
| 32 | } |
| 33 | |
| 34 | cmd := &cobra.Command{ |
| 35 | Use: "pin {<number> | <url>}", |
| 36 | Short: "Pin an issue", |
| 37 | Long: heredoc.Doc(` |
| 38 | Pin an issue to a repository. |
| 39 | |
| 40 | The issue can be specified by issue number or URL. |
| 41 | `), |
| 42 | Example: heredoc.Doc(` |
| 43 | # Pin an issue to the current repository |
| 44 | $ gh issue pin 23 |
| 45 | |
| 46 | # Pin an issue by URL |
| 47 | $ gh issue pin https://github.com/owner/repo/issues/23 |
| 48 | |
| 49 | # Pin an issue to specific repository |
| 50 | $ gh issue pin 23 --repo owner/repo |
| 51 | `), |
| 52 | Args: cobra.ExactArgs(1), |
| 53 | RunE: func(cmd *cobra.Command, args []string) error { |
| 54 | issueNumber, baseRepo, err := shared.ParseIssueFromArg(args[0]) |
| 55 | if err != nil { |
| 56 | return err |
| 57 | } |
| 58 | |
| 59 | // If the args provided the base repo then use that directly. |
| 60 | if baseRepo, present := baseRepo.Value(); present { |
| 61 | opts.BaseRepo = func() (ghrepo.Interface, error) { |
| 62 | return baseRepo, nil |
| 63 | } |
| 64 | } else { |
| 65 | // support `-R, --repo` override |
| 66 | opts.BaseRepo = f.BaseRepo |
| 67 | } |
| 68 | |
| 69 | opts.IssueNumber = issueNumber |
| 70 | |
| 71 | if runF != nil { |
| 72 | return runF(opts) |
| 73 | } |
| 74 | |
| 75 | return pinRun(opts) |
| 76 | }, |
| 77 | } |
| 78 | |
| 79 | return cmd |
| 80 | } |
| 81 | |
| 82 | func pinRun(opts *PinOptions) error { |
| 83 | cs := opts.IO.ColorScheme() |
nothing calls this directly
no test coverage detected