MCPcopy
hub / github.com/cli/cli / NewCmdPin

Function NewCmdPin

pkg/cmd/issue/pin/pin.go:26–80  ·  view source on GitHub ↗
(f *cmdutil.Factory, runF func(*PinOptions) error)

Source from the content-addressed store, hash-verified

24}
25
26func 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
82func pinRun(opts *PinOptions) error {
83 cs := opts.IO.ColorScheme()

Callers

nothing calls this directly

Calls 3

ParseIssueFromArgFunction · 0.92
pinRunFunction · 0.85
ValueMethod · 0.80

Tested by

no test coverage detected