mirror of
https://github.com/woodpecker-ci/woodpecker.git
synced 2024-06-18 05:10:48 +00:00
Renamed `procs` to `steps` in code for the issue #1288 Co-authored-by: Harikesh Prajapati <harikesh.prajapati@druva.com> Co-authored-by: qwerty287 <ndev@web.de> Co-authored-by: qwerty287 <80460567+qwerty287@users.noreply.github.com> Co-authored-by: 6543 <6543@obermui.de>
67 lines
1.7 KiB
TypeScript
67 lines
1.7 KiB
TypeScript
import { Pipeline, PipelineStep, Repo } from '~/lib/api/types';
|
|
|
|
export function findStep(steps: PipelineStep[], pid: number): PipelineStep | undefined {
|
|
return steps.reduce((prev, step) => {
|
|
if (step.pid === pid) {
|
|
return step;
|
|
}
|
|
|
|
if (step.children) {
|
|
const result = findStep(step.children, pid);
|
|
if (result) {
|
|
return result;
|
|
}
|
|
}
|
|
|
|
return prev;
|
|
}, undefined as PipelineStep | undefined);
|
|
}
|
|
|
|
/**
|
|
* Returns true if the process is in a completed state.
|
|
*
|
|
* @param {Object} step - The process object.
|
|
* @returns {boolean}
|
|
*/
|
|
export function isStepFinished(step: PipelineStep): boolean {
|
|
return step.state !== 'running' && step.state !== 'pending';
|
|
}
|
|
|
|
/**
|
|
* Returns true if the process is running.
|
|
*
|
|
* @param {Object} step - The process object.
|
|
* @returns {boolean}
|
|
*/
|
|
export function isStepRunning(step: PipelineStep): boolean {
|
|
return step.state === 'running';
|
|
}
|
|
|
|
/**
|
|
* Compare two pipelines by creation timestamp.
|
|
* @param {Object} a - A pipeline.
|
|
* @param {Object} b - A pipeline.
|
|
* @returns {number}
|
|
*/
|
|
export function comparePipelines(a: Pipeline, b: Pipeline): number {
|
|
return (b.created_at || -1) - (a.created_at || -1);
|
|
}
|
|
|
|
export function isPipelineActive(pipeline: Pipeline): boolean {
|
|
return ['pending', 'running', 'started'].includes(pipeline.status);
|
|
}
|
|
|
|
export function repoSlug(ownerOrRepo: Repo): string;
|
|
export function repoSlug(ownerOrRepo: string, name: string): string;
|
|
export function repoSlug(ownerOrRepo: string | Repo, name?: string): string {
|
|
if (typeof ownerOrRepo === 'string') {
|
|
if (!name) {
|
|
throw new Error('Please provide a name as well');
|
|
}
|
|
|
|
return `${ownerOrRepo}/${name}`;
|
|
}
|
|
|
|
return `${ownerOrRepo.owner}/${ownerOrRepo.name}`;
|
|
}
|