Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
];
const properties = {};
const parameters = bodyOverride || req.body;
ourFields.forEach((fieldName) => {
if (parameters[fieldName] !== undefined) {
properties[fieldName] = parameters[fieldName];
delete parameters[fieldName];
}
});
const msProperties = {
onBehalfOf: properties['ms.onBehalfOf'] || req.headers['ms-onbehalfof'],
justification: properties['ms.justification'] || req.headers['ms-justification'],
license: properties['ms.license'] || req.headers['ms-license'],
approvalType: properties['ms.approval'] || req.headers['ms-approval'],
approvalUrl: properties['ms.approval-url'] || req.headers['ms-approval-url'],
notify: properties['ms.notify'] || req.headers['ms-notify'],
teams: properties['ms.teams'] || req.headers['ms-teams'],
template: properties['ms.template'] || req.headers['ms-template'],
projectType: properties['ms.project-type'] || req.headers['ms-project-type'],
};
// Validate licenses
let msLicense = msProperties.license;
if (!msLicense) {
throw jsonError(new Error('Missing Microsoft license information'), 422);
}
msLicense = msLicense.toLowerCase();
if (supportedLicenseExpressions.indexOf(msLicense) < 0) {
throw jsonError(new Error('The provided license expression is not currently supported'), 422);
}
// Validate approval types
const msApprovalType = msProperties.approvalType;
if (!msApprovalType) {
// Team permissions
if (!body.selectedAdminTeams || !body.selectedAdminTeams.length) {
return next(jsonError('No administration team(s) provided in the request', 400));
}
translateTeams(body);
// Initial repo contents and license
const templates = _.keyBy(organization.getRepositoryCreateMetadata().templates, 'id');
const template = templates[body.template];
if (!template) {
return next(jsonError('There was a configuration problem, the template metadata was not available for this request', 400));
}
translateValue(body, 'template', 'ms.template');
body['ms.license'] = template.spdx || template.name; // Today this is the "template name" or SPDX if available
translateValue(body, 'gitIgnoreTemplate', 'gitignore_template');
if (!body['ms.notify']) {
body['ms.notify'] = req.knownRequesterMailAddress || config.brand.operationsMail || config.brand.supportMail;
}
// these fields are currently ignored: orgName
delete body.orgName;
delete body.claEntity; // a legacy value
req.app.settings.providers.insights.trackEvent({
name: 'ApiClientNewOrgRepoStart',
properties: {
body: JSON.stringify(req.body),
},
});
let success: ICreateRepositoryApiResult = null;
try {
success = await CreateRepository(req, body);
} catch (createRepositoryError) {
req.app.settings.providers.insights.trackEvent({
name: 'ApiClientNewOrgRepoError',
translateValue(body, 'projectType', 'ms.project-type');
// Team permissions
if (!body.selectedAdminTeams || !body.selectedAdminTeams.length) {
return next(jsonError('No administration team(s) provided in the request', 400));
}
translateTeams(body);
// Initial repo contents and license
const templates = _.keyBy(organization.getRepositoryCreateMetadata().templates, 'id');
const template = templates[body.template];
if (!template) {
return next(jsonError('There was a configuration problem, the template metadata was not available for this request', 400));
}
translateValue(body, 'template', 'ms.template');
body['ms.license'] = template.spdx || template.name; // Today this is the "template name" or SPDX if available
translateValue(body, 'gitIgnoreTemplate', 'gitignore_template');
if (!body['ms.notify']) {
body['ms.notify'] = req.knownRequesterMailAddress || config.brand.operationsMail || config.brand.supportMail;
}
// these fields are currently ignored: orgName
delete body.orgName;
delete body.claEntity; // a legacy value
req.app.settings.providers.insights.trackEvent({
name: 'ApiClientNewOrgRepoStart',
properties: {
body: JSON.stringify(req.body),
},
});
let success: ICreateRepositoryApiResult = null;
try {
success = await CreateRepository(req, body);
} catch (createRepositoryError) {
req.app.settings.providers.insights.trackEvent({