Deprecate sync-request
This commit is contained in:
Родитель
99457069c5
Коммит
f8761fcec0
|
@ -1,7 +1,8 @@
|
|||
var express = require('express');
|
||||
var router = express.Router();
|
||||
const util = require('util');
|
||||
const request = require('sync-request');
|
||||
var utils = require('./utils');
|
||||
const request = utils.request;
|
||||
const constants = require('./constants');
|
||||
const kusto = require('./kusto');
|
||||
|
||||
|
@ -11,16 +12,16 @@ const buildResultUrlFormat = "https://dev.azure.com/%s/%s/_build/results?buildId
|
|||
|
||||
const platformMapping = constants.PLATFORMS;
|
||||
|
||||
function GetLatestBuild(req) {
|
||||
async function GetLatestBuild(req) {
|
||||
var params = req.params;
|
||||
var query = req.query;
|
||||
var succeededBuildUrl = util.format(succeededBuildUrlFormat, params.organization, params.project, params.definitionId, query.branchName);
|
||||
var buildRes = request('GET', succeededBuildUrl);
|
||||
var build = JSON.parse(buildRes.getBody('utf8'));
|
||||
var buildRes = await request('GET', succeededBuildUrl);
|
||||
var build = JSON.parse(buildRes);
|
||||
return build;
|
||||
}
|
||||
|
||||
function RedirectArtifacts(req, res, next) {
|
||||
async function RedirectArtifacts(req, res, next) {
|
||||
var params = req.params;
|
||||
var query = req.query;
|
||||
var buildId = params.buildId;
|
||||
|
@ -30,14 +31,14 @@ function RedirectArtifacts(req, res, next) {
|
|||
return res.status(400).json({status: 400, message: message});
|
||||
}
|
||||
|
||||
var build = GetLatestBuild(req);
|
||||
var build = await GetLatestBuild(req);
|
||||
var value = build.value[0];
|
||||
buildId = value.id;
|
||||
}
|
||||
|
||||
var artifactUrl = util.format(artifactUrlFormat, params.organization, params.project, buildId, query.artifactName);
|
||||
var artifactRes = request('GET', artifactUrl, {json: {"Content-type": "application/json"}});
|
||||
var artifact = JSON.parse(artifactRes.getBody('utf8'));
|
||||
var artifactRes = await request('GET', artifactUrl, {headers: {"Content-type": "application/json"}});
|
||||
var artifact = JSON.parse(artifactRes);
|
||||
var downloadUrl = artifact.resource.downloadUrl;
|
||||
if (query.subPath != null){
|
||||
if (query.format != "zip"){
|
||||
|
@ -53,7 +54,7 @@ function RedirectArtifacts(req, res, next) {
|
|||
res.redirect(downloadUrl);
|
||||
}
|
||||
|
||||
function RedirectSonicArtifacts(req, res, next) {
|
||||
async function RedirectSonicArtifacts(req, res, next) {
|
||||
var params = req.params;
|
||||
var query = req.query;
|
||||
params['organization'] = 'mssonic';
|
||||
|
@ -86,7 +87,7 @@ function RedirectSonicArtifacts(req, res, next) {
|
|||
query['artifactName'] = 'sonic-buildimage.' + platform;
|
||||
}
|
||||
|
||||
RedirectArtifacts(req, res, next);
|
||||
await RedirectArtifacts(req, res, next);
|
||||
}
|
||||
|
||||
/* Get the build artifacts for all public projects
|
||||
|
|
|
@ -3,7 +3,8 @@ const KustoConnectionStringBuilder = require("azure-kusto-data").KustoConnection
|
|||
const ClientRequestProperties = require("azure-kusto-data").ClientRequestProperties;
|
||||
const uuidv4 = require("uuid/v4");
|
||||
const NodeCache = require( "node-cache" );
|
||||
const request = require('sync-request');
|
||||
var utils = require('./utils');
|
||||
const request = utils.request;
|
||||
|
||||
const clusterConectionString = "https://sonic.westus2.kusto.windows.net";
|
||||
const database = "build";
|
||||
|
@ -14,10 +15,10 @@ const TEST = false;
|
|||
|
||||
/* Query builds from Azure Pipelines, only for test
|
||||
Only support to list the default branch for a definition, it is hard to list all the branches for Azure Pipelines API in a single query*/
|
||||
function test_queryBuilds(){
|
||||
async function test_queryBuilds(){
|
||||
var url = "https://dev.azure.com/mssonic/build/_apis/build/definitions?api-version=6.0&includeAllProperties=true";
|
||||
var definitionsRes = request('GET', url);
|
||||
var definitions = JSON.parse(definitionsRes.getBody('utf8'));
|
||||
var definitionsRes = await request('GET', url);
|
||||
var definitions = JSON.parse(definitionsRes);
|
||||
var results = {};
|
||||
//Sequence, DefinitionId, DefinitionName, Platform, SourceBranch
|
||||
var rows = [];
|
||||
|
@ -50,7 +51,7 @@ async function query(queryString, timoutInSeconds = 1000 * 20, fromAzureAPI = fa
|
|||
clientRequestProps.clientRequestId = `MyApp.MyActivity;${uuidv4()}`;
|
||||
|
||||
if (TEST || fromAzureAPI){
|
||||
return test_queryBuilds();
|
||||
return await test_queryBuilds();
|
||||
}
|
||||
|
||||
try {
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
var express = require('express');
|
||||
var router = express.Router();
|
||||
const request = require('sync-request');
|
||||
var utils = require('./utils');
|
||||
const request = utils.request;
|
||||
const constants = require('./constants');
|
||||
const kusto = require('./kusto');
|
||||
const util = require('util');
|
||||
|
@ -56,12 +57,12 @@ router.get('/sonic/pipelines', async function(req, res, next) {
|
|||
});
|
||||
|
||||
/* Get SONiC builds. */
|
||||
router.get('/sonic/pipelines/:definitionId/builds', function(req, res, next) {
|
||||
router.get('/sonic/pipelines/:definitionId/builds', async function(req, res, next) {
|
||||
var params = req.params;
|
||||
var query = req.query;
|
||||
var url = util.format(buildUrlFormat, params.definitionId, query.branchName)
|
||||
var buildsRes = request('GET', url);
|
||||
var builds = JSON.parse(buildsRes.getBody('utf8'));
|
||||
var url = util.format(buildUrlFormat, params.definitionId, query.branchName);
|
||||
var buildsRes = await request('GET', url);
|
||||
var builds = JSON.parse(buildsRes);
|
||||
res.render('builds', { title: 'Builds',
|
||||
rows: builds['value'],
|
||||
branchName: query.branchName,
|
||||
|
@ -69,13 +70,13 @@ router.get('/sonic/pipelines/:definitionId/builds', function(req, res, next) {
|
|||
});
|
||||
|
||||
/* Get SONiC artifacts. */
|
||||
router.get('/sonic/pipelines/:definitionId/builds/:buildId/artifacts', function(req, res, next) {
|
||||
router.get('/sonic/pipelines/:definitionId/builds/:buildId/artifacts', async function(req, res, next) {
|
||||
var params = req.params;
|
||||
var query = req.query;
|
||||
var url = util.format(artifactUrlFormat, params.buildId);
|
||||
var navigator_builds = navigator_pipelines.concat([{name:'Builds', href:`/ui/sonic/pipelines/${params.definitionId}/builds?branchName=${query.branchName}`}]);
|
||||
var artifactsRes = request('GET', url);
|
||||
var artifacts = JSON.parse(artifactsRes.getBody('utf8'));
|
||||
var artifactsRes = await request('GET', url);
|
||||
var artifacts = JSON.parse(artifactsRes);
|
||||
for(var i=0; i<artifacts['value'].length; i++){
|
||||
var row = artifacts['value'][i];
|
||||
row["seq"] = i + 1;
|
||||
|
@ -89,7 +90,7 @@ router.get('/sonic/pipelines/:definitionId/builds/:buildId/artifacts', function(
|
|||
});
|
||||
|
||||
/* Get SONiC artifact files. */
|
||||
router.get('/sonic/pipelines/:definitionId/builds/:buildId/artifacts/:artifactId', function(req, res, next) {
|
||||
router.get('/sonic/pipelines/:definitionId/builds/:buildId/artifacts/:artifactId', async function(req, res, next) {
|
||||
var params = req.params;
|
||||
var query = req.query;
|
||||
var sourceUrl = util.format(buildResultUrlFormat, params.buildId);
|
||||
|
@ -111,8 +112,8 @@ router.get('/sonic/pipelines/:definitionId/builds/:buildId/artifacts/:artifactId
|
|||
},
|
||||
body: JSON.stringify(body),
|
||||
};
|
||||
var artifactsRes = request('POST', url, options);
|
||||
var artifacts = JSON.parse(artifactsRes.getBody('utf8'));
|
||||
var artifactsRes = await request('POST', url, options);
|
||||
var artifacts = JSON.parse(artifactsRes);
|
||||
var dataProvider = artifacts['dataProviders']['ms.vss-build-web.run-artifacts-data-provider'];
|
||||
var items = GetArtifactItems(dataProvider.items);
|
||||
for (var i=0; i<items.length; i++){
|
||||
|
|
|
@ -0,0 +1,39 @@
|
|||
const util = require('util');
|
||||
const request = require('request');
|
||||
|
||||
function _request_internal(options) {
|
||||
return new Promise((resolve, reject) => {
|
||||
request(options, (error, response, body) => {
|
||||
if (error) {
|
||||
console.error(error);
|
||||
reject(error);
|
||||
}
|
||||
if (response.statusCode != 200) {
|
||||
console.error(response.statusCode);
|
||||
reject('Invalid status code <' + response.statusCode + '>');
|
||||
}
|
||||
resolve(body);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
async function _request(method, url, options=null) {
|
||||
try{
|
||||
if (options == null){
|
||||
options = {}
|
||||
}
|
||||
options['url'] = url;
|
||||
options['method'] = method;
|
||||
|
||||
return _request_internal(options);
|
||||
}
|
||||
catch(error)
|
||||
{
|
||||
console.error(util.format("failed to %s request to %s", method, url));
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = Object.freeze({
|
||||
request: _request,
|
||||
});
|
Загрузка…
Ссылка в новой задаче