|
| 1 | +--- |
| 2 | +sidebar_position: 2 |
| 3 | +--- |
| 4 | + |
| 5 | +# API |
| 6 | + |
| 7 | +```js |
| 8 | +// Require the module |
| 9 | +const versionCheck = require('github-version-checker'); |
| 10 | +``` |
| 11 | + |
| 12 | +### `function versionCheck(options, [callback])` |
| 13 | +Performs an update check with the given options. The `callback` is optional, can be omitted to return a `Promise`. |
| 14 | + |
| 15 | +#### The `options` object |
| 16 | +Option | Description | Default Value | Introduction |
| 17 | +--- | --- | --- | --- |
| 18 | +token | A [personal access token](https://blog.github.com/2013-05-16-personal-api-tokens/) used to access the **Github GraphQL API (v4)**. Can be omitted and instead be read from an env variable called `GITHUB_API_TOKEN`. When no token can be found, the module will fall back to the **Github Rest API (v3)**. | `undefined` | `v2.0.0` |
| 19 | +repo | The name of your Github repository.| **None. Required.** | `v1.0.0` |
| 20 | +owner | The owner of your Github repository (usually your username).| **None. Required.** | `v1.0.0` |
| 21 | +currentVersion | Your app's current version. | **None. Required.** | `v1.0.0` |
| 22 | +fetchTags | Whether to fetch the repositories' git tags instead of the GitHub releases. Useful when no releases are created, but only tags. | `false` | `v1.0.0` |
| 23 | +latestOnly | Setting this to `true` will fetch the latest release only | `false` | `v2.2.0` |
| 24 | +excludePrereleases | Excludes pre-releases from checks. Currently only works when no token is specified. | `false` | `v2.3.0` |
| 25 | + |
| 26 | +#### The `callback` function (optional) |
| 27 | +Should be of the following form: |
| 28 | +```javascript |
| 29 | +function(error, update) { |
| 30 | + // ...your code |
| 31 | +} |
| 32 | +``` |
| 33 | +* `error`: |
| 34 | + * If an error occurs, this holds the error message. `null` if no error occurs. |
| 35 | +* `update`: |
| 36 | + * An object in the format specified below. `null` if no update was found. |
| 37 | + |
| 38 | +#### Using `Promise` |
| 39 | +You can omit the `callback` function to return a `Promise`, which resolves with the `update` object. |
| 40 | + |
| 41 | +### Object schemes |
| 42 | +#### Releases |
| 43 | +When fetching releases, an object with the following structure will be returned: |
| 44 | +```js |
| 45 | +Object { |
| 46 | + name |
| 47 | + tag { |
| 48 | + name |
| 49 | + } |
| 50 | + isPrerelease |
| 51 | + publishedAt |
| 52 | + url |
| 53 | +} |
| 54 | +``` |
| 55 | + |
| 56 | +#### Tags |
| 57 | +When fetching tags, you will receive an object with the following structure: |
| 58 | +```js |
| 59 | +Object { |
| 60 | + name |
| 61 | +} |
| 62 | +``` |
0 commit comments