You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Dec 19, 2025. It is now read-only.
Please note the following changes, when you migrate from a version below `2.0.0`:
4
+
5
+
- The `options` object changed and require using a [personal access token](https://blog.github.com/2013-05-16-personal-api-tokens/). See [here](https://github.com/axelrindle/github-version-checker#the-options-object).
6
+
- The `callback` structure changed. I decided to apply a node convention called **Error-First** in which a callback function's first parameter is the `error`. See [here](https://github.com/axelrindle/github-version-checker#the-callback-function-optional).
7
+
8
+
Before opening an issue, please confirm that you changed your code according to these changes.
Simple **version checker** working with **GitHub releases** and the **GitHub API**.
2
+
> Simple **version checker** working with **GitHub releases** and the **GitHub API**.
3
+
4
+
# Note on upgrading to **v2.0.0**
5
+
If you are upgrading from a version before **v2.0.0**, please read [**this guide**](MIGRATING-TO-2.0.0.md).
3
6
4
7
## Install
5
8
```bash
6
9
$ npm install github-version-checker
7
10
```
8
-
or
9
-
```bash
10
-
$ yarn add github-version-checker
11
-
```
12
11
13
12
## Usage
14
13
```javascript
@@ -18,16 +17,16 @@ const pkg = require('./package.json'); // or whereever your package.json lies
18
17
19
18
// version check options (for details see below)
20
19
constoptions= {
21
-
repo:'axelrindle/github-version-checker', // will be expanded to https://api.github.com/repos/axelrindle/github-version-checker/releases
22
-
currentVersion:pkg.version, // your app's current version
23
-
includePreReleases:false// if you want to check pre-releases to
20
+
token:'PUT-YOUR-TOKEN-HERE', // personal access token
21
+
repo:'github-version-checker', // repository name
22
+
owner:'axelrindle', // repository owner
23
+
currentVersion:pkg.version, // your app's current version
24
+
fetchTags:false// whether to fetch releases or tags
24
25
};
25
-
versionCheck(options, function (update, error) { // callback function
26
+
versionCheck(options, function (error, update) { // callback function
26
27
if (error) throw error;
27
28
if (update) { // print some update info if an update is available
28
-
console.log('An update is available!');
29
-
console.log('New version: '+update.tag_name);
30
-
console.log('Details here: '+update.html_url);
29
+
console.log('An update is available! '+update.name);
31
30
}
32
31
33
32
// start your app
@@ -45,27 +44,51 @@ Always try to follow a clear [semver format](http://semver.org/). This helps to
45
44
Performs an update check with the given options. The `callback` is optional, can be left out to return a `Promise`.
46
45
47
46
#### The `options` object
48
-
Option | Default value | Description
47
+
Option | Description | Default Value
49
48
--- | --- | ---
50
-
repo | **None. Required option** | Defines from which GitHub repository to load releases from.
51
-
currentVersion | **None. Required option** | Your app's current version. Needed to check if a newer release is found.
52
-
includePreReleases | false | Whether or not to include pre-releases. **Note:** This will fetch **all** releases, which might result in high traffic, depending on how much releases your app has on GitHub.
49
+
token | A [personal access token](https://blog.github.com/2013-05-16-personal-api-tokens/) used to access the Github GraphQL API (as of version **2.0.0**).
50
+
repo | The name of your Github repository.
51
+
owner | The owner of your Github repository (usually your username).
52
+
currentVersion | Your app's current version. Needed to check if a newer release is found.
53
+
fetchTags | Whether to fetch the repositorie's git tags instead of the GitHub releases (this is useful when the releases are autogenerated from the tags). | `false`
53
54
54
55
#### The `callback` function (optional)
55
56
Should be of the following form:
56
57
```javascript
57
-
function(update, error) {
58
+
function(error, update) {
58
59
// ...your code
59
60
}
60
61
```
61
-
*`update`:
62
-
* An object in the format specified [here](https://developer.github.com/v3/repos/releases/#get-a-single-release). `null` if no update was found.
63
62
*`error`:
64
63
* If an error occurs, this holds the error message. `null` if no error occurs.
64
+
*`update`:
65
+
* An object in the format specified below. `null` if no update was found.
65
66
67
+
#### Using `Promise`
68
+
You can omit the `callback` function to return a `Promise`, which resolved with the `update` object.
66
69
67
-
## Todo
70
+
### Object schemes
71
+
#### Releases
72
+
When fetching releases, an object with the following structure will be returned:
73
+
```js
74
+
Object {
75
+
name
76
+
tag {
77
+
name
78
+
}
79
+
isPrerelease
80
+
publishedAt
81
+
url
82
+
}
83
+
```
84
+
85
+
#### Tags
86
+
When fetching tags, you will receive an object with the following structure:
87
+
```js
88
+
Object {
89
+
name
90
+
}
91
+
```
68
92
69
-
*~~Add a sync method returning just `true` or `false`~~ Can be achieved with **async/await**
70
-
*~~Add settings to define an own update service~~ For now, I stay with GitHub releases only
71
-
*~~Only compare to the latest release on GitHub (see [#1](https://github.com/axelrindle/github-version-checker/issues/1))~~
0 commit comments