Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
items.map(i => {
const icon = {
type: i && i.icon && i.icon.type,
path: '',
};
if (i.icon && i.icon.path) {
icon.path = i.icon.path;
const isBase64 = /data:image\/.*;base64/.test(i.icon.path);
if (!is.url(i.icon.path) && !isBase64) {
icon.path = path.resolve(plugin.path, i.icon.path);
}
}
// if an icon isn't set, fallback to the icon.png file in the plugin's directory
if (!icon.path) {
icon.path = path.resolve(plugin.path, 'icon.png');
}
const newObject = deepAssign({}, i);
newObject.plugin = {
path: plugin.path,
name: plugin.name,
};
if (plugin.keyword) {
newObject.keyword = plugin.keyword;
}
if (plugin.action) {
const configCopy = Object.assign({}, config);
// handle the 'legacy' configuration where each type had its own propery
if (configCopy.contributorListGithubUrl) {
configCopy.contributors = configCopy.contributorListGithubUrl;
} else if (config.contributorListUrl) {
configCopy.contributors = configCopy.contributorListUrl;
} else if (config.contributorWebhook) {
configCopy.contributors = configCopy.contributorWebhook;
}
if (configCopy.contributors) {
if (is.array(configCopy.contributors)) {
console.info('INFO', 'Checking contributors against the list supplied in the .clabot file');
return contributorArrayVerifier(configCopy.contributors);
} else if (is.url(configCopy.contributors) && configCopy.contributors.indexOf('api.github.com') !== -1) {
console.info('INFO', 'Checking contributors against the github URL supplied in the .clabot file');
return configFileFromGithubUrlVerifier(configCopy.contributors);
} else if (is.url(configCopy.contributors) && configCopy.contributors.indexOf('?') !== -1) {
console.info('INFO', 'Checking contributors against the webhook supplied in the .clabot file');
return webhookVerifier(configCopy.contributors);
} else if (is.url(configCopy.contributors)) {
console.info('INFO', 'Checking contributors against the URL supplied in the .clabot file');
return configFileFromUrlVerifier(configCopy.contributors);
}
}
throw new Error('A mechanism for verifying contributors has not been specified');
};
wordsToAnchorify.forEach(word => {
let href = !is.url(word) && !word.startsWith('ob://') ?
`#ob://${word}` : word;
if (is.url(word)) {
const link = document.createElement('a');
link.setAttribute('href', word);
if (link.protocol === 'file:') {
href = `http://${word}`;
}
}
processedMessage = processedMessage
.split(word)
.join(`<a class="clrTEm" href="${href}">${word}</a>`);
});
configCopy.contributors = configCopy.contributorListUrl;
} else if (config.contributorWebhook) {
configCopy.contributors = configCopy.contributorWebhook;
}
if (configCopy.contributors) {
if (is.array(configCopy.contributors)) {
console.info('INFO', 'Checking contributors against the list supplied in the .clabot file');
return contributorArrayVerifier(configCopy.contributors);
} else if (is.url(configCopy.contributors) && configCopy.contributors.indexOf('api.github.com') !== -1) {
console.info('INFO', 'Checking contributors against the github URL supplied in the .clabot file');
return configFileFromGithubUrlVerifier(configCopy.contributors);
} else if (is.url(configCopy.contributors) && configCopy.contributors.indexOf('?') !== -1) {
console.info('INFO', 'Checking contributors against the webhook supplied in the .clabot file');
return webhookVerifier(configCopy.contributors);
} else if (is.url(configCopy.contributors)) {
console.info('INFO', 'Checking contributors against the URL supplied in the .clabot file');
return configFileFromUrlVerifier(configCopy.contributors);
}
}
throw new Error('A mechanism for verifying contributors has not been specified');
};
validate(attrs) {
const errObj = {};
const addError = (fieldName, error) => {
errObj[fieldName] = errObj[fieldName] || [];
errObj[fieldName].push(error);
};
if (!attrs.url || (typeof attrs.url === 'string' && !attrs.url.trim())) {
addError('url', app.polyglot.t('orderFulfillmentModelErrors.provideUrl'));
} else if (!is.url(attrs.url)) {
addError('url', app.polyglot.t('orderFulfillmentModelErrors.invalidUrl'));
}
if (Object.keys(errObj).length) return errObj;
return undefined;
}
}
urlTypes.push('vendors');
}
if (is.url(data.links.listings)) {
update.listings = data.links.listings;
urlTypes.push('listings');
}
if (is.url(data.links.reports)) {
update.reports = data.links.reports;
urlTypes.push('reports');
}
if (data.links.tor) {
if (is.url(data.links.tor.listings)) {
update.torListings = data.links.tor.listings;
urlTypes.push('torlistings');
}
if (is.url(data.links.tor.vendors)) {
update.torVendors = data.links.tor.vendors;
urlTypes.push('torVendors');
}
if (is.url(data.links.tor.reports)) {
update.torReports = data.links.tor.reports;
urlTypes.push('torReports');
}
}
}
return {
update,
urlTypes,
};
}
if (data.logo && is.url(data.logo)) update.logo = data.logo;
if (data.links) {
if (is.url(data.links.vendors)) {
update.vendors = data.links.vendors;
urlTypes.push('vendors');
}
if (is.url(data.links.listings)) {
update.listings = data.links.listings;
urlTypes.push('listings');
}
if (is.url(data.links.reports)) {
update.reports = data.links.reports;
urlTypes.push('reports');
}
if (data.links.tor) {
if (is.url(data.links.tor.listings)) {
update.torListings = data.links.tor.listings;
urlTypes.push('torlistings');
}
if (is.url(data.links.tor.vendors)) {
update.torVendors = data.links.tor.vendors;
urlTypes.push('torVendors');
}
if (is.url(data.links.tor.reports)) {
update.torReports = data.links.tor.reports;
urlTypes.push('torReports');
}
}
}
return {
update,
urlTypes.push('listings');
}
if (is.url(data.links.reports)) {
update.reports = data.links.reports;
urlTypes.push('reports');
}
if (data.links.tor) {
if (is.url(data.links.tor.listings)) {
update.torListings = data.links.tor.listings;
urlTypes.push('torlistings');
}
if (is.url(data.links.tor.vendors)) {
update.torVendors = data.links.tor.vendors;
urlTypes.push('torVendors');
}
if (is.url(data.links.tor.reports)) {
update.torReports = data.links.tor.reports;
urlTypes.push('torReports');
}
}
}
return {
update,
urlTypes,
};
}
buildProviderUpdate(data) {
const update = {};
const urlTypes = [];
if (data.name && is.string(data.name)) update.name = data.name;
if (data.logo && is.url(data.logo)) update.logo = data.logo;
if (data.links) {
if (is.url(data.links.vendors)) {
update.vendors = data.links.vendors;
urlTypes.push('vendors');
}
if (is.url(data.links.listings)) {
update.listings = data.links.listings;
urlTypes.push('listings');
}
if (is.url(data.links.reports)) {
update.reports = data.links.reports;
urlTypes.push('reports');
}
if (data.links.tor) {
if (is.url(data.links.tor.listings)) {
update.torListings = data.links.tor.listings;
const isurl = url => url.match(/^http:\/\/localhost:\d*\/?$/) || is.url(url);