Skip to content
This repository was archived by the owner on Dec 19, 2025. It is now read-only.

Commit 6de6a17

Browse files
author
Axel Rindle
committed
Implement tag fetching for rest api as well
1 parent 17bc1e2 commit 6de6a17

File tree

2 files changed

+39
-5
lines changed

2 files changed

+39
-5
lines changed

lib/check.js

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ const https = require('https');
33
const github_graphql = require('github-graphql-client');
44
const semver = require('semver');
55
const query = require('./query');
6+
const schemeMapper = require('./scheme-mapper');
67
const pkg = require('../package.json');
78

89
/**
@@ -79,24 +80,32 @@ const rest = (options, callback) => {
7980
let version = null;
8081
for (let i = 0; i < json.length; i++) {
8182
version = json[i];
82-
if (semver.gt(version.tag_name, options.currentVersion)) {
83+
if (semver.gt(version[options.fetchTags ? 'name' : 'tag_name'], options.currentVersion)) {
8384
found = true;
8485
break;
8586
}
8687
}
8788

8889
if (found) {
89-
callback(null, version);
90+
const mapped = schemeMapper[options.fetchTags ? 'tag' : 'release'](version);
91+
console.log(mapped);
92+
callback(null, mapped);
9093
} else {
9194
callback(null, null);
9295
}
9396
});
9497
};
9598

9699
// build url
97-
let apiUrl = `https://api.github.com/repos/${options.owner}/${options.repo}/releases`;
98-
if (options.latestOnly) {
99-
apiUrl += '/latest';
100+
let apiUrl = `https://api.github.com/repos/${options.owner}/${options.repo}`;
101+
if (options.fetchTags) {
102+
apiUrl += '/tags';
103+
} else {
104+
apiUrl += '/releases';
105+
106+
if (options.latestOnly) {
107+
apiUrl += '/latest';
108+
}
100109
}
101110

102111
// define request options

lib/scheme-mapper.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/**
2+
* Maps a response object into the form described here:
3+
* https://github.com/axelrindle/github-version-checker/wiki/API#releases
4+
*/
5+
module.exports.release = obj => {
6+
return {
7+
name: obj.name,
8+
tag: {
9+
name: obj.tag_name
10+
},
11+
isPrerelease: obj.prerelease,
12+
publishedAt: obj.published_at,
13+
url: obj.html_url
14+
}
15+
};
16+
17+
/**
18+
* Maps a response object into the form described here:
19+
* https://github.com/axelrindle/github-version-checker/wiki/API#tags
20+
*/
21+
module.exports.tag = obj => {
22+
return {
23+
name: obj.name
24+
}
25+
};

0 commit comments

Comments
 (0)