Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
import { fetchGoalsForCommit } from "../../../../internal/delivery/goals/support/fetchGoalsOnCommit";
import { isGoalRelevant } from "../../../../internal/delivery/goals/support/validateGoal";
import { RepoRefResolver } from "../../../../spi/repo-ref/RepoRefResolver";
import {
OnAnySuccessfulSdmGoal,
ScmProvider,
} from "../../../../typings/types";
/**
* Respond to a failure status by failing downstream goals
*/
@EventHandler("Move downstream goals from 'planned' to 'success' when preconditions are met",
subscription("OnAnySuccessfulSdmGoal"))
export class RequestDownstreamGoalsOnGoalSuccess implements HandleEvent {
@Value("token")
public githubToken: string;
constructor(private readonly implementationMapper: SdmGoalImplementationMapper,
private readonly repoRefResolver: RepoRefResolver) { }
// #98: GitHub Status->SdmGoal: I believe all the goal state updates in this SDM
// are now happening on the SdmGoal. This subscription can change to be on SdmGoal state.
public async handle(event: EventFired,
context: HandlerContext,
params: this): Promise {
const sdmGoal = event.data.SdmGoal[0] as SdmGoal;
if (!isGoalRelevant(sdmGoal)) {
logger.debug(`Goal ${sdmGoal.name} skipped because not relevant for this SDM`);
return Success;
}
import {
fetchBranchTips,
fetchPushForCommit,
tipOfBranch,
} from "../../util/graph/queryCommits";
@Parameters()
export class ResetGoalsParameters {
@MappedParameter(MappedParameters.GitHubRepositoryProvider)
public providerId: string;
@Value("name")
public name: string;
@Value("version")
public version: string;
}
export function resetGoalsCommand(
sdm: SoftwareDeliveryMachine,
repoTargets: Maker = GitHubRepoTargets,
): CommandHandlerRegistration {
return {
name: "ResetGoalsOnCommit",
description: "Plan goals on a commit",
paramsMaker: toRepoTargetingParametersMaker(ResetGoalsParameters, repoTargets),
listener: resetGoalsOnCommit(sdm),
intent: [
`reset goals ${sdm.configuration.name.replace("@", "")}`,
@Parameter({ required: false, displayable: false })
public msgId?: string;
@MappedParameter(MappedParameters.GitHubOwner)
public owner: string;
@MappedParameter(MappedParameters.GitHubRepository)
public repo: string;
@MappedParameter(MappedParameters.GitHubRepositoryProvider)
public providerId: string;
@Value("name")
public name: string;
@Value("version")
public version: string;
}
/**
* Command to set deploy enablement on the currently mapped repo
* @param {CommandListenerInvocation} cli
* @param {boolean} enable
* @returns {Promise}
*/
export function setDeployEnablement(cli: CommandListenerInvocation,
enable: boolean): Promise {
const deployEnablement: SdmDeployEnablement = {
state: enable ? "requested" : "disabled",
owner: cli.parameters.owner,
repo: cli.parameters.repo,
providerId: cli.parameters.providerId,
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({
name: "OnAnySuccessfulSdmGoal",
variables: { registration: () => [automationClientInstance()?.configuration?.name] },
}))
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;
if (!shouldHandle(sdmGoal)) {
logger.debug(`Goal ${sdmGoal.uniqueName} skipped because not managed by this SDM`);
return Success;
CredentialsResolver,
PreferenceStoreFactory,
RepoRefResolver,
resolveCredentialsPromise,
UpdatedIssueListener,
UpdatedIssueListenerInvocation,
} from "@atomist/sdm";
import * as schema from "@atomist/sdm/lib/typings/types";
/**
* An issue has been updated
*/
@EventHandler("On issue update", GraphQL.subscription("OnIssueAction"))
export class UpdatedIssueHandler implements HandleEvent {
@Value("")
public configuration: Configuration;
private readonly updatedIssueListeners: UpdatedIssueListener[];
constructor(updatedIssueListeners: UpdatedIssueListener[],
private readonly repoRefResolver: RepoRefResolver,
private readonly credentialsFactory: CredentialsResolver,
private readonly preferenceStoreFactory: PreferenceStoreFactory) {
this.updatedIssueListeners = updatedIssueListeners;
}
public async handle(event: EventFired,
context: HandlerContext): Promise {
const issue = event.data.Issue[0];
const addressChannels = addressChannelsFor(issue.repo, context);
const id = this.repoRefResolver.toRemoteRepoRef(issue.repo, {});
ChannelLinkListenerInvocation,
CredentialsResolver,
PreferenceStoreFactory,
ProjectLoader,
RepoRefResolver,
resolveCredentialsPromise,
} from "@atomist/sdm";
import * as schema from "../../../typings/types";
/**
* A new channel has been linked to a repo
*/
@EventHandler("On channel link", GraphQL.subscription("OnChannelLink"))
export class OnChannelLink implements HandleEvent {
@Value("")
public configuration: Configuration;
constructor(
private readonly projectLoader: ProjectLoader,
private readonly repoRefResolver: RepoRefResolver,
private readonly listeners: ChannelLinkListener[],
private readonly credentialsFactory: CredentialsResolver,
private readonly preferenceStoreFactory: PreferenceStoreFactory) {
}
public async handle(event: EventFired,
context: HandlerContext): Promise {
const repo = event.data.ChannelLink[0].repo;
const id = this.repoRefResolver.toRemoteRepoRef(
repo,
{
@Parameters()
export class SetDeployEnablementParameters {
@Parameter({ required: false, displayable: false })
public msgId?: string;
@MappedParameter(MappedParameters.GitHubOwner)
public owner: string;
@MappedParameter(MappedParameters.GitHubRepository)
public repo: string;
@MappedParameter(MappedParameters.GitHubRepositoryProvider)
public providerId: string;
@Value("name")
public name: string;
@Value("version")
public version: string;
}
/**
* Command to set deploy enablement on the currently mapped repo
* @param {CommandListenerInvocation} cli
* @param {boolean} enable
* @returns {Promise}
*/
export function setDeployEnablement(cli: CommandListenerInvocation,
enable: boolean): Promise {
const deployEnablement: SdmDeployEnablement = {
state: enable ? "requested" : "disabled",
codeLine,
italic,
} from "@atomist/slack-messages";
import {
fetchBranchTips,
fetchPushForCommit,
tipOfBranch,
} from "../../util/graph/queryCommits";
@Parameters()
export class ResetGoalsParameters {
@MappedParameter(MappedParameters.GitHubRepositoryProvider)
public providerId: string;
@Value("name")
public name: string;
@Value("version")
public version: string;
}
export function resetGoalsCommand(
sdm: SoftwareDeliveryMachine,
repoTargets: Maker = GitHubRepoTargets,
): CommandHandlerRegistration {
return {
name: "ResetGoalsOnCommit",
description: "Plan goals on a commit",
paramsMaker: toRepoTargetingParametersMaker(ResetGoalsParameters, repoTargets),
CredentialsResolver,
NewIssueListener,
NewIssueListenerInvocation,
PreferenceStoreFactory,
RepoRefResolver,
resolveCredentialsPromise,
} from "@atomist/sdm";
import * as schema from "@atomist/sdm/lib/typings/types";
/**
* A new issue has been created.
*/
@EventHandler("On issue creation", GraphQL.subscription("OnIssueAction"))
export class NewIssueHandler implements HandleEvent {
@Value("")
public configuration: Configuration;
private readonly newIssueListeners: NewIssueListener[];
constructor(newIssueListeners: NewIssueListener[],
private readonly repoRefResolver: RepoRefResolver,
private readonly credentialsFactory: CredentialsResolver,
private readonly preferenceStoreFactory: PreferenceStoreFactory) {
this.newIssueListeners = newIssueListeners;
}
public async handle(event: EventFired,
context: HandlerContext): Promise {
const issue = event.data.Issue[0];
const addressChannels = addressChannelsFor(issue.repo, context);
const id = this.repoRefResolver.toRemoteRepoRef(issue.repo, {});
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));
const addressChannels: AddressChannels = addressChannelsFor(repoOnboarded.repo, context);
const preferences = this.preferenceStoreFactory(context);