Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add typed Build goal to register Builder instances #506

Merged
merged 5 commits into from
Sep 3, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions src/api-helper/goal/executeBuild.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,17 @@ import {
GoalInvocation,
} from "../../api/goal/GoalInvocation";
import { Builder } from "../../spi/build/Builder";
import { ProjectLoader } from "../../spi/project/ProjectLoader";

/**
* Execute build with the appropriate builder
* @param projectLoader used to load projects
* @param builder builder to user
*/
export function executeBuild(projectLoader: ProjectLoader,
builder: Builder): ExecuteGoal {
export function executeBuild(builder: Builder): ExecuteGoal {
return async (goalInvocation: GoalInvocation): Promise<ExecuteGoalResult> => {
const { sdmGoal, credentials, id, context, progressLog, addressChannels } = goalInvocation;

logger.info("Building project %s:%s with builder [%s]", id.owner, id.repo, builder.name);
logger.info("Building project '%s/%s' with builder '%s'", id.owner, id.repo, builder.name);

// the builder is expected to result in a complete Build event (which will update the build status)
// and an ImageLinked event (which will update the artifact status).
Expand Down
6 changes: 3 additions & 3 deletions src/api-helper/machine/AbstractSoftwareDeliveryMachine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ import { AutofixRegistration } from "../../api/registration/AutofixRegistration"
import {
CodeInspection,
CodeInspectionRegistration,
InspectionResult,
CodeInspectionResult,
} from "../../api/registration/CodeInspectionRegistration";
import { CodeTransformOrTransforms } from "../../api/registration/CodeTransform";
import { CodeTransformRegistration } from "../../api/registration/CodeTransformRegistration";
Expand Down Expand Up @@ -305,7 +305,7 @@ function toCodeInspectionCommand<PARAMS>(
}

function defaultOnInspectionResults<PARAMS>(name: string) {
return async (results: Array<InspectionResult<InvarianceAssessment>>, ci: CommandListenerInvocation<PARAMS>) => {
return async (results: Array<CodeInspectionResult<InvarianceAssessment>>, ci: CommandListenerInvocation<PARAMS>) => {
const messages = results.map(r =>
// TODO cast will go with automation-client upgrade
`${(r.repoId as RemoteRepoRef).url}: Satisfies invariant _${name}_: \`${r.result.holds}\``);
Expand All @@ -314,7 +314,7 @@ function defaultOnInspectionResults<PARAMS>(name: string) {
}

/**
* Return a CodeInspection that runs a transform and sees whether or it made
* Return a AutoCodeInspection that runs a transform and sees whether or it made
* an edit
* @param {CodeTransformOrTransforms<PARAMS>} transform
* @return {CodeInspection<InvarianceAssessment, PARAMS>}
Expand Down
6 changes: 3 additions & 3 deletions src/api-helper/machine/handlerRegistrations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ import {
import { ProjectPredicate } from "../../api/mapping/PushTest";
import {
CodeInspectionRegistration,
InspectionResult,
CodeInspectionResult,
} from "../../api/registration/CodeInspectionRegistration";
import {
CodeTransform,
Expand Down Expand Up @@ -174,7 +174,7 @@ export function codeInspectionRegistrationToCommand<R>(sdm: MachineOrMachineOpti
`Code Inspection`,
`Invalid parameters to code inspection '${ci.commandName}': \n\n${vr.message}`, ci.context));
}
const action: (p: Project, params: any) => Promise<InspectionResult<R>> = async p => {
const action: (p: Project, params: any) => Promise<CodeInspectionResult<R>> = async p => {
if (!!cir.projectTest && !(await cir.projectTest(p))) {
return { repoId: p.id, result: undefined };
}
Expand All @@ -190,7 +190,7 @@ export function codeInspectionRegistrationToCommand<R>(sdm: MachineOrMachineOpti
(ci.parameters as RepoTargetingParameters).targets.credentials,
true,
ci.context);
const results = await doWithAllRepos<InspectionResult<R>, any>(
const results = await doWithAllRepos<CodeInspectionResult<R>, any>(
ci.context,
ci.credentials,
action,
Expand Down
32 changes: 28 additions & 4 deletions src/api/goal/GoalWithFulfillment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,36 @@ import { GoalFulfillmentCallback } from "./support/GoalImplementationMapper";

export type Fulfillment = Implementation | SideEffect;

export interface Implementation {
/**
* Register a goal implementation with required details
*/
export interface ImplementationRegistration {

/**
* Name of goal implementation
*/
name: string;
goalExecutor: ExecuteGoal;
logInterpreter: InterpretLog;
progressReporter?: ReportProgress;

/**
* Optional push test to identify the types of projects and pushes this implementation
* should get invoked on when the goal gets scheduled
*/
pushTest?: PushTest;

/**
* Optional log interpreter for this goal implementations log output
*/
logInterpreter?: InterpretLog;

/**
* Optional progress reporter for this goal implementation
*/
progressReporter?: ReportProgress;

}

export interface Implementation extends ImplementationRegistration {
goalExecutor: ExecuteGoal;
}

export function isImplementation(f: Fulfillment): f is Implementation {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import { FulfillableGoalWithRegistrationsAndListeners } from "../GoalWithFulfill
/**
* Goal that runs code inspections
*/
export class CodeInspects
export class AutoCodeInspection
extends FulfillableGoalWithRegistrationsAndListeners<CodeInspectionRegistration<any, any>, ReviewListenerRegistration> {

constructor(private readonly uniqueName: string) {
Expand Down
53 changes: 53 additions & 0 deletions src/api/goal/common/Build.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/*
* Copyright © 2018 Atomist, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import {
Builder,
BuildGoal,
ImplementationRegistration,
} from "../../..";
import { executeBuild } from "../../../api-helper/goal/executeBuild";
import { FulfillableGoalWithRegistrations } from "../GoalWithFulfillment";

/**
* Register a Builder for a certain type of push
*/
export interface BuilderRegistration extends ImplementationRegistration {
builder: Builder;
}

/**
* Goal that performs builds: For example using a Maven or NPM Builder implementation
*/
export class Build extends FulfillableGoalWithRegistrations<BuilderRegistration> {

constructor(private readonly uniqueName: string) {

super({
...BuildGoal.definition,
uniqueName,
orderedName: `2-${uniqueName.toLowerCase()}`,
});
}

public with(registration: BuilderRegistration): this {
this.addFulfillment({
goalExecutor: executeBuild(registration.builder),
...registration as ImplementationRegistration,
});
return this;
}
}
16 changes: 16 additions & 0 deletions src/api/machine/ConfigurationValues.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
/*
* Copyright © 2018 Atomist, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import * as _ from "lodash";

/**
Expand Down
10 changes: 5 additions & 5 deletions src/api/registration/CodeInspectionRegistration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export type CodeInspection<R, P = NoParameters> = (p: Project,
/**
* Result of inspecting a single project
*/
export interface InspectionResult<R> {
export interface CodeInspectionResult<R> {

repoId: RepoRef;

Expand All @@ -45,7 +45,7 @@ export interface InspectionResult<R> {
/**
* Actions added by inspections. For internal use.
*/
export interface InspectionActions<R, PARAMS> {
export interface CodeInspectionActions<R, PARAMS> {

/**
* Inspection function to run on each project
Expand All @@ -58,15 +58,15 @@ export interface InspectionActions<R, PARAMS> {
* @param ci context
* @return {Promise<any>}
*/
onInspectionResults?(results: Array<InspectionResult<R>>, ci: CommandListenerInvocation<PARAMS>): Promise<any>;
onInspectionResults?(results: Array<CodeInspectionResult<R>>, ci: CommandListenerInvocation<PARAMS>): Promise<any>;
}

/**
* Register a CodeInspection that can run against any number of projects.
* Register a AutoCodeInspection that can run against any number of projects.
* Include an optional react method that can react to review results.
*/
export interface CodeInspectionRegistration<R, PARAMS = NoParameters>
extends ProjectsOperationRegistration<PARAMS>,
InspectionActions<R, PARAMS> {
CodeInspectionActions<R, PARAMS> {

}
9 changes: 4 additions & 5 deletions src/api/registration/ProjectInvariantRegistration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ import {
} from "../project/exports";
import { AutofixRegistration } from "./AutofixRegistration";
import {
CodeInspectionActions,
CodeInspectionRegistration,
InspectionActions,
} from "./CodeInspectionRegistration";
import { CodeTransformRegistration } from "./CodeTransformRegistration";

Expand All @@ -37,12 +37,11 @@ export interface ProjectInvariantRegistration<PARAMS = NoParameters>
/**
* An invariant that can be enforced via an autofix.
* Based around a CodeTransform which can be used as a command or an autofix.
* If the CodeInspection isn't specified,
* a CodeInspection will be created based on running the transform and seeing if
* it makes changes.
* If the CodeInspection isn't specified, a CodeInspection will be created
* based on running the transform and seeing if it makes changes.
*/
export interface EnforceableProjectInvariantRegistration<PARAMS = NoParameters>
extends Partial<InspectionActions<InvarianceAssessment, PARAMS>>,
extends Partial<CodeInspectionActions<InvarianceAssessment, PARAMS>>,
CodeTransformRegistration<PARAMS>,
AutofixRegistration<PARAMS> {

Expand Down
4 changes: 3 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ export * from "./api/goal/Goals";
export * from "./api/goal/SdmGoalEvent";
export * from "./api/goal/SdmGoalMessage";
export * from "./api/goal/common/Autofix";
export * from "./api/goal/common/CodeInspects";
export * from "./api/goal/common/Build";
export * from "./api/goal/common/AutoCodeInspection";
export * from "./api/goal/common/Fingerprint";
export * from "./api/goal/common/GenericGoal";
export * from "./api/goal/common/MessageGoal";
Expand Down Expand Up @@ -59,6 +60,7 @@ export * from "./api/listener/TagListener";
export * from "./api/listener/UpdatedIssueListener";
export * from "./api/listener/UserJoiningChannelListener";
export * from "./api/listener/VerifiedDeploymentListener";
export * from "./api/machine/ConfigurationValues";
export * from "./api/machine/ExtensionPack";
export * from "./api/machine/FunctionalUnit";
export * from "./api/machine/GoalDrivenMachine";
Expand Down