debian-mirror-gitlab/app/assets/javascripts/pipelines/components/graph/utils.js

66 lines
1.7 KiB
JavaScript
Raw Normal View History

2021-02-22 17:27:13 +05:30
import Visibility from 'visibilityjs';
import { getIdFromGraphQLId } from '~/graphql_shared/utils';
2021-03-08 18:12:59 +05:30
import * as Sentry from '~/sentry/wrapper';
2021-02-22 17:27:13 +05:30
import { unwrapStagesWithNeeds } from '../unwrapping_utils';
const addMulti = (mainPipelineProjectPath, linkedPipeline) => {
return {
...linkedPipeline,
multiproject: mainPipelineProjectPath !== linkedPipeline.project.fullPath,
};
};
2021-03-08 18:12:59 +05:30
const transformId = (linkedPipeline) => {
2021-02-22 17:27:13 +05:30
return { ...linkedPipeline, id: getIdFromGraphQLId(linkedPipeline.id) };
};
const unwrapPipelineData = (mainPipelineProjectPath, data) => {
if (!data?.project?.pipeline) {
return null;
}
const { pipeline } = data.project;
const {
upstream,
downstream,
stages: { nodes: stages },
} = pipeline;
const nodes = unwrapStagesWithNeeds(stages);
return {
...pipeline,
id: getIdFromGraphQLId(pipeline.id),
stages: nodes,
upstream: upstream
? [upstream].map(addMulti.bind(null, mainPipelineProjectPath)).map(transformId)
: [],
downstream: downstream
? downstream.nodes.map(addMulti.bind(null, mainPipelineProjectPath)).map(transformId)
: [],
};
};
const toggleQueryPollingByVisibility = (queryRef, interval = 10000) => {
2021-03-08 18:12:59 +05:30
const stopStartQuery = (query) => {
2021-02-22 17:27:13 +05:30
if (!Visibility.hidden()) {
query.startPolling(interval);
} else {
query.stopPolling();
}
};
stopStartQuery(queryRef);
Visibility.change(stopStartQuery.bind(null, queryRef));
};
export { unwrapPipelineData, toggleQueryPollingByVisibility };
2021-03-08 18:12:59 +05:30
export const reportToSentry = (component, failureType) => {
Sentry.withScope((scope) => {
scope.setTag('component', component);
Sentry.captureException(failureType);
});
};