|
1 | 1 | # GitHub Command Line Tool
|
2 | 2 |
|
3 |
| -Human-friendly command line tool for the GitHub API. |
| 3 | +A human-friendly<sup>1</sup> command line tool for the GitHub API. |
4 | 4 |
|
5 |
| -## Usage |
| 5 | +<sup>1</sup> script-friendly too :) |
6 | 6 |
|
7 |
| -### Command Line Tool |
| 7 | + |
8 | 8 |
|
9 |
| -#### Install globally (recommmended) |
| 9 | +## Installation |
10 | 10 |
|
11 |
| -```shell |
| 11 | +### Global installation (recommmended) |
| 12 | + |
| 13 | +```bash |
12 | 14 | npm install --global @financial-times/github
|
| 15 | +``` |
| 16 | + |
| 17 | +When you run the tool, it will automatically notify you if there is a newer version of it available for you to update to. |
13 | 18 |
|
14 |
| -github --help |
| 19 | +[You can disable notifications](https://www.npmjs.com/package/update-notifier#user-settings) if you'd prefer not to be notified about updates. |
| 20 | + |
| 21 | +### No installation |
| 22 | + |
| 23 | +```bash |
| 24 | +npx @financial-times/github |
15 | 25 | ```
|
16 | 26 |
|
17 |
| -When you run the tool it will automatically notify you if there is a newer |
18 |
| -version of it available for you to update to. This |
19 |
| -[can be disabled](https://www.npmjs.com/package/update-notifier#user-settings) |
20 |
| -if you'd prefer not to be notified about updates. |
| 27 | +The `npx` command lets you use this tool without installing it. However, each time you use `npx` it downloads the whole package from the npm registry, which takes a while. That's why global installation is reccommended. |
21 | 28 |
|
22 |
| -Note: If you install this tool globally on your machine and then run |
23 |
| -`npx @financial-times/github`, it will use the globally installed version of the |
24 |
| -tool rather than temporarily installing it from the npm registry. |
| 29 | +> Note: If this tool is globally installed, `npx @financial-times/github` will use that globally installed version rather than downloading. |
25 | 30 |
|
26 |
| -#### No installation |
| 31 | +## Commands |
27 | 32 |
|
28 |
| -If you just want to try this tool out without installing it, you can run it with |
29 |
| -[`npx`](https://www.npmjs.com/package/npx) e.g. |
| 33 | +```bash |
| 34 | +github |
30 | 35 |
|
31 |
| -```shell |
32 |
| -npx @financial-times/github --help |
| 36 | +# Display help. |
33 | 37 | ```
|
34 | 38 |
|
35 |
| -### Library |
| 39 | +```bash |
| 40 | +github <command> |
36 | 41 |
|
| 42 | +# Display help for the command. |
37 | 43 | ```
|
38 |
| -npm install @financial-times/github |
| 44 | + |
| 45 | +```bash |
| 46 | +github --version |
| 47 | + |
| 48 | +# Show the version number. |
| 49 | +``` |
| 50 | + |
| 51 | +### Working with GitHub Projects |
| 52 | + |
| 53 | +```bash |
| 54 | +github add-pull-request [--column-url] [--pull-request-url] |
| 55 | + |
| 56 | +# Add a pull request to a GitHub project column. |
39 | 57 | ```
|
40 | 58 |
|
41 |
| -```javascript |
42 |
| -const github = require("@financial-times/github")({ |
43 |
| - personalAccessToken: process.env.GITHUB_PERSONAL_ACCESS_TOKEN |
44 |
| -}); |
| 59 | +```bash |
| 60 | +github close-project <github-url> |
| 61 | + |
| 62 | +# Set the state of an existing project board to `closed`. |
| 63 | +``` |
| 64 | + |
| 65 | +```bash |
| 66 | +github create-project <github-url> [--body] |
| 67 | + |
| 68 | +# Create a new project. |
| 69 | +``` |
| 70 | + |
| 71 | +@see: [`src/commands/projects/README.md`](https://github.com/Financial-Times/github/blob/master/src/commands/projects/README.md) for more details. |
| 72 | + |
| 73 | +### Working with GitHub Pull Requests |
| 74 | + |
| 75 | +```bash |
| 76 | +github close-pull-request <github-url> |
| 77 | + |
| 78 | +# Set the state of an existing pull request to `closed`. |
| 79 | +``` |
| 80 | + |
| 81 | +```bash |
| 82 | +github create-comment <github-url> [--body] |
| 83 | + |
| 84 | +# Create a comment on an existing pull request. |
| 85 | +``` |
| 86 | + |
| 87 | +```bash |
| 88 | +github create-review-request <github-url> [reviewers|team-reviewers] |
| 89 | + |
| 90 | +# Request a review for a pull request. |
| 91 | +``` |
| 92 | + |
| 93 | +```bash |
| 94 | +github create-pull-request <github-url> [--base] [--body] [--title] |
| 95 | + |
| 96 | +# Create a new pull request. |
| 97 | +``` |
| 98 | + |
| 99 | +```bash |
| 100 | +github delete-comment <github-url> |
| 101 | + |
| 102 | +# Delete a comment on an existing pull request. |
| 103 | +``` |
| 104 | + |
| 105 | +```bash |
| 106 | +github delete-review-request <github-url> [reviewers|team-reviewers] |
| 107 | + |
| 108 | +# Delete a review for a pull request. |
| 109 | +``` |
| 110 | + |
| 111 | +```bash |
| 112 | +github merge-pull-request <github-url> [--method] |
| 113 | + |
| 114 | +# Merge an existing pull request. |
| 115 | +``` |
| 116 | + |
| 117 | +```bash |
| 118 | +github open-pull-request <github-url> |
| 119 | + |
| 120 | +# Set the state of an existing pull request to `open`. |
| 121 | +``` |
| 122 | + |
| 123 | +@see: [`src/commands/pulls/README.md`](https://github.com/Financial-Times/github/blob/master/src/commands/pulls/README.md) for more details. |
| 124 | + |
| 125 | +### Global Options |
| 126 | + |
| 127 | +```bash |
| 128 | +--json |
| 129 | + |
| 130 | +# Format command output as JSON string. |
| 131 | +``` |
| 132 | + |
| 133 | +```bash |
| 134 | +--token |
| 135 | + |
| 136 | +# GitHub personal access token. |
| 137 | +# Generate one at https://github.com/settings/tokens |
| 138 | +``` |
| 139 | + |
| 140 | +> Note: You can omit the `--token` argument, because it will default to `$GITHUB_PERSONAL_ACCESS_TOKEN`. |
| 141 | +> |
| 142 | +> In that case you will need to export the token to your environment: |
| 143 | +
|
| 144 | +```bash |
| 145 | +export $GITHUB_PERSONAL_ACCESS_TOKEN=[your token here] |
45 | 146 | ```
|
46 | 147 |
|
47 | 148 | # Developers
|
48 | 149 |
|
49 | 150 | ## Command hierarchy and directory structure
|
50 | 151 |
|
51 |
| -This project follows the example provided in the Yargs documentation for command hierarchy and directory structure. |
| 152 | +This project loosely follows the example provided in the Yargs documentation for command hierarchy and directory structure. |
| 153 | + |
| 154 | +- @see: https://github.com/yargs/yargs/blob/master/docs/advanced.md#commanddirdirectory-opts |
| 155 | +- @see: [`bin/github.js`](https://github.com/Financial-Times/github/blob/master/bin/github.js) for the root `github` command. |
| 156 | +- @see: [`src/commands`](https://github.com/Financial-Times/github/blob/master/src/commands/) for the `github <command>` commands. |
| 157 | + |
| 158 | +## Conventions |
| 159 | + |
| 160 | +### CamelCase, hyphen-case and under_scores |
| 161 | + |
| 162 | +- All yargs commands and filenames are in `hyphen-case`. |
| 163 | +- All function names and variables are in `camelCase`. |
| 164 | +- The parameters used by Octokit are in `under_score` format. |
| 165 | + |
| 166 | +### Code formatting and linting |
| 167 | + |
| 168 | +- The [.eslintrc.js](https://github.com/Financial-Times/github/blob/master/.eslintrc.js) file contains the settings for code linting. |
| 169 | + |
| 170 | + - @see: https://eslint.org/ |
| 171 | + |
| 172 | +- Consider installing `eslint` in your editor. Plugins are available for most popular editors. |
| 173 | + |
| 174 | + - @see: https://eslint.org/docs/user-guide/integrations#editors |
52 | 175 |
|
53 |
| - - @see: https://github.com/yargs/yargs/blob/master/docs/advanced.md#commanddirdirectory-opts |
54 |
| - - @see: [`src/commands`](https://github.com/Financial-Times/github/blob/master/src/commands/) for all available commands. |
| 176 | +- Note: `.eslintrc.js` extends the `prettier` tool, which applies code formatting rules. |
55 | 177 |
|
56 |
| -## Conventions: CamelCase and under_scores |
| 178 | + - @see: https://prettier.io/docs/en/integrating-with-linters.html |
57 | 179 |
|
58 |
| -All commands and variables are consistent with the Ocktokit and GitHub APIs documentation, respectively: |
| 180 | +- You can `npm run eslint-check` to check there are no conflicts between eslint and prettier configurations. |
59 | 181 |
|
60 |
| - - https://octokit.github.io/rest.js/#api-Pulls <-- Instead of camelCaseFormat, we use hyphen-format. |
61 |
| - - https://developer.github.com/v3/pulls <-- Variables are under_score_format. |
| 182 | + - @see: https://github.com/prettier/eslint-config-prettier#cli-helper-tool |
| 183 | + |
| 184 | +- The `prettier` tool uses the "@adambraimbridge/prettierrc-2019-05" configuration. |
| 185 | + |
| 186 | + - @see: https://www.npmjs.com/package/@adambraimbridge/prettierrc-2019-05 |
| 187 | + |
| 188 | +- Consider installing `prettier` in your editor. Plugins are available for most popular editors. |
| 189 | + |
| 190 | + - @see: https://prettier.io/docs/en/editors.html |
| 191 | + |
| 192 | +## Package.json scripts |
| 193 | + |
| 194 | +```bash |
| 195 | +npm run unit-test |
| 196 | + |
| 197 | +# jest --coverage |
| 198 | +``` |
| 199 | + |
| 200 | +```bash |
| 201 | +npm run test |
| 202 | + |
| 203 | +# npm run lint && npm run unit-test |
| 204 | +``` |
| 205 | + |
| 206 | +```bash |
| 207 | +npm run lint |
| 208 | + |
| 209 | +# eslint src/ bin/ test/ |
| 210 | +``` |
| 211 | + |
| 212 | +```bash |
| 213 | +npm run lint-fix |
| 214 | + |
| 215 | +# eslint --fix eslint --fix src/ bin/ test/ |
| 216 | +``` |
| 217 | + |
| 218 | +```bash |
| 219 | +npm run eslint-check |
| 220 | + |
| 221 | +# eslint --print-config . | eslint-config-prettier-check |
| 222 | +``` |
0 commit comments