Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
export function hasDependency(on: DependencySpecifier): PredicatePushTest {
return predicatePushTest(
`hasDeclaredDep-${coordinates(on)}`,
async p => {
// Attempt an optimization: Look for it in the fast stuff first
const directDeps = (await findDeclaredDependencies(p)).dependencies;
const direct = dependencyFound(on, directDeps);
if (direct) {
return true;
}
// If we're still going, check transient dependencies
const deps = await findDependenciesFromEffectivePom(p);
return dependencyFound(on, deps);
},
);
}
export async function init(opts: InitOptions): Promise {
// 1. clone the repo
try {
print.info("Cloning repository...");
await execPromise("git", ["clone", opts.cloneUrl, "."]);
await execPromise("git", ["checkout", opts.sha]);
print.info("Finished");
} catch (e) {
print.error(`Failed to checkout repository: ${e.message}`);
return 5;
}
// 2. load input
const inputs: string[] = JSON.parse(process.env.ATOMIST_INPUT || "[]");
for (const input of inputs) {
print.info(`Restoring '${input}'`);
try {
const files = glob.sync(input, { cwd: "/atm/share" });
for (const file of files) {
await fs.copy(path.join("/", "atm", "share", file), path.join(process.cwd(), file), {
overwrite: true,
if (options.push) {
if (!options.user || !options.password) {
const message = "Required configuration missing for pushing docker image. Please make sure to set " +
"'registry', 'user' and 'password' in your configuration.";
progressLog.write(message);
return { code: 1, message };
}
const loginArgs: string[] = ["login", "--username", options.user, "--password", options.password];
if (/[^A-Za-z0-9]/.test(options.registry)) {
loginArgs.push(options.registry);
}
// 2. run docker login
let result = await spawnAndWatch(
{
command: "docker",
args: loginArgs,
},
{},
progressLog,
{
...spOpts,
logCommand: false,
});
if (result.code !== 0) {
return result;
}
// 3. run docker push
}
if (!!_.get(pj.devDependencies, pk.name)) {
pj.devDependencies[pk.name] = pk.version;
}
// Fix up peerDependency entries
if (!!_.get(pj.peerDependencies, pk.name)) {
const version = pk.version.replace(/\^/g, "");
const peerVersion = `>=${semver.major(version)}.${semver.minor(version)}.0`;
pj.peerDependencies[pk.name] = peerVersion;
}
});
await file.setContent(JSON.stringify(pj, undefined, 2));
const log = new LoggingProgressLog("npm install");
const result = await spawnLog(
"npm",
["install"],
{
cwd: (p as LocalProject).baseDir,
log,
logCommand: true,
});
return result.code === 0;
} else {
return false;
}
};
await verifyGoal(sdmGoal, this.configuration.sdm.goalSigning, ctx);
if ((await cancelableGoal(sdmGoal, this.configuration)) && (await isGoalCanceled(sdmGoal, ctx))) {
logger.debug(`Goal ${sdmGoal.uniqueName} has been canceled. Not fulfilling`);
return Success;
}
if (sdmGoal.fulfillment.method === SdmGoalFulfillmentMethod.SideEffect &&
sdmGoal.fulfillment.registration !== this.configuration.name) {
logger.debug("Not fulfilling side-effected goal '%s' with method '%s/%s'",
sdmGoal.uniqueName, sdmGoal.fulfillment.method, sdmGoal.fulfillment.name);
return Success;
} else if (sdmGoal.fulfillment.method === SdmGoalFulfillmentMethod.Other) {
// fail goal with neither Sdm nor SideEffect fulfillment
await updateGoal(
ctx,
sdmGoal,
{
state: SdmGoalState.failure,
description: `No fulfillment for ${sdmGoal.uniqueName}`,
});
return Success;
}
const id = this.configuration.sdm.repoRefResolver.repoRefFromSdmGoal(sdmGoal);
const credentials = await resolveCredentialsPromise(this.configuration.sdm.credentialsResolver.eventHandlerCredentials(ctx, id));
const addressChannels = addressChannelsFor(sdmGoal.push.repo, ctx);
const preferences = this.configuration.sdm.preferenceStoreFactory(ctx);
const implementation = this.implementationMapper.findImplementationBySdmGoal(sdmGoal);
const { goal } = implementation;
parameters: !!event.data.SdmGoal[0].parameters ? JSON.parse(event.data.SdmGoal[0].parameters) : {},
};
const goalScheduler = await findGoalScheduler(goalInvocation, this.configuration);
if (!!goalScheduler) {
const start = Date.now();
const result = await goalScheduler.schedule(goalInvocation);
if (!!result && result.code !== undefined && result.code !== 0) {
await updateGoal(ctx, sdmGoal, {
state: SdmGoalState.failure,
description: `Failed to schedule goal`,
url: progressLog.url,
});
await reportEndAndClose(result, start, progressLog);
} else {
await updateGoal(ctx, sdmGoal, {
state: !!result && !!result.state ? result.state : SdmGoalState.in_process,
phase: !!result && !!result.phase ? result.phase : "scheduled",
description: !!result && !!result.description ? result.description : descriptionFromState(goal, SdmGoalState.in_process, sdmGoal),
url: progressLog.url,
externalUrls: !!result ? result.externalUrls : undefined,
});
}
return {
...result as any,
// successfully handled event even if goal failed
code: 0,
};
} else {
delete (sdmGoal as any).id;
const listeners = [];
sdmGoal.uniqueName, sdmGoal.fulfillment.method, sdmGoal.fulfillment.name);
return Success;
} else if (sdmGoal.fulfillment.method === SdmGoalFulfillmentMethod.Other) {
// fail goal with neither Sdm nor SideEffect fulfillment
await updateGoal(
ctx,
sdmGoal,
{
state: SdmGoalState.failure,
description: `No fulfillment for ${sdmGoal.uniqueName}`,
});
return Success;
}
const id = this.configuration.sdm.repoRefResolver.repoRefFromSdmGoal(sdmGoal);
const credentials = await resolveCredentialsPromise(this.configuration.sdm.credentialsResolver.eventHandlerCredentials(ctx, id));
const addressChannels = addressChannelsFor(sdmGoal.push.repo, ctx);
const preferences = this.configuration.sdm.preferenceStoreFactory(ctx);
const implementation = this.implementationMapper.findImplementationBySdmGoal(sdmGoal);
const { goal } = implementation;
const progressLog = new WriteToAllProgressLog(
sdmGoal.name,
new LoggingProgressLog(sdmGoal.name, "debug"),
await this.configuration.sdm.logFactory(ctx, sdmGoal));
const goalInvocation: GoalInvocation = {
configuration: this.configuration,
sdmGoal,
goalEvent: sdmGoal,
goal,
return Success;
} else if (sdmGoal.fulfillment.method === SdmGoalFulfillmentMethod.Other) {
// fail goal with neither Sdm nor SideEffect fulfillment
await updateGoal(
ctx,
sdmGoal,
{
state: SdmGoalState.failure,
description: `No fulfillment for ${sdmGoal.uniqueName}`,
});
return Success;
}
const id = this.configuration.sdm.repoRefResolver.repoRefFromSdmGoal(sdmGoal);
const credentials = await resolveCredentialsPromise(this.configuration.sdm.credentialsResolver.eventHandlerCredentials(ctx, id));
const addressChannels = addressChannelsFor(sdmGoal.push.repo, ctx);
const preferences = this.configuration.sdm.preferenceStoreFactory(ctx);
const implementation = this.implementationMapper.findImplementationBySdmGoal(sdmGoal);
const { goal } = implementation;
const progressLog = new WriteToAllProgressLog(
sdmGoal.name,
new LoggingProgressLog(sdmGoal.name, "debug"),
await this.configuration.sdm.logFactory(ctx, sdmGoal));
const goalInvocation: GoalInvocation = {
configuration: this.configuration,
sdmGoal,
goalEvent: sdmGoal,
goal,
progressLog,
}, ...toArray(options.taggers) || []);
const aspects = [...toArray(options.aspects || []), ...scoringAspects, tagAspect]
.map(aspect => makeVirtualProjectAware(aspect, options.virtualProjectFinder));
// Default the two display methods with some sensible defaults
aspects.forEach(a => {
if (!a.toDisplayableFingerprint) {
a.toDisplayableFingerprint = fp => JSON.stringify(fp.data);
}
if (!a.toDisplayableFingerprintName) {
a.toDisplayableFingerprintName = fn => fn;
}
});
return {
...metadata(),
configure: sdm => {
const cfg = sdm.configuration;
const analysisTracking = new AnalysisTracker();
if (isInLocalMode()) {
// If we're in local mode, expose analyzer commands and
// HTTP endpoints
const analyzer = createAnalyzer(
aspects,
options.virtualProjectFinder || exports.DefaultVirtualProjectFinder);
sdm.addCommand(analyzeGitHubByQueryCommandRegistration(analyzer, analysisTracking));
sdm.addCommand(analyzeGitHubOrganizationCommandRegistration(analyzer, analysisTracking));
sdm.addCommand(analyzeLocalCommandRegistration(analyzer, analysisTracking));
} else {
// Add command to calculate fingerprints as part of the initial onboarding
public async clone(sourceData: GitHubSearchResult): Promise {
const project = await GitCommandGitProject.cloned(
process.env.GITHUB_TOKEN ? { token: process.env.GITHUB_TOKEN } : undefined,
GitHubRepoRef.from({
owner: sourceData.owner.login,
repo: sourceData.name,
rawApiBase: "https://api.github.com", // for GitHub Enterprise, make this something like github.yourcompany.com/api/v3
}), {
alwaysDeep: false,
noSingleBranch: true,
depth: 1,
},
this.directoryManager);
if (!project.id.sha) {
const sha = await execPromise("git", ["rev-parse", "HEAD"], {
cwd: (project as LocalProject).baseDir,
});
project.id.sha = sha.stdout.trim();
logger.debug(`Set sha to ${project.id.sha}`);
}
return project;
}