From aa8e5f6bc399fd86af5b1cb15820a32974343764 Mon Sep 17 00:00:00 2001 From: AJ ONeal Date: Sun, 3 May 2020 10:25:57 +0000 Subject: [PATCH] create gitea from github --- _common/gitea.js | 31 +++++++++++++++++++++++++++++++ _common/github.js | 4 ++-- 2 files changed, 33 insertions(+), 2 deletions(-) create mode 100644 _common/gitea.js diff --git a/_common/gitea.js b/_common/gitea.js new file mode 100644 index 0000000..425d7d7 --- /dev/null +++ b/_common/gitea.js @@ -0,0 +1,31 @@ +'use strict'; + +var ghRelease = require('./github.js'); + +/** + * Gets the releases for 'ripgrep'. This function could be trimmed down and made + * for use with any github release. + * + * @param request + * @param {string} owner + * @param {string} repo + * @returns {PromiseLike | Promise} + */ +function getAllReleases(request, owner, repo, baseurl) { + if (!baseurl) { + return Promise.reject('missing baseurl'); + } + return ghRelease(request, owner, repo, baseurl + '/api/v1').then(function (all) { + return all; + }); +} + +module.exports = getAllReleases; + +if (module === require.main) { + getAllReleases(require('@root/request'), 'root', 'serviceman', 'https://git.rootprojects.org').then( + function (all) { + console.log(JSON.stringify(all, null, 2)); + } + ); +} diff --git a/_common/github.js b/_common/github.js index 0ad9782..eb117eb 100644 --- a/_common/github.js +++ b/_common/github.js @@ -9,7 +9,7 @@ * @param {string} repo * @returns {PromiseLike | Promise} */ -function getAllReleases(request, owner = 'BurntSushi', repo = 'ripgrep') { +function getAllReleases(request, owner, repo, baseurl = 'https://api.github.com') { if (!owner) { return Promise.reject('missing owner for repo'); } @@ -17,7 +17,7 @@ function getAllReleases(request, owner = 'BurntSushi', repo = 'ripgrep') { return Promise.reject('missing repo name'); } return request({ - url: `https://api.github.com/repos/${owner}/${repo}/releases`, + url: `${baseurl}/repos/${owner}/${repo}/releases`, json: true }).then((resp) => { const gHubResp = resp.body; -- 2.25.1