create gitea from github
authorAJ ONeal <aj@therootcompany.com>
Sun, 3 May 2020 10:25:57 +0000 (10:25 +0000)
committerAJ ONeal <aj@therootcompany.com>
Sun, 3 May 2020 10:25:57 +0000 (10:25 +0000)
_common/gitea.js [new file with mode: 0644]
_common/github.js

diff --git a/_common/gitea.js b/_common/gitea.js
new file mode 100644 (file)
index 0000000..425d7d7
--- /dev/null
@@ -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<any> | Promise<any>}
+ */
+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));
+    }
+  );
+}
index 0ad9782e339c1116fce76d6350f06ad385973359..eb117ebb5028079c85228ffb96ff5c487e928a23 100644 (file)
@@ -9,7 +9,7 @@
  * @param {string} repo
  * @returns {PromiseLike<any> | Promise<any>}
  */
-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;