debian-mirror-gitlab/app/assets/javascripts/api/analytics_api.js

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

92 lines
3.4 KiB
JavaScript
Raw Normal View History

2021-09-04 01:27:46 +05:30
import axios from '~/lib/utils/axios_utils';
2021-10-27 15:23:28 +05:30
import { joinPaths } from '~/lib/utils/url_utility';
2021-09-04 01:27:46 +05:30
import { buildApiUrl } from './api_utils';
2023-05-27 22:25:52 +05:30
const PROJECT_VSA_METRICS_BASE = '/:namespace_path/-/analytics/value_stream_analytics';
const PROJECT_VSA_PATH_BASE = '/:namespace_path/-/analytics/value_stream_analytics/value_streams';
2021-09-04 01:27:46 +05:30
const PROJECT_VSA_STAGES_PATH = `${PROJECT_VSA_PATH_BASE}/:value_stream_id/stages`;
2021-10-27 15:23:28 +05:30
const PROJECT_VSA_STAGE_DATA_PATH = `${PROJECT_VSA_STAGES_PATH}/:stage_id`;
2021-09-04 01:27:46 +05:30
2023-03-04 22:38:38 +05:30
export const LEAD_TIME_METRIC_TYPE = 'lead_time';
export const CYCLE_TIME_METRIC_TYPE = 'cycle_time';
export const ISSUES_METRIC_TYPE = 'issues';
export const DEPLOYS_METRIC_TYPE = 'deploys';
2021-10-27 15:23:28 +05:30
export const METRIC_TYPE_SUMMARY = 'summary';
export const METRIC_TYPE_TIME_SUMMARY = 'time_summary';
2023-05-27 22:25:52 +05:30
const buildProjectMetricsPath = (namespacePath) =>
buildApiUrl(PROJECT_VSA_METRICS_BASE).replace(':namespace_path', namespacePath);
2021-10-27 15:23:28 +05:30
2023-05-27 22:25:52 +05:30
const buildProjectValueStreamPath = (namespacePath, valueStreamId = null) => {
2021-09-04 01:27:46 +05:30
if (valueStreamId) {
return buildApiUrl(PROJECT_VSA_STAGES_PATH)
2023-05-27 22:25:52 +05:30
.replace(':namespace_path', namespacePath)
2021-09-04 01:27:46 +05:30
.replace(':value_stream_id', valueStreamId);
}
2023-05-27 22:25:52 +05:30
return buildApiUrl(PROJECT_VSA_PATH_BASE).replace(':namespace_path', namespacePath);
2021-09-04 01:27:46 +05:30
};
2023-05-27 22:25:52 +05:30
const buildValueStreamStageDataPath = ({ namespacePath, valueStreamId = null, stageId = null }) =>
2021-10-27 15:23:28 +05:30
buildApiUrl(PROJECT_VSA_STAGE_DATA_PATH)
2023-05-27 22:25:52 +05:30
.replace(':namespace_path', namespacePath)
2021-09-30 23:02:18 +05:30
.replace(':value_stream_id', valueStreamId)
.replace(':stage_id', stageId);
2023-05-27 22:25:52 +05:30
export const getProjectValueStreams = (namespacePath) => {
const url = buildProjectValueStreamPath(namespacePath);
2021-09-04 01:27:46 +05:30
return axios.get(url);
};
2023-05-27 22:25:52 +05:30
export const getProjectValueStreamStages = (namespacePath, valueStreamId) => {
const url = buildProjectValueStreamPath(namespacePath, valueStreamId);
2021-09-04 01:27:46 +05:30
return axios.get(url);
};
// NOTE: legacy VSA request use a different path
2023-05-27 22:25:52 +05:30
// the `namespacePath` provides a full url for the request
export const getProjectValueStreamStageData = ({ namespacePath, stageId, params }) =>
axios.get(joinPaths(namespacePath, 'events', stageId), { params });
2021-09-04 01:27:46 +05:30
2021-09-30 23:02:18 +05:30
/**
2021-10-27 15:23:28 +05:30
* Dedicated project VSA paths
2021-09-30 23:02:18 +05:30
*/
2023-05-27 22:25:52 +05:30
export const getValueStreamStageMedian = (
{ namespacePath, valueStreamId, stageId },
params = {},
) => {
const stageBase = buildValueStreamStageDataPath({ namespacePath, valueStreamId, stageId });
2021-10-27 15:23:28 +05:30
return axios.get(joinPaths(stageBase, 'median'), { params });
};
export const getValueStreamStageRecords = (
2023-05-27 22:25:52 +05:30
{ namespacePath, valueStreamId, stageId },
2021-10-27 15:23:28 +05:30
params = {},
) => {
2023-05-27 22:25:52 +05:30
const stageBase = buildValueStreamStageDataPath({ namespacePath, valueStreamId, stageId });
2021-10-27 15:23:28 +05:30
return axios.get(joinPaths(stageBase, 'records'), { params });
};
2023-05-27 22:25:52 +05:30
export const getValueStreamStageCounts = (
{ namespacePath, valueStreamId, stageId },
params = {},
) => {
const stageBase = buildValueStreamStageDataPath({ namespacePath, valueStreamId, stageId });
2021-10-27 15:23:28 +05:30
return axios.get(joinPaths(stageBase, 'count'), { params });
};
export const getValueStreamMetrics = ({
endpoint = METRIC_TYPE_SUMMARY,
2023-05-27 22:25:52 +05:30
requestPath: namespacePath,
2021-10-27 15:23:28 +05:30
params = {},
}) => {
2023-05-27 22:25:52 +05:30
const metricBase = buildProjectMetricsPath(namespacePath);
2021-10-27 15:23:28 +05:30
return axios.get(joinPaths(metricBase, endpoint), { params });
};
2023-05-27 22:25:52 +05:30
export const getValueStreamSummaryMetrics = (namespacePath, params = {}) => {
const metricBase = buildProjectMetricsPath(namespacePath);
2021-10-27 15:23:28 +05:30
return axios.get(joinPaths(metricBase, 'summary'), { params });
2021-09-30 23:02:18 +05:30
};