Skip to content

Commit

Permalink
Allow to set description from a ExecuteGoal
Browse files Browse the repository at this point in the history
[changelog:added]
  • Loading branch information
cdupuis committed Aug 30, 2018
1 parent 2feb033 commit 1d18bf9
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 16 deletions.
40 changes: 24 additions & 16 deletions src/api-helper/goal/executeGoal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -233,46 +233,54 @@ export async function executeHook(rules: { projectLoader: ProjectLoader },
});
}

function goalToHookFile(sdmGoal: SdmGoalEvent, prefix: string): string {
function goalToHookFile(sdmGoal: SdmGoalEvent,
prefix: string): string {
return `${prefix}-${sdmGoal.environment.toLocaleLowerCase().slice(2)}-${
sdmGoal.name.toLocaleLowerCase().replace(" ", "_")}`;
}

export function markStatus(parameters: {
context: HandlerContext, sdmGoal: SdmGoalEvent, goal: Goal, result: ExecuteGoalResult,
error?: Error, progressLogUrl: string,
}) {
context: HandlerContext,
sdmGoal: SdmGoalEvent,
goal: Goal,
result: ExecuteGoalResult,
error?: Error,
progressLogUrl: string}) {
const { context, sdmGoal, goal, result, error, progressLogUrl } = parameters;
const newState = result.code !== 0 ? SdmGoalState.failure :
result.requireApproval ? SdmGoalState.waiting_for_approval : SdmGoalState.success;

return updateGoal(context, sdmGoal,
return updateGoal(
context,
sdmGoal,
{
url: progressLogUrl,
externalUrl: result.targetUrl,
state: newState,
phase: sdmGoal.phase,
description: descriptionFromState(goal, newState),
description: result.description ? result.description : descriptionFromState(goal, newState),
error,
});
}

async function markGoalInProcess(parameters: {
ctx: HandlerContext,
sdmGoal: SdmGoalEvent,
goal: Goal,
progressLogUrl: string,
}): Promise<SdmGoalEvent> {
ctx: HandlerContext,
sdmGoal: SdmGoalEvent,
goal: Goal,
progressLogUrl: string,
}): Promise<SdmGoalEvent> {
const { ctx, sdmGoal, goal, progressLogUrl } = parameters;
sdmGoal.state = SdmGoalState.in_process;
sdmGoal.description = goal.inProcessDescription;
sdmGoal.url = progressLogUrl;
try {
await updateGoal(ctx, sdmGoal, {
url: progressLogUrl,
description: goal.inProcessDescription,
state: SdmGoalState.in_process,
});
await updateGoal(ctx,
sdmGoal,
{
url: progressLogUrl,
description: goal.inProcessDescription,
state: SdmGoalState.in_process,
});
} catch (err) {
logger.warn("Failed to update %s goal to tell people we are working on it: \n%s", goal.name, err.stack);
}
Expand Down
16 changes: 16 additions & 0 deletions src/api/goal/ExecuteGoalResult.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,23 @@

import { HandlerResult } from "@atomist/automation-client";

/**
* Result from goal execution
*/
export interface ExecuteGoalResult extends HandlerResult {

/**
* Optional description to be set on the goal
*/
description?: string;

/**
* Optional targetUrl to be set on the goal as externalUrl
*/
targetUrl?: string;

/**
* Optional flag to indicate if this goal requires approval now
*/
requireApproval?: boolean;
}

0 comments on commit 1d18bf9

Please sign in to comment.