| 62 | } |
| 63 | |
| 64 | func NewCmdApi(f *cmdutil.Factory, runF func(*ApiOptions) error) *cobra.Command { |
| 65 | opts := ApiOptions{ |
| 66 | AppVersion: f.AppVersion, |
| 67 | InvokingAgent: f.InvokingAgent, |
| 68 | BaseRepo: f.BaseRepo, |
| 69 | Branch: f.Branch, |
| 70 | Config: f.Config, |
| 71 | IO: f.IOStreams, |
| 72 | } |
| 73 | |
| 74 | cmd := &cobra.Command{ |
| 75 | Use: "api <endpoint>", |
| 76 | Short: "Make an authenticated GitHub API request", |
| 77 | Long: heredoc.Docf(` |
| 78 | Makes an authenticated HTTP request to the GitHub API and prints the response. |
| 79 | |
| 80 | The endpoint argument should either be a path of a GitHub API v3 endpoint, or |
| 81 | %[1]sgraphql%[1]s to access the GitHub API v4. |
| 82 | |
| 83 | Placeholder values %[1]s{owner}%[1]s, %[1]s{repo}%[1]s, and %[1]s{branch}%[1]s in the endpoint |
| 84 | argument will get replaced with values from the repository of the current |
| 85 | directory or the repository specified in the %[1]sGH_REPO%[1]s environment variable. |
| 86 | Note that in some shells, for example PowerShell, you may need to enclose |
| 87 | any value that contains %[1]s{...}%[1]s in quotes to prevent the shell from |
| 88 | applying special meaning to curly braces. |
| 89 | |
| 90 | The %[1]s-p/--preview%[1]s flag enables opting into previews, which are feature-flagged, |
| 91 | experimental API endpoints or behaviors. The API expects opt-in via the %[1]sAccept%[1]s |
| 92 | header with format %[1]sapplication/vnd.github.<preview-name>-preview+json%[1]s and this |
| 93 | command facilitates that via %[1]s--preview <preview-name>%[1]s. To send a request for |
| 94 | the corsair and scarlet witch previews, you could use %[1]s-p corsair,scarlet-witch%[1]s |
| 95 | or %[1]s--preview corsair --preview scarlet-witch%[1]s. |
| 96 | |
| 97 | The default HTTP request method is %[1]sGET%[1]s normally and %[1]sPOST%[1]s if any parameters |
| 98 | were added. Override the method with %[1]s--method%[1]s. |
| 99 | |
| 100 | Pass one or more %[1]s-f/--raw-field%[1]s values in %[1]skey=value%[1]s format to add static string |
| 101 | parameters to the request payload. To add non-string or placeholder-determined values, see |
| 102 | %[1]s-F/--field%[1]s below. Note that adding request parameters will automatically switch the |
| 103 | request method to %[1]sPOST%[1]s. To send the parameters as a %[1]sGET%[1]s query string instead, use |
| 104 | %[1]s--method GET%[1]s. |
| 105 | |
| 106 | The %[1]s-F/--field%[1]s flag has magic type conversion based on the format of the value: |
| 107 | |
| 108 | - literal values %[1]strue%[1]s, %[1]sfalse%[1]s, %[1]snull%[1]s, and integer numbers get converted to |
| 109 | appropriate JSON types; |
| 110 | - placeholder values %[1]s{owner}%[1]s, %[1]s{repo}%[1]s, and %[1]s{branch}%[1]s get populated with values |
| 111 | from the repository of the current directory; |
| 112 | - if the value starts with %[1]s@%[1]s, the rest of the value is interpreted as a |
| 113 | filename to read the value from. Pass %[1]s-%[1]s to read from standard input. |
| 114 | |
| 115 | For GraphQL requests, all fields other than %[1]squery%[1]s and %[1]soperationName%[1]s are |
| 116 | interpreted as GraphQL variables. |
| 117 | |
| 118 | To pass nested parameters in the request payload, use %[1]skey[subkey]=value%[1]s syntax when |
| 119 | declaring fields. To pass nested values as arrays, declare multiple fields with the |
| 120 | syntax %[1]skey[]=value1%[1]s, %[1]skey[]=value2%[1]s. To pass an empty array, use %[1]skey[]%[1]s without a |
| 121 | value. |