From 90ca60047c0af46e8e8e8a95344d93f55c00df68 Mon Sep 17 00:00:00 2001 From: Christian Dupuis Date: Mon, 3 Sep 2018 09:19:32 +0200 Subject: [PATCH 1/5] Add typed Build goal --- src/api-helper/goal/executeBuild.ts | 6 +-- src/api/goal/GoalWithFulfillment.ts | 32 +++++++++-- src/api/goal/common/Build.ts | 53 +++++++++++++++++++ .../{CodeInspects.ts => CodeInspection.ts} | 2 +- src/index.ts | 4 +- 5 files changed, 87 insertions(+), 10 deletions(-) create mode 100644 src/api/goal/common/Build.ts rename src/api/goal/common/{CodeInspects.ts => CodeInspection.ts} (98%) diff --git a/src/api-helper/goal/executeBuild.ts b/src/api-helper/goal/executeBuild.ts index 4d835952c..e2d25ed5c 100644 --- a/src/api-helper/goal/executeBuild.ts +++ b/src/api-helper/goal/executeBuild.ts @@ -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 => { 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). diff --git a/src/api/goal/GoalWithFulfillment.ts b/src/api/goal/GoalWithFulfillment.ts index 313039a9c..fd1a9315b 100644 --- a/src/api/goal/GoalWithFulfillment.ts +++ b/src/api/goal/GoalWithFulfillment.ts @@ -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 { diff --git a/src/api/goal/common/Build.ts b/src/api/goal/common/Build.ts new file mode 100644 index 000000000..a86a177a3 --- /dev/null +++ b/src/api/goal/common/Build.ts @@ -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 { + + 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; + } +} diff --git a/src/api/goal/common/CodeInspects.ts b/src/api/goal/common/CodeInspection.ts similarity index 98% rename from src/api/goal/common/CodeInspects.ts rename to src/api/goal/common/CodeInspection.ts index 83a17e06e..3ba890d9b 100644 --- a/src/api/goal/common/CodeInspects.ts +++ b/src/api/goal/common/CodeInspection.ts @@ -23,7 +23,7 @@ import { FulfillableGoalWithRegistrationsAndListeners } from "../GoalWithFulfill /** * Goal that runs code inspections */ -export class CodeInspects +export class CodeInspection extends FulfillableGoalWithRegistrationsAndListeners, ReviewListenerRegistration> { constructor(private readonly uniqueName: string) { diff --git a/src/index.ts b/src/index.ts index 9a61eb2a3..94d4610a5 100644 --- a/src/index.ts +++ b/src/index.ts @@ -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/CodeInspection"; export * from "./api/goal/common/Fingerprint"; export * from "./api/goal/common/GenericGoal"; export * from "./api/goal/common/MessageGoal"; @@ -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"; From 9e7659db7a7195114842178f42058ea32ded6631 Mon Sep 17 00:00:00 2001 From: Atomist Bot Date: Mon, 3 Sep 2018 07:19:59 +0000 Subject: [PATCH 2/5] Autofix: TypeScript header [atomist:generated] [atomist:autofix=TypeScript header] --- src/api/machine/ConfigurationValues.ts | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/api/machine/ConfigurationValues.ts b/src/api/machine/ConfigurationValues.ts index ac3072b6d..3662f0d81 100644 --- a/src/api/machine/ConfigurationValues.ts +++ b/src/api/machine/ConfigurationValues.ts @@ -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"; /** From 4d2f0e354dd64cc4c28b3087284624b8e27a70e0 Mon Sep 17 00:00:00 2001 From: Atomist Bot Date: Mon, 3 Sep 2018 07:20:24 +0000 Subject: [PATCH 3/5] Autofix: tslint [atomist:generated] [atomist:autofix=tslint] --- src/api/goal/common/Build.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/api/goal/common/Build.ts b/src/api/goal/common/Build.ts index a86a177a3..6d6826b25 100644 --- a/src/api/goal/common/Build.ts +++ b/src/api/goal/common/Build.ts @@ -46,7 +46,7 @@ export class Build extends FulfillableGoalWithRegistrations public with(registration: BuilderRegistration): this { this.addFulfillment({ goalExecutor: executeBuild(registration.builder), - ...registration as ImplementationRegistration, + ...registration as ImplementationRegistration, }); return this; } From 98149f555ea85173ce38f60262fcd14bba62ff8e Mon Sep 17 00:00:00 2001 From: Christian Dupuis Date: Mon, 3 Sep 2018 09:38:07 +0200 Subject: [PATCH 4/5] Fix name conflict --- .../machine/AbstractSoftwareDeliveryMachine.ts | 6 +++--- src/api-helper/machine/handlerRegistrations.ts | 6 +++--- .../{CodeInspection.ts => AutoCodeInspection.ts} | 2 +- src/api/registration/CodeInspectionRegistration.ts | 10 +++++----- src/api/registration/ProjectInvariantRegistration.ts | 9 ++++----- src/index.ts | 2 +- 6 files changed, 17 insertions(+), 18 deletions(-) rename src/api/goal/common/{CodeInspection.ts => AutoCodeInspection.ts} (98%) diff --git a/src/api-helper/machine/AbstractSoftwareDeliveryMachine.ts b/src/api-helper/machine/AbstractSoftwareDeliveryMachine.ts index a1383031b..568b410b6 100644 --- a/src/api-helper/machine/AbstractSoftwareDeliveryMachine.ts +++ b/src/api-helper/machine/AbstractSoftwareDeliveryMachine.ts @@ -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"; @@ -305,7 +305,7 @@ function toCodeInspectionCommand( } function defaultOnInspectionResults(name: string) { - return async (results: Array>, ci: CommandListenerInvocation) => { + return async (results: Array>, ci: CommandListenerInvocation) => { const messages = results.map(r => // TODO cast will go with automation-client upgrade `${(r.repoId as RemoteRepoRef).url}: Satisfies invariant _${name}_: \`${r.result.holds}\``); @@ -314,7 +314,7 @@ function defaultOnInspectionResults(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} transform * @return {CodeInspection} diff --git a/src/api-helper/machine/handlerRegistrations.ts b/src/api-helper/machine/handlerRegistrations.ts index 22d0acaf8..51eaf9324 100644 --- a/src/api-helper/machine/handlerRegistrations.ts +++ b/src/api-helper/machine/handlerRegistrations.ts @@ -64,7 +64,7 @@ import { import { ProjectPredicate } from "../../api/mapping/PushTest"; import { CodeInspectionRegistration, - InspectionResult, + CodeInspectionResult, } from "../../api/registration/CodeInspectionRegistration"; import { CodeTransform, @@ -174,7 +174,7 @@ export function codeInspectionRegistrationToCommand(sdm: MachineOrMachineOpti `Code Inspection`, `Invalid parameters to code inspection '${ci.commandName}': \n\n${vr.message}`, ci.context)); } - const action: (p: Project, params: any) => Promise> = async p => { + const action: (p: Project, params: any) => Promise> = async p => { if (!!cir.projectTest && !(await cir.projectTest(p))) { return { repoId: p.id, result: undefined }; } @@ -190,7 +190,7 @@ export function codeInspectionRegistrationToCommand(sdm: MachineOrMachineOpti (ci.parameters as RepoTargetingParameters).targets.credentials, true, ci.context); - const results = await doWithAllRepos, any>( + const results = await doWithAllRepos, any>( ci.context, ci.credentials, action, diff --git a/src/api/goal/common/CodeInspection.ts b/src/api/goal/common/AutoCodeInspection.ts similarity index 98% rename from src/api/goal/common/CodeInspection.ts rename to src/api/goal/common/AutoCodeInspection.ts index 3ba890d9b..54d2f30a4 100644 --- a/src/api/goal/common/CodeInspection.ts +++ b/src/api/goal/common/AutoCodeInspection.ts @@ -23,7 +23,7 @@ import { FulfillableGoalWithRegistrationsAndListeners } from "../GoalWithFulfill /** * Goal that runs code inspections */ -export class CodeInspection +export class AutoCodeInspection extends FulfillableGoalWithRegistrationsAndListeners, ReviewListenerRegistration> { constructor(private readonly uniqueName: string) { diff --git a/src/api/registration/CodeInspectionRegistration.ts b/src/api/registration/CodeInspectionRegistration.ts index 25bd2b771..216dbd326 100644 --- a/src/api/registration/CodeInspectionRegistration.ts +++ b/src/api/registration/CodeInspectionRegistration.ts @@ -31,7 +31,7 @@ export type CodeInspection = (p: Project, /** * Result of inspecting a single project */ -export interface InspectionResult { +export interface CodeInspectionResult { repoId: RepoRef; @@ -45,7 +45,7 @@ export interface InspectionResult { /** * Actions added by inspections. For internal use. */ -export interface InspectionActions { +export interface CodeInspectionActions { /** * Inspection function to run on each project @@ -58,15 +58,15 @@ export interface InspectionActions { * @param ci context * @return {Promise} */ - onInspectionResults?(results: Array>, ci: CommandListenerInvocation): Promise; + onInspectionResults?(results: Array>, ci: CommandListenerInvocation): Promise; } /** - * 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 extends ProjectsOperationRegistration, - InspectionActions { + CodeInspectionActions { } diff --git a/src/api/registration/ProjectInvariantRegistration.ts b/src/api/registration/ProjectInvariantRegistration.ts index ac72f8f57..31bc7eb9d 100644 --- a/src/api/registration/ProjectInvariantRegistration.ts +++ b/src/api/registration/ProjectInvariantRegistration.ts @@ -22,7 +22,7 @@ import { import { AutofixRegistration } from "./AutofixRegistration"; import { CodeInspectionRegistration, - InspectionActions, + CodeInspectionActions, } from "./CodeInspectionRegistration"; import { CodeTransformRegistration } from "./CodeTransformRegistration"; @@ -37,12 +37,11 @@ export interface ProjectInvariantRegistration /** * 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 - extends Partial>, + extends Partial>, CodeTransformRegistration, AutofixRegistration { diff --git a/src/index.ts b/src/index.ts index 94d4610a5..6b3f0b34f 100644 --- a/src/index.ts +++ b/src/index.ts @@ -25,7 +25,7 @@ export * from "./api/goal/SdmGoalEvent"; export * from "./api/goal/SdmGoalMessage"; export * from "./api/goal/common/Autofix"; export * from "./api/goal/common/Build"; -export * from "./api/goal/common/CodeInspection"; +export * from "./api/goal/common/AutoCodeInspection"; export * from "./api/goal/common/Fingerprint"; export * from "./api/goal/common/GenericGoal"; export * from "./api/goal/common/MessageGoal"; From 3654a92ddcccd6894ecef6a832ee15681b04107b Mon Sep 17 00:00:00 2001 From: Atomist Bot Date: Mon, 3 Sep 2018 07:38:56 +0000 Subject: [PATCH 5/5] Autofix: tslint [atomist:generated] [atomist:autofix=tslint] --- src/api/registration/ProjectInvariantRegistration.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/api/registration/ProjectInvariantRegistration.ts b/src/api/registration/ProjectInvariantRegistration.ts index 31bc7eb9d..9a69e000f 100644 --- a/src/api/registration/ProjectInvariantRegistration.ts +++ b/src/api/registration/ProjectInvariantRegistration.ts @@ -21,8 +21,8 @@ import { } from "../project/exports"; import { AutofixRegistration } from "./AutofixRegistration"; import { - CodeInspectionRegistration, CodeInspectionActions, + CodeInspectionRegistration, } from "./CodeInspectionRegistration"; import { CodeTransformRegistration } from "./CodeTransformRegistration";