From f218cdfed4d50c9926c5753604d7bb7a81476a33 Mon Sep 17 00:00:00 2001 From: Egor Stronhin Date: Wed, 6 Mar 2024 22:21:51 +0200 Subject: [PATCH 01/16] feat: actions --- src/main/ipcs/ipcGitHub.ts | 29 +++++++++++++++++++ src/main/ipcs/preload.ts | 1 + .../components/QuickActions/QuickActions.tsx | 16 ++++++++++ 3 files changed, 46 insertions(+) diff --git a/src/main/ipcs/ipcGitHub.ts b/src/main/ipcs/ipcGitHub.ts index ee6f774..5a66982 100644 --- a/src/main/ipcs/ipcGitHub.ts +++ b/src/main/ipcs/ipcGitHub.ts @@ -52,3 +52,32 @@ ipcMain.handle('git:api:reset', async (_, id: string, origin: string, target: st return { message: e.message, success: false }; } }); + +ipcMain.handle('git:api:getAction', async (_, id: string, filterBy: string[]) => { + try { + const { owner, repo } = await getRepoInfo(id); + if (!owner || !repo) throw new Error('Project not found'); + + const { data } = await getClient().rest.actions.listWorkflowRunsForRepo({ + owner, + repo + }); + + if (data.total_count < 1) { + return { message: 'No running actions', success: true }; + } + + // Filter by branch and only from last hour + const runs = data.workflow_runs + .filter((run) => filterBy.includes(run.head_branch)) + .filter((run) => new Date(run.created_at).getTime() > Date.now() - 3600000); + + if (runs.length < 1) { + return { message: 'No actions for this branch', success: true }; + } + + return { data, filterBy, runs, success: true }; + } catch (e) { + return { message: e.message, success: false }; + } +}); diff --git a/src/main/ipcs/preload.ts b/src/main/ipcs/preload.ts index 61fd610..5854620 100644 --- a/src/main/ipcs/preload.ts +++ b/src/main/ipcs/preload.ts @@ -21,6 +21,7 @@ const bridge = { reset: (id: string, target: string, force: boolean) => ipcRenderer.invoke('git:reset', id, target, force) }, gitAPI: { + getAction: (id: string, filterBy: string[]) => ipcRenderer.invoke('git:api:getAction', id, filterBy), reset: (id: string, origin: string, target: string) => ipcRenderer.invoke('git:api:reset', id, origin, target) }, launch: { diff --git a/src/rendered/components/Project/components/QuickActions/QuickActions.tsx b/src/rendered/components/Project/components/QuickActions/QuickActions.tsx index bda113c..c6e7d54 100644 --- a/src/rendered/components/Project/components/QuickActions/QuickActions.tsx +++ b/src/rendered/components/Project/components/QuickActions/QuickActions.tsx @@ -25,6 +25,15 @@ export const QuickActions: FC = ({ project, gitStatus, loading }) => { navigator.clipboard.writeText(gitStatus?.branchSummary?.current); }; + const getActions = async () => { + const savedOrigin = localStorage.getItem(`GitResetModal:origin-${project.id}`); + const filterBy = [gitStatus.branchSummary.current]; + if (savedOrigin) filterBy.push(savedOrigin); + + const res = await window.bridge.gitAPI.getAction(project.id, filterBy); + console.log(res); + }; + return (