Skip to content

Commit

Permalink
feat: add analytics for --all-projects
Browse files Browse the repository at this point in the history
  • Loading branch information
gitphill committed Jan 3, 2020
1 parent daf8fd5 commit 1912a1d
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions src/lib/plugins/get-deps-from-plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,12 @@ import { Options, TestOptions } from '../types';
import { NoSupportedManifestsFoundError } from '../errors';
import { getMultiPluginResult } from './get-multi-plugin-result';
import { getSinglePluginResult } from './get-single-plugin-result';
import { detectPackageFile, AUTO_DETECTABLE_FILES } from '../detect';
import {
detectPackageFile,
AUTO_DETECTABLE_FILES,
detectPackageManagerFromFile,
} from '../detect';
import analytics = require('../analytics');

const debug = debugModule('snyk');

Expand All @@ -18,8 +23,8 @@ export async function getDepsFromPlugin(
let inspectRes: pluginApi.InspectResult;

if (options.allProjects) {
// auto-detect only one-level deep for now
const targetFiles = await find(root, [], AUTO_DETECTABLE_FILES, 1);
const levelsDeep = 1; // TODO: auto-detect only one-level deep for now
const targetFiles = await find(root, [], AUTO_DETECTABLE_FILES, levelsDeep);
debug(
`auto detect manifest files, found ${targetFiles.length}`,
targetFiles,
Expand All @@ -28,6 +33,15 @@ export async function getDepsFromPlugin(
throw NoSupportedManifestsFoundError([root]);
}
inspectRes = await getMultiPluginResult(root, options, targetFiles);
const analyticData = {
scannedProjects: inspectRes.scannedProjects.length,
targetFiles,
packageManagers: targetFiles.map((file) =>
detectPackageManagerFromFile(file),
),
levelsDeep,
};
analytics.add('allProjects', analyticData);
return inspectRes;
} else {
// TODO: is this needed for the auto detect handling above?
Expand Down

0 comments on commit 1912a1d

Please sign in to comment.