MCPcopy
hub / github.com/cli/cli / NewCmdCommits

Function NewCmdCommits

pkg/cmd/search/commits/commits.go:28–123  ·  view source on GitHub ↗
(f *cmdutil.Factory, runF func(*CommitsOptions) error)

Source from the content-addressed store, hash-verified

26}
27
28func NewCmdCommits(f *cmdutil.Factory, runF func(*CommitsOptions) error) *cobra.Command {
29 var order string
30 var sort string
31 opts := &CommitsOptions{
32 Browser: f.Browser,
33 IO: f.IOStreams,
34 Query: search.Query{Kind: search.KindCommits},
35 }
36
37 cmd := &cobra.Command{
38 Use: "commits [<query>]",
39 Short: "Search for commits",
40 Long: heredoc.Docf(`
41 Search for commits on GitHub.
42
43 The command supports constructing queries using the GitHub search syntax,
44 using the parameter and qualifier flags, or a combination of the two.
45
46 GitHub search syntax is documented at:
47 <https://docs.github.com/search-github/searching-on-github/searching-commits>
48
49 For more information on handling search queries containing a hyphen, run %[1]sgh search --help%[1]s.
50 `, "`"),
51 Example: heredoc.Doc(`
52 # Search commits matching set of keywords "readme" and "typo"
53 $ gh search commits readme typo
54
55 # Search commits matching phrase "bug fix"
56 $ gh search commits "bug fix"
57
58 # Search commits committed by user "monalisa"
59 $ gh search commits --committer=monalisa
60
61 # Search commits authored by users with name "Jane Doe"
62 $ gh search commits --author-name="Jane Doe"
63
64 # Search commits matching hash "8dd03144ffdc6c0d486d6b705f9c7fba871ee7c3"
65 $ gh search commits --hash=8dd03144ffdc6c0d486d6b705f9c7fba871ee7c3
66
67 # Search commits authored before February 1st, 2022
68 $ gh search commits --author-date="<2022-02-01"
69 `),
70 RunE: func(c *cobra.Command, args []string) error {
71 if len(args) == 0 && c.Flags().NFlag() == 0 {
72 return cmdutil.FlagErrorf("specify search keywords or flags")
73 }
74 if opts.Query.Limit < 1 || opts.Query.Limit > shared.SearchMaxResults {
75 return cmdutil.FlagErrorf("`--limit` must be between 1 and 1000")
76 }
77 if c.Flags().Changed("order") {
78 opts.Query.Order = order
79 }
80 if c.Flags().Changed("sort") {
81 opts.Query.Sort = sort
82 }
83 opts.Query.Keywords = args
84 if runF != nil {
85 return runF(opts)

Callers 1

TestNewCmdCommitsFunction · 0.85

Calls 7

FlagErrorfFunction · 0.92
SearcherFunction · 0.92
AddJSONFlagsFunction · 0.92
StringEnumFlagFunction · 0.92
NilBoolFlagFunction · 0.92
StringSliceEnumFlagFunction · 0.92
commitsRunFunction · 0.85

Tested by 1

TestNewCmdCommitsFunction · 0.68