Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Webhooks execution #922

Merged
merged 8 commits into from
Feb 3, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,12 @@ export const repoWebhooksListStore: RepoWebhooksListStore = {
}
],
error: undefined,
webhookExecutionPage: 1,
setWebhookExecutionPage: (_: number) => {},
totalWebhookExecutionPages: 1,
executions: [],
setExecutions: () => {},
setTotalWebhookExecutionPages: (_: Headers) => {},
setError: noop,
totalPages: 20,
webhookLoading: false,
Expand Down
3 changes: 2 additions & 1 deletion apps/gitness/src/RouteDefinitions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ export const PathProps = {
pullRequestId: ':pullRequestId',
gitRef: ':gitRef*',
resourcePath: ':resourcePath*',
diffRefs: ':diffRefs*'
diffRefs: ':diffRefs*',
webhookId: ':webhookId*'
}

export type PullRequestRoutePathParams = Omit<PathParams, 'pipelineId' | 'executionId' | 'gitRef'>
4 changes: 3 additions & 1 deletion apps/gitness/src/framework/routing/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,9 @@ export enum RouteConstants {
toProfileKeys = 'toProfileKeys',
toProfileGeneral = 'toProfileGeneral',
toRepoLabels = 'toRepoLabels',
toProjectLabels = 'toProjectLabels'
toProjectLabels = 'toProjectLabels',
toRepoWebhookDetails = 'toRepoWebhookDetails',
toRepoWebhookExecutions = 'toRepoWebhookExecutions'
}

export interface RouteEntry {
Expand Down
11 changes: 10 additions & 1 deletion apps/gitness/src/pages-v2/webhooks/stores/webhook-store.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { create } from 'zustand'

import { CreateWebhookFormFields, WebhookStore } from '@harnessio/ui/views'
import { CreateWebhookFormFields, WebhookExecutionType, WebhookStore } from '@harnessio/ui/views'

import { timeAgoFromEpochTime } from '../../../pages/pipeline-edit/utils/time-utils'
import { PageResponseHeader } from '../../../types'
Expand All @@ -12,9 +12,15 @@ export const useWebhookStore = create<WebhookStore>(set => ({
preSetWebhookData: null,
setError: error => set({ error }),
page: 1,
webhookExecutionPage: 1,
totalWebhookExecutionPages: 0,
setPage: page => set({ page }),
webhookLoading: false,
executions: null,
setWebhookLoading: (webhookLoading: boolean) => set({ webhookLoading }),
setWebhookExecutionPage: page => set({ webhookExecutionPage: page }),
setTotalWebhookExecutionPages: headers =>
set({ totalWebhookExecutionPages: parseInt(headers.get(PageResponseHeader.xTotalPages) || '0') }),
setWebhooks: data => {
const transformedWebhooks = data.map(webhook => ({
id: webhook.id || 0,
Expand All @@ -31,6 +37,9 @@ export const useWebhookStore = create<WebhookStore>(set => ({
webhooks: transformedWebhooks
})
},
setExecutions: (data: WebhookExecutionType[]) => {
set({ executions: data })
},
setTotalPages: headers => set({ totalPages: parseInt(headers?.get(PageResponseHeader.xTotalPages) || '0') }),
setPreSetWebhookData: (data: CreateWebhookFormFields | null) => set({ preSetWebhookData: data })
}))
53 changes: 53 additions & 0 deletions apps/gitness/src/pages-v2/webhooks/webhook-executions.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import { useEffect } from 'react'
import { useParams } from 'react-router-dom'

import { useListRepoWebhookExecutionsQuery } from '@harnessio/code-service-client'
import { RepoWebhookExecutionsPage, WebhookExecutionType } from '@harnessio/ui/views'

import { useRoutes } from '../../framework/context/NavigationContext'
import { useGetRepoRef } from '../../framework/hooks/useGetRepoPath'
import usePaginationQueryStateWithStore from '../../hooks/use-pagination-query-state-with-store'
import { useTranslationStore } from '../../i18n/stores/i18n-store'
import { PathParams } from '../../RouteDefinitions'
import { useWebhookStore } from './stores/webhook-store'

export const WebhookExecutionsContainer = () => {
const repo_ref = useGetRepoRef()
const routes = useRoutes()
const { webhookId } = useParams<PathParams>()
const { webhookExecutionPage, setWebhookExecutionPage, setExecutions, setTotalWebhookExecutionPages } =
useWebhookStore()

const { queryPage } = usePaginationQueryStateWithStore({
page: webhookExecutionPage,
setPage: setWebhookExecutionPage
})

const { data: { body: executions, headers } = {}, isLoading } = useListRepoWebhookExecutionsQuery(
{
repo_ref,
webhook_identifier: parseInt(webhookId ?? ''),
queryParams: {
page: queryPage
}
},
{ enabled: !!webhookId }
)

useEffect(() => {
if (executions && headers) {
setExecutions(executions as WebhookExecutionType[])
setTotalWebhookExecutionPages(headers)
}
}, [executions, setExecutions])

return (
<RepoWebhookExecutionsPage
useTranslationStore={useTranslationStore}
useWebhookStore={useWebhookStore}
toRepoWebhooks={() => routes.toRepoWebhooks({ repoId: repo_ref })}
repo_ref={repo_ref}
isLoading={isLoading}
/>
)
}
53 changes: 45 additions & 8 deletions apps/gitness/src/routes.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
import { Navigate } from 'react-router-dom'

import { Breadcrumb, Text } from '@harnessio/ui/components'
import { EmptyPage, ProfileSettingsLayout, RepoSettingsLayout, SandboxLayout } from '@harnessio/ui/views'
import {
EmptyPage,
ProfileSettingsLayout,
RepoSettingsLayout,
SandboxLayout,
WebhookSettingsLayout
} from '@harnessio/ui/views'

import { AppShell, AppShellMFE } from './components-v2/app-shell'
import { ProjectDropdown } from './components-v2/breadcrumbs/project-dropdown'
Expand Down Expand Up @@ -52,6 +58,7 @@ import { SignIn } from './pages-v2/signin'
import { SignUp } from './pages-v2/signup'
import { UserManagementPageContainer } from './pages-v2/user-management/user-management-container'
import { CreateWebhookContainer } from './pages-v2/webhooks/create-webhook-container'
import { WebhookExecutionsContainer } from './pages-v2/webhooks/webhook-executions'
import WebhookListPage from './pages-v2/webhooks/webhook-list'

enum Page {
Expand Down Expand Up @@ -426,13 +433,6 @@ export const repoRoutes: CustomRouteObject[] = [
handle: {
breadcrumb: () => <Text>Create a webhook</Text>
}
},
{
path: ':webhookId',
element: <CreateWebhookContainer />,
handle: {
breadcrumb: ({ webhookId }: { webhookId: string }) => <Text>{webhookId}</Text>
}
}
]
},
Expand Down Expand Up @@ -465,6 +465,43 @@ export const repoRoutes: CustomRouteObject[] = [
]
}
]
},

{
path: 'settings/webhooks/:webhookId',
element: <WebhookSettingsLayout useTranslationStore={useTranslationStore} />,
children: [
{
index: true,
element: <Navigate to="details" replace />
},
{
path: 'details',
element: <CreateWebhookContainer />,
handle: {
breadcrumb: ({ webhookId }: { webhookId: string }) => (
<>
<Text>{webhookId}</Text> <Breadcrumb.Separator />
<Text className="ml-1.5">Details</Text>
</>
),
routeName: RouteConstants.toRepoWebhookDetails
}
},
{
path: 'executions',
element: <WebhookExecutionsContainer />,
handle: {
breadcrumb: ({ webhookId }: { webhookId: string }) => (
<>
<Text>{webhookId}</Text> <Breadcrumb.Separator />
<Text className="ml-1.5">Executions</Text>
</>
),
routeName: RouteConstants.toRepoWebhookExecutions
}
}
]
}
]
}
Expand Down
6 changes: 5 additions & 1 deletion packages/ui/locales/en/views.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@
"saving": "Saving…",
"save": "Save",
"cancel": "Cancel",
"general": "General",
"details": "Details",
"executions": "Executions",
"generalTab": "General",
"keysTab": "Keys and tokens",
"tags": "Tags",
Expand Down Expand Up @@ -127,7 +130,6 @@
"security": "Security",
"secretScanning": "Secret scanning",
"secretScanningDescription": "Block commits containing secrets like passwords, API keys and tokens.",
"general": "General",
"codeAutomation": "Code and automation",
"webhooks": "Webhooks",
"labels": "Labels",
Expand Down Expand Up @@ -195,6 +197,8 @@
"noRepos": "No repositories yet",
"noReposProject": "There are no repositories in this project yet.",
"createOrImportRepos": "Create new or import an existing repository.",
"noWebhookExecution": "No webhook executions yet",
"noWebhookExecutionsDescription": "Your webhook executions will appear here once they're completed. Trigger your webhook to see the results.",
"noWebhooks": "No webhooks yet",
"noWebhooksDescription": "Add or manage webhooks to automate tasks and connect external services to your project.",
"commit": "Commit",
Expand Down
6 changes: 5 additions & 1 deletion packages/ui/locales/es/views.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@
"saving": "Saving...",
"save": "Save",
"cancel": "Cancel",
"general": "General",
"details": "Details",
"executions": "Executions",
"generalTab": "General",
"keysTab": "Keys and tokens",
"tags": "Tags",
Expand Down Expand Up @@ -127,7 +130,6 @@
"security": "Security",
"secretScanning": "Secret scanning",
"secretScanningDescription": "Block commits containing secrets like passwords, API keys and tokens.",
"general": "General",
"codeAutomation": "Code and automation",
"webhooks": "Webhooks",
"labels": "Labels",
Expand Down Expand Up @@ -195,6 +197,8 @@
"noRepos": "No repositories yet",
"noReposProject": "There are no repositories in this project yet.",
"createOrImportRepos": "Create new or import an existing repository.",
"noWebhookExecution": "No webhook executions yet",
"noWebhookExecutionsDescription": "Your webhook executions will appear here once they're completed. Trigger your webhook to see the results.",
"noWebhooks": "No webhooks yet",
"noWebhooksDescription": "Add or manage webhooks to automate tasks and connect external services to your project.",
"commit": "Commit",
Expand Down
6 changes: 5 additions & 1 deletion packages/ui/locales/fr/views.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@
"saving": "Enregistrement...",
"save": "Enregistrer",
"cancel": "Annuler",
"general": "Général",
"details": "Details",
"executions": "Executions",
"generalTab": "General",
"keysTab": "Keys and tokens",
"tags": "Étiquettes",
Expand Down Expand Up @@ -127,7 +130,6 @@
"security": "Sécurité",
"secretScanning": "Analyse des secrets",
"secretScanningDescription": "Empêcher les commits contenant des secrets comme les mots de passe ou jetons API.",
"general": "Général",
"codeAutomation": "Automatisation du code",
"webhooks": "Webhooks",
"labels": "Labels",
Expand Down Expand Up @@ -195,6 +197,8 @@
"noRepos": "Pas encore de dépôts",
"noReposProject": "Il n'y a pas encore de dépôts dans ce projet.",
"createOrImportRepos": "Créer un nouveau dépôt ou importer un dépôt existant.",
"noWebhookExecution": "No webhook executions yet",
"noWebhookExecutionsDescription": "Your webhook executions will appear here once they're completed. Trigger your webhook to see the results.",
"noWebhooks": "No webhooks yet",
"noWebhooksDescription": "Add or manage webhooks to automate tasks and connect external services to your project.",
"commit": "Validation",
Expand Down
1 change: 1 addition & 0 deletions packages/ui/src/views/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export * as SandboxLayout from './layouts/SandboxLayout'
export * from './layouts/Floating1ColumnLayout'
export * from './layouts/PullRequestLayout'
export * from './layouts/content-layout-with-sidebar'
export * from './layouts/webhooks-settings-layout'

// Account
export * from './account'
Expand Down
25 changes: 25 additions & 0 deletions packages/ui/src/views/layouts/webhooks-settings-layout.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { Outlet } from 'react-router-dom'

import { ContentLayoutWithSidebar, TranslationStore } from '@/views'
import { TFunction } from 'i18next'

const getNavItems = (t: TFunction) => [
{
groupId: 0,
title: t('views:repos.general', 'Webhook Settings'),
items: [
{ id: 0, title: t('views:repos.details', 'Details'), to: 'details' },
{ id: 1, title: t('views:repos.executions', 'Executions'), to: 'executions' }
Comment on lines +11 to +12
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

navigation paths should not be hardcoded. use routes object instead

]
}
]

export function WebhookSettingsLayout({ useTranslationStore }: { useTranslationStore: () => TranslationStore }) {
const { t } = useTranslationStore()

return (
<ContentLayoutWithSidebar sidebarMenu={getNavItems(t)} sidebarOffsetTop={100} sidebarViewportClassName="pt-7">
<Outlet />
</ContentLayoutWithSidebar>
)
}
3 changes: 3 additions & 0 deletions packages/ui/src/views/repo/webhooks/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,6 @@ export * from '@views/repo/webhooks/webhook-list/types'
// webhook create
export * from '@views/repo/webhooks/webhook-create/repo-webhook-create-page'
export * from '@views/repo/webhooks/webhook-create/types'

// webhook executions
export * from '@views/repo/webhooks/webhook-executions/repo-webhook-executions-page'
Loading