Skip to content

Commit

Permalink
Implement tag fetching for rest api as well
Browse files Browse the repository at this point in the history
  • Loading branch information
Axel Rindle committed May 2, 2020
1 parent 17bc1e2 commit 6de6a17
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 5 deletions.
19 changes: 14 additions & 5 deletions lib/check.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ const https = require('https');
const github_graphql = require('github-graphql-client');
const semver = require('semver');
const query = require('./query');
const schemeMapper = require('./scheme-mapper');
const pkg = require('../package.json');

/**
Expand Down Expand Up @@ -79,24 +80,32 @@ const rest = (options, callback) => {
let version = null;
for (let i = 0; i < json.length; i++) {
version = json[i];
if (semver.gt(version.tag_name, options.currentVersion)) {
if (semver.gt(version[options.fetchTags ? 'name' : 'tag_name'], options.currentVersion)) {
found = true;
break;
}
}

if (found) {
callback(null, version);
const mapped = schemeMapper[options.fetchTags ? 'tag' : 'release'](version);
console.log(mapped);
callback(null, mapped);
} else {
callback(null, null);
}
});
};

// build url
let apiUrl = `https://api.github.com/repos/${options.owner}/${options.repo}/releases`;
if (options.latestOnly) {
apiUrl += '/latest';
let apiUrl = `https://api.github.com/repos/${options.owner}/${options.repo}`;
if (options.fetchTags) {
apiUrl += '/tags';
} else {
apiUrl += '/releases';

if (options.latestOnly) {
apiUrl += '/latest';
}
}

// define request options
Expand Down
25 changes: 25 additions & 0 deletions lib/scheme-mapper.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/**
* Maps a response object into the form described here:
* https://github.com/axelrindle/github-version-checker/wiki/API#releases
*/
module.exports.release = obj => {
return {
name: obj.name,
tag: {
name: obj.tag_name
},
isPrerelease: obj.prerelease,
publishedAt: obj.published_at,
url: obj.html_url
}
};

/**
* Maps a response object into the form described here:
* https://github.com/axelrindle/github-version-checker/wiki/API#tags
*/
module.exports.tag = obj => {
return {
name: obj.name
}
};

0 comments on commit 6de6a17

Please sign in to comment.