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 fetchGoalsFromPush method to read goals from subscription #559

Merged
merged 3 commits into from
Oct 25, 2018
Merged
Show file tree
Hide file tree
Changes from 2 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
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));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is sdmGoal.push not typed?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is typed to a different type. Internally we are using subscription types but the API is using public SdmGoalEvent.

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
Loading