Skip to content
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
104 changes: 0 additions & 104 deletions web-server/pages/api/internal/[org_id]/filters-api.ts

This file was deleted.

60 changes: 30 additions & 30 deletions web-server/pages/api/internal/team/[team_id]/dora_metrics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,25 @@ import * as yup from 'yup';
import { getTeamRepos } from '@/api/resources/team_repos';
import { getUnsyncedRepos } from '@/api/resources/teams/[team_id]/unsynced_repos';
import { Endpoint } from '@/api-helpers/global';
import {
repoFiltersFromTeamProdBranches,
updatePrFilterParams,
workFlowFiltersFromTeamProdBranches
} from '@/api-helpers/team';
import { updatePrFilterParams } from '@/api-helpers/team';
import { mockDoraMetrics } from '@/mocks/dora_metrics';
import { TeamDoraMetricsApiResponseType } from '@/types/resources';
import {
ActiveBranchMode,
TeamDoraMetricsApiResponseType
} from '@/types/resources';
import {
fetchLeadTimeStats,
fetchChangeFailureRateStats,
fetchMeanTimeToRestoreStats,
fetchDeploymentFrequencyStats
} from '@/utils/cockpitMetricUtils';
import { isoDateString, getAggregateAndTrendsIntervalTime } from '@/utils/date';
import {
getBranchesAndRepoFilter,
getWorkFlowFiltersAsPayloadForSingleTeam
} from '@/utils/filterUtils';

import { getTeamLeadTimePRs } from './insights';
import { getAllTeamsReposProdBranchesForOrgAsMap } from './repo_branches';

const pathSchema = yup.object().shape({
team_id: yup.string().uuid().required()
Expand All @@ -31,7 +33,7 @@ const getSchema = yup.object().shape({
branches: yup.string().optional().nullable(),
from_date: yup.date().required(),
to_date: yup.date().required(),
repo_filters: yup.mixed().optional().nullable()
branch_mode: yup.string().oneOf(Object.values(ActiveBranchMode)).required()
});

const endpoint = new Endpoint(pathSchema);
Expand All @@ -46,33 +48,31 @@ endpoint.handle.GET(getSchema, async (req, res) => {
team_id: teamId,
from_date: rawFromDate,
to_date: rawToDate,
branches
branches,
branch_mode
} = req.payload;

const [teamProdBranchesMap, unsyncedRepos] = await Promise.all([
getAllTeamsReposProdBranchesForOrgAsMap(org_id),
getUnsyncedRepos(teamId)
]);
const teamRepoFiltersMap =
repoFiltersFromTeamProdBranches(teamProdBranchesMap);

const from_date = isoDateString(startOfDay(new Date(rawFromDate)));
const to_date = isoDateString(endOfDay(new Date(rawToDate)));

const [prFilters, workflowFilters] = await Promise.all([
updatePrFilterParams(
const [branchAndRepoFilters, unsyncedRepos] = await Promise.all([
getBranchesAndRepoFilter({
orgId: org_id,
teamId,
{},
{
branches: branches,
repo_filters: !branches ? teamRepoFiltersMap[teamId] : null
}
).then(({ pr_filter }) => ({
pr_filter
})),
Object.fromEntries(
Object.entries(workFlowFiltersFromTeamProdBranches(teamProdBranchesMap))
)[teamId]
branchMode: branch_mode as ActiveBranchMode,
branches
}),
getUnsyncedRepos(teamId)
]);
const [prFilters, workflowFilters] = await Promise.all([
updatePrFilterParams(teamId, {}, branchAndRepoFilters).then(
({ pr_filter }) => ({
pr_filter
})
),
getWorkFlowFiltersAsPayloadForSingleTeam({
orgId: org_id,
teamId: teamId
})
]);

const {
Expand Down
31 changes: 15 additions & 16 deletions web-server/pages/api/internal/team/[team_id]/get_incidents.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,17 @@ import { endOfDay, startOfDay } from 'date-fns';
import { isNil, reject } from 'ramda';
import * as yup from 'yup';

import { getAllTeamsReposProdBranchesForOrgAsMap } from '@/api/internal/team/[team_id]/repo_branches';
import { handleRequest } from '@/api-helpers/axios';
import { Endpoint } from '@/api-helpers/global';
import {
updatePrFilterParams,
repoFiltersFromTeamProdBranches
} from '@/api-helpers/team';
import { updatePrFilterParams } from '@/api-helpers/team';
import { mockDeploymentsWithIncidents } from '@/mocks/incidents';
import {
DeploymentWithIncidents,
IncidentApiResponseType
IncidentApiResponseType,
ActiveBranchMode
} from '@/types/resources';
import { getWeekStartAndEndInterval } from '@/utils/date';
import { getBranchesAndRepoFilter } from '@/utils/filterUtils';

const pathSchema = yup.object().shape({
team_id: yup.string().uuid().required()
Expand All @@ -25,7 +23,8 @@ const getSchema = yup.object().shape({
to_date: yup.date().required(),
branches: yup.string().optional().nullable(),
repo_filters: yup.mixed().optional().nullable(),
org_id: yup.string().uuid().required()
org_id: yup.string().uuid().required(),
branch_mode: yup.string().oneOf(Object.values(ActiveBranchMode)).required()
});

const endpoint = new Endpoint(pathSchema);
Expand All @@ -39,22 +38,22 @@ endpoint.handle.GET(getSchema, async (req, res) => {
from_date: rawFromDate,
to_date: rawToDate,
branches,
org_id
org_id,
branch_mode
} = req.payload;
const from_date = startOfDay(new Date(rawFromDate));
const to_date = endOfDay(new Date(rawToDate));

const teamProdBranchesMap =
await getAllTeamsReposProdBranchesForOrgAsMap(org_id);
const teamRepoFiltersMap =
repoFiltersFromTeamProdBranches(teamProdBranchesMap);
const branchAndRepoFilters = await getBranchesAndRepoFilter({
orgId: org_id,
teamId: team_id,
branchMode: branch_mode as ActiveBranchMode,
branches
});
const prFilter = await updatePrFilterParams(
team_id,
{},
{
branches: branches,
repo_filters: !branches ? teamRepoFiltersMap[team_id] : null
}
branchAndRepoFilters
).then(({ pr_filter }) => ({
pr_filter
}));
Expand Down
83 changes: 36 additions & 47 deletions web-server/pages/api/internal/team/[team_id]/insights.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { endOfDay, startOfDay } from 'date-fns';
import * as yup from 'yup';

import { handleRequest } from '@/api-helpers/axios';
import { Endpoint } from '@/api-helpers/global';
import {
batchPaginatedRequest,
Expand All @@ -10,11 +11,17 @@ import { adaptPr } from '@/api-helpers/pr';
import { updatePrFilterParams } from '@/api-helpers/team';
import { MAX_INT } from '@/constants/generic';
import { mockTeamPullRequests } from '@/mocks/pull-requests';
import { BasePR, Comparison, PR, RepoFilterConfig } from '@/types/resources';
import {
ActiveBranchMode,
BasePR,
Comparison,
PR,
RepoFilterConfig
} from '@/types/resources';
import { getFilters } from '@/utils/cockpitMetricUtils';
import { getCycleTimeForPr } from '@/utils/code';
import { isoDateString, getDateWithComparisonRanges } from '@/utils/date';
import { getFilters } from '@/utils/cockpitMetricUtils';
import { handleRequest } from '@/api-helpers/axios';
import { getBranchesAndRepoFilter } from '@/utils/filterUtils';

const pathSchema = yup.object().shape({
team_id: yup.string().uuid().required()
Expand All @@ -32,7 +39,8 @@ const getSchema = yup.object().shape({
})
.optional()
.nullable(),
repo_filters: yup.mixed().optional().nullable()
repo_filters: yup.mixed().optional().nullable(),
branch_mode: yup.string().oneOf(Object.values(ActiveBranchMode)).required()
});

const endpoint = new Endpoint(pathSchema);
Expand All @@ -44,22 +52,31 @@ endpoint.handle.GET(getSchema, async (req, res) => {
prev: mockTeamPullRequests
});
}
const {
org_id,
team_id,
from_date,
to_date,
branch_mode,
branches,
cycle_time
} = req.payload;

const { curr } = getDateWithComparisonRanges(from_date, to_date);
const branchAndRepoFilters = await getBranchesAndRepoFilter({
orgId: org_id,
teamId: team_id,
branchMode: branch_mode as ActiveBranchMode,
branches
});

const { curr } = getDateWithComparisonRanges(
req.payload.from_date,
req.payload.to_date
);

const [currInsights] = await Promise.all([
getTeamPrs({
team_id: req.payload.team_id,
branches: req.payload.branches,
from_date: curr.from,
to_date: curr.to,
cycle_time: req.payload.cycle_time,
repo_filters: req.payload.repo_filters
})
]);
const currInsights = await getTeamPrs({
team_id: team_id,
from_date: curr.from,
to_date: curr.to,
cycle_time: cycle_time,
...branchAndRepoFilters
});

return res.send({
curr: currInsights,
Expand Down Expand Up @@ -112,34 +129,6 @@ export const getTeamPrs = async ({
}));
};

export const getTeamPrsWithComparisonSegment = ({
team_id,
branches,
from_date,
to_date,
repo_filters
}: GetTeamPrs): [Promise<PR[]>, Promise<PR[]>] => {
const { curr, prev } = getDateWithComparisonRanges(from_date, to_date);

const currentSegmentPromise = getTeamPrs({
team_id,
branches,
from_date: curr.from,
to_date: curr.to,
repo_filters
}).then((r) => r.data);

const previousSegmentPromise = getTeamPrs({
team_id,
branches,
from_date: prev.from,
to_date: prev.to,
repo_filters
}).then((r) => r.data);

return [currentSegmentPromise, previousSegmentPromise];
};

export const getTeamLeadTimePRs = (
team_id: string,
from_time: Date | DateString,
Expand Down
Loading