// API utilities /** * Execute an GitHub HTTP API request * @param {String} httpMethod 'get', 'post', etc. * @param {String} method name of the method * @param {Object} args Req. parameters for get, or json data for others */ request(httpMethod, method, args) { const axiosOpts = { method: httpMethod, url: urlJoin( this.options.get('host'), '/repos/' + this.options.get('repository') + '/' + method ) + '?t=' + Date.now(), headers: { 'Accept': 'application/vnd.github.v3+json', 'Content-type': 'application/json;charset=UTF-8' } }; const username = this.options.get('username'); const token = this.options.get('token'); if (username && token) { axiosOpts.headers['Authorization'] = 'Basic ' + base64.encode(username + ':' + token); } else if (token) { axiosOpts.headers['Authorization'] = 'Token ' + token; } if (httpMethod == 'get') axiosOpts.params = args; else axiosOpts.data = args; // console.log('API', httpMethod.toUpperCase(), method); return Q(axios(axiosOpts)) .get('data') .fail((response) => { if (response instanceof Error) throw response; const e = new Error(response.data.message || 'Error ' + response.status + ': ' + response.data); e.statusCode = response.status; throw e; }); }
.then(function(versions) { var latest = versions[0]; // Already using latest version? if (!latest || latest.tag == tag) { return res.status(204).send('No updates'); } // Extract release notes from all versions in range var notesSlice = versions.length === 1? [versions[0]] : versions.slice(0, -1); var releaseNotes = notes.merge(notesSlice, { includeTag: false }); // URL for download should be absolute var gitFilePath = (req.params.channel ? '/../../../../../' : '/../../../' ); res.status(200) .send({ 'url': urljoin(fullUrl, gitFilePath, '/download/version/' + latest.tag + '/' + platform + '?filetype=' + filetype), 'name': latest.tag, 'notes': releaseNotes, 'pub_date': latest.published_at.toISOString() }); })
.map(function(entry) { var gitFilePath = (channel === '*' ? '../../../../' : '../../../../../../'); entry.filename = urljoin(fullUrl, gitFilePath, '/download/'+latest.tag+'/'+entry.filename); return entry; })
.map(function(entry) { entry.filename = urljoin(fullUrl, '/../../../../', '/download/'+entry.semver+'/'+entry.filename); return entry; })