2023-01-31 09:37:11 +01:00
|
|
|
import { usePipelineStore } from '~/store/pipelines';
|
|
|
|
import { useRepoStore } from '~/store/repos';
|
2021-11-03 17:40:31 +01:00
|
|
|
|
|
|
|
import useApiClient from './useApiClient';
|
|
|
|
|
|
|
|
const apiClient = useApiClient();
|
|
|
|
let initialized = false;
|
|
|
|
|
|
|
|
export default () => {
|
|
|
|
if (initialized) {
|
|
|
|
return;
|
|
|
|
}
|
2023-01-31 09:37:11 +01:00
|
|
|
const repoStore = useRepoStore();
|
|
|
|
const pipelineStore = usePipelineStore();
|
2021-11-03 17:40:31 +01:00
|
|
|
|
|
|
|
initialized = true;
|
|
|
|
|
|
|
|
apiClient.on((data) => {
|
|
|
|
// contains repo update
|
|
|
|
if (!data.repo) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
const { repo } = data;
|
|
|
|
repoStore.setRepo(repo);
|
|
|
|
|
2022-10-22 15:54:43 +02:00
|
|
|
// contains pipeline update
|
2022-10-18 03:24:12 +02:00
|
|
|
if (!data.pipeline) {
|
2021-11-03 17:40:31 +01:00
|
|
|
return;
|
|
|
|
}
|
2022-10-18 03:24:12 +02:00
|
|
|
const { pipeline } = data;
|
2023-06-12 16:07:52 -07:00
|
|
|
pipelineStore.setPipeline(repo.id, pipeline);
|
2021-11-03 17:40:31 +01:00
|
|
|
|
2022-10-28 21:08:53 +05:30
|
|
|
// contains step update
|
|
|
|
if (!data.step) {
|
2021-11-03 17:40:31 +01:00
|
|
|
return;
|
|
|
|
}
|
2022-10-28 21:08:53 +05:30
|
|
|
const { step } = data;
|
2023-06-27 18:01:18 +02:00
|
|
|
pipelineStore.setWorkflow(repo.id, pipeline.number, step);
|
2021-11-03 17:40:31 +01:00
|
|
|
});
|
|
|
|
};
|