File size: 1,887 Bytes
1e92f2d |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
import { useQuery, UseQueryOptions } from '@tanstack/react-query';
import wp from 'calypso/lib/wp';
import { GITHUB_DEPLOYMENTS_QUERY_KEY } from '../constants';
export const CODE_DEPLOYMENTS_RUN_LOG_QUERY_KEY = 'code-deployments-run-log';
export interface LogEntry {
message: string;
level: string;
timestamp: string;
context?: Context;
}
export interface Context {
command: Command;
}
export interface Command {
command_identifier: string;
exit_code: number;
}
export interface LogEntryDetail {
exit_code: number;
stdout: Array< string >;
stderr: Array< string >;
}
export const useCodeDeploymentsRunLogQuery = (
siteId: number | null,
deploymentId: number,
runId: number,
options?: Partial< UseQueryOptions< LogEntry[] > >
) => {
return useQuery< LogEntry[] >( {
enabled: !! siteId,
queryKey: [
GITHUB_DEPLOYMENTS_QUERY_KEY,
CODE_DEPLOYMENTS_RUN_LOG_QUERY_KEY,
siteId,
deploymentId,
runId,
],
queryFn: (): LogEntry[] =>
wp.req.get( {
path: `/sites/${ siteId }/hosting/code-deployments/${ deploymentId }/runs/${ runId }/logs`,
apiNamespace: 'wpcom/v2',
} ),
meta: {
persist: false,
},
...options,
} );
};
export const useCodeDeploymentsRunLogDetailQuery = (
siteId: number | null,
deploymentId: number,
runId: number,
commandIdentifier: string | null,
options?: Partial< UseQueryOptions< LogEntryDetail > >
) => {
return useQuery< LogEntryDetail >( {
enabled: !! siteId && !! commandIdentifier,
queryKey: [
GITHUB_DEPLOYMENTS_QUERY_KEY,
CODE_DEPLOYMENTS_RUN_LOG_QUERY_KEY,
siteId,
deploymentId,
runId,
commandIdentifier,
],
queryFn: (): LogEntryDetail =>
wp.req.get( {
path: `/sites/${ siteId }/hosting/code-deployments/${ deploymentId }/runs/${ runId }/logs/${ commandIdentifier }`,
apiNamespace: 'wpcom/v2',
} ),
meta: {
persist: false,
},
...options,
} );
};
|