Skip to content

Commit

Permalink
Add fetchGoalsFromPush method to read goals from subscription
Browse files Browse the repository at this point in the history
  • Loading branch information
cdupuis committed Oct 25, 2018
1 parent 0b2867c commit 638e44f
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions lib/api-helper/goal/fetchGoalsOnCommit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,14 @@ import {
import { goalKeyString } from "./sdmGoal";
import { goalCorrespondsToSdmGoal } from "./storeGoals";

export function fetchGoalsFromPush(sdmGoal: SdmGoalEvent): SdmGoalEvent[] {
const goals = sumSdmGoalEvents((sdmGoal.push as any).goals.filter(g => g.goalSetId === sdmGoal.goalSetId));
const push = _.cloneDeep(sdmGoal.push);
delete (push as any).goals;
goals.forEach(g => g.push = push);
return goals;
}

export async function findSdmGoalOnCommit(ctx: HandlerContext, id: RemoteRepoRef, providerId: string, goal: Goal): Promise<SdmGoalEvent> {
const sdmGoals = await fetchGoalsForCommit(ctx, id, providerId);
const matches = sdmGoals.filter(g => goalCorrespondsToSdmGoal(goal, g));
Expand Down

0 comments on commit 638e44f

Please sign in to comment.