Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
descriptionFromState,
findSdmGoalOnCommit,
Goal,
RepoRefResolver,
SdmGoalEvent,
SdmGoalFulfillmentMethod,
SdmGoalState,
updateGoal,
} from "@atomist/sdm";
import { OnBuildComplete } from "../../../../typings/types";
/**
* Set build status on complete build
*/
// TODO CD move to sdm-pack-build
@EventHandler("Set build goal to successful on build complete, if it's side-effecting",
GraphQL.subscription("OnBuildComplete"))
export class SetGoalOnBuildComplete implements HandleEvent {
constructor(private readonly buildGoals: Goal[],
private readonly repoRefResolver: RepoRefResolver) {
}
public async handle(event: EventFired,
ctx: HandlerContext, params: this): Promise {
const build = event.data.Build[0];
const commit: OnBuildComplete.Commit = build.commit;
const id = params.repoRefResolver.toRemoteRepoRef(commit.repo, { sha: commit.sha });
for (const buildGoal of params.buildGoals) {
const sdmGoal = await findSdmGoalOnCommit(ctx, id, commit.repo.org.provider.providerId, buildGoal);
if (!sdmGoal) {
EnrichGoal,
GoalImplementationMapper,
GoalSetter,
GoalsSetListener,
PreferenceStoreFactory,
ProjectLoader,
RepoRefResolver,
resolveCredentialsPromise,
TagGoalSet,
} from "@atomist/sdm";
import { OnPushToAnyBranch } from "../../../../typings/types";
/**
* Set up goalSet on a push (e.g. for delivery).
*/
@EventHandler("Set up goalSet on Push", GraphQL.subscription("OnPushToAnyBranch"))
export class SetGoalsOnPush implements HandleEvent {
/**
* Configure goal setting
* @param projectLoader use to load projects
* @param repoRefResolver used to resolve repos from GraphQL return
* @param goalSetter
* @param goalsListeners listener to goals set
* @param implementationMapping
* @param credentialsFactory credentials factory
*/
constructor(private readonly projectLoader: ProjectLoader,
private readonly repoRefResolver: RepoRefResolver,
private readonly goalSetter: GoalSetter,
// public for tests only
public readonly goalsListeners: GoalsSetListener[],
Success,
Value,
} from "@atomist/automation-client";
import { EventHandler } from "@atomist/automation-client/lib/decorators";
import { HandleEvent } from "@atomist/automation-client/lib/HandleEvent";
import { ClusterWorkerRequestProcessor } from "@atomist/automation-client/lib/internal/transport/cluster/ClusterWorkerRequestProcessor";
import {
cancelableGoal,
SdmGoalEvent,
SoftwareDeliveryMachineConfiguration,
} from "@atomist/sdm";
import * as cluster from "cluster";
import { verifyGoal } from "../../../../internal/signing/goalSigning";
import { OnSpecificCanceledSdmGoal } from "../../../../typings/types";
@EventHandler("Cancel the currently executing goal",
() => GraphQL.subscription({
name: "OnSpecificCanceledSdmGoal",
variables: {
goalSetId: process.env.ATOMIST_GOAL_SET_ID || "n/a",
uniqueName: process.env.ATOMIST_GOAL_UNIQUE_NAME || "n/a",
},
}))
export class CancelGoalOnCanceled implements HandleEvent {
@Value("") // empty path returns the entire configuration
public configuration: SoftwareDeliveryMachineConfiguration;
public async handle(e: EventFired, ctx: HandlerContext): Promise {
const sdmGoal = e.data.SdmGoal[0] as SdmGoalEvent;
CredentialsResolver,
FingerprintDifference,
FingerprintDifferenceListener,
FingerprintDifferenceListenerInvocation,
FingerprintValue,
PreferenceStoreFactory,
RepoRefResolver,
resolveCredentialsPromise,
} from "@atomist/sdm";
import * as _ from "lodash";
import * as schema from "../../../../typings/types";
/**
* React to a PushImpact event to react to semantic diffs
*/
@EventHandler("Find semantic diffs from a PushImpact", GraphQL.subscription("OnPushImpact"))
export class ReactToSemanticDiffsOnPushImpact
implements HandleEvent {
@Value("")
public configuration: Configuration;
constructor(private readonly differenceListeners: FingerprintDifferenceListener[],
private readonly repoRefResolver: RepoRefResolver,
private readonly credentialsFactory: CredentialsResolver,
private readonly preferencesStoreFactory: PreferenceStoreFactory) {
}
public async handle(event: EventFired,
context: HandlerContext): Promise {
const pushImpact = event.data.PushImpact[0];
import {
AddressChannels,
addressChannelsFor,
CredentialsResolver,
PreferenceStoreFactory,
ProjectListener,
ProjectListenerInvocation,
RepoRefResolver,
resolveCredentialsPromise,
} from "@atomist/sdm";
import * as schema from "../../../typings/types";
/**
* A repo has been onboarded
*/
@EventHandler("On repo onboarding", GraphQL.subscription("OnRepoOnboarded"))
export class OnRepoOnboarded implements HandleEvent {
@Value("")
public configuration: Configuration;
constructor(private readonly actions: ProjectListener[],
private readonly repoRefResolver: RepoRefResolver,
private readonly credentialsFactory: CredentialsResolver,
private readonly preferenceStoreFactory: PreferenceStoreFactory) {
}
public async handle(event: EventFired,
context: HandlerContext): Promise {
const repoOnboarded = event.data.RepoOnboarded[0];
const id = this.repoRefResolver.toRemoteRepoRef(repoOnboarded.repo, {branch: repoOnboarded.repo.defaultBranch});
const credentials = await resolveCredentialsPromise(this.credentialsFactory.eventHandlerCredentials(context, id));
SdmGoalFulfillmentMethod,
SdmGoalKey,
SoftwareDeliveryMachineConfiguration,
updateGoal,
} from "@atomist/sdm";
import { isGoalRelevant } from "../../../../internal/delivery/goals/support/validateGoal";
import { verifyGoal } from "../../../../internal/signing/goalSigning";
import {
OnAnySuccessfulSdmGoal,
SdmGoalState,
} from "../../../../typings/types";
/**
* Move downstream goals from 'planned' to 'requested' when preconditions are met.
*/
@EventHandler("Move downstream goals from 'planned' to 'requested' when preconditions are met",
GraphQL.subscription("OnAnySuccessfulSdmGoal"))
export class RequestDownstreamGoalsOnGoalSuccess implements HandleEvent {
@Value("")
public configuration: SoftwareDeliveryMachineConfiguration;
constructor(private readonly name: string,
private readonly implementationMapper: GoalImplementationMapper,
private readonly repoRefResolver: RepoRefResolver,
private readonly credentialsResolver: CredentialsResolver,
private readonly preferenceStoreFactory: PreferenceStoreFactory) {
}
public async handle(event: EventFired,
context: HandlerContext): Promise {
const sdmGoal = event.data.SdmGoal[0] as SdmGoalEvent;
import { HandleEvent } from "@atomist/automation-client/lib/HandleEvent";
import {
addressChannelsFor,
ClosedIssueListener,
ClosedIssueListenerInvocation,
CredentialsResolver,
PreferenceStoreFactory,
RepoRefResolver,
resolveCredentialsPromise,
} from "@atomist/sdm";
import * as schema from "@atomist/sdm/lib/typings/types";
/**
* A new issue has been created.
*/
@EventHandler("On an issue being closed", GraphQL.subscription("OnClosedIssue"))
export class ClosedIssueHandler implements HandleEvent {
@Value("")
public configuration: Configuration;
private readonly closedIssueListeners: ClosedIssueListener[];
constructor(closedIssueListeners: ClosedIssueListener[],
private readonly repoRefResolver: RepoRefResolver,
private readonly credentialsFactory: CredentialsResolver,
private readonly preferenceStoreFactory: PreferenceStoreFactory) {
this.closedIssueListeners = closedIssueListeners;
}
public async handle(event: EventFired,
context: HandlerContext): Promise {
updateGoal,
} from "@atomist/sdm";
import { shouldHandle } from "../../../../internal/delivery/goals/support/validateGoal";
import { verifyGoal } from "../../../../internal/signing/goalSigning";
import { OnAnyApprovedSdmGoal } from "../../../../typings/types";
/**
* Vote on approved goals.
*
* This allows GoalApprovalVoter instances to vote on the approved goal to decide
* if this approval request can be granted or not.
*
* The final decision if the request should be granted based on all votes is delegated to the
* configured instance of GoalApprovalRequestVoteDecisionManager.
*/
@EventHandler("Vote on started or approved goals",
() => GraphQL.subscription({
name: "OnAnyApprovedSdmGoal",
variables: { registration: () => [automationClientInstance()?.configuration?.name] },
}))
export class VoteOnGoalApprovalRequest implements HandleEvent {
@Value("")
public configuration: SoftwareDeliveryMachineConfiguration;
constructor(private readonly repoRefResolver: RepoRefResolver,
private readonly credentialsFactory: CredentialsResolver,
private readonly voters: GoalApprovalRequestVoter[],
private readonly decisionManager: GoalApprovalRequestVoteDecisionManager,
private readonly implementationMapper: GoalImplementationMapper,
private readonly preferenceStoreFactory: PreferenceStoreFactory) {
if (this.voters.length === 0) {
GoalCompletionListenerInvocation,
PreferenceStoreFactory,
RepoRefResolver,
resolveCredentialsPromise,
SdmGoalEvent,
SoftwareDeliveryMachineConfiguration,
} from "@atomist/sdm";
import * as stringify from "json-stringify-safe";
import { shouldHandle } from "../../../../internal/delivery/goals/support/validateGoal";
import { verifyGoal } from "../../../../internal/signing/goalSigning";
import { OnAnyCompletedSdmGoal } from "../../../../typings/types";
/**
* Respond to a failure or success status by running listeners
*/
@EventHandler("Run a listener on goal failure or success",
() => GraphQL.subscription({
name: "OnAnyCompletedSdmGoal",
variables: { registration: () => [automationClientInstance()?.configuration?.name] },
}))
export class RespondOnGoalCompletion implements HandleEvent {
@Value("")
public configuration: SoftwareDeliveryMachineConfiguration;
constructor(private readonly repoRefResolver: RepoRefResolver,
private readonly credentialsFactory: CredentialsResolver,
private readonly goalCompletionListeners: GoalCompletionListener[],
private readonly preferenceStoreFactory: PreferenceStoreFactory) {
}
public async handle(event: EventFired,
fetchGoalsFromPush,
mapKeyToGoal,
SdmGoalEvent,
SdmGoalState,
SoftwareDeliveryMachineConfiguration,
updateGoal,
} from "@atomist/sdm";
import { SdmGoalKey } from "@atomist/sdm/lib/api/goal/SdmGoalMessage";
import { shouldHandle } from "../../../../internal/delivery/goals/support/validateGoal";
import { verifyGoal } from "../../../../internal/signing/goalSigning";
import { OnAnyFailedSdmGoal } from "../../../../typings/types";
/**
* Skip downstream goals on failed or stopped goal
*/
@EventHandler("Skip downstream goals on failed, stopped or canceled goal",
() => GraphQL.subscription({
name: "OnAnyFailedSdmGoal",
variables: { registration: () => [automationClientInstance()?.configuration?.name] },
}))
export class SkipDownstreamGoalsOnGoalFailure implements HandleEvent {
@Value("")
public configuration: SoftwareDeliveryMachineConfiguration;
public async handle(event: EventFired,
context: HandlerContext): Promise {
const failedGoal = event.data.SdmGoal[0] as SdmGoalEvent;
if (!shouldHandle(failedGoal)) {
logger.debug(`Goal ${failedGoal.uniqueName} skipped because not managed by this SDM`);
return Success;