İçeriğe geç

Samples

Bu içerik henüz dilinizde mevcut değil.

To start a new Kit from a template instead, run ketvia kits create <slug> --template tools|webhook|events; see the CLI. The webhook template matches the sample below.

ci-webhook (in samples/ci-webhook) is the smallest possible Kit: an incoming webhook only, with no backend, no tokens and no events. It posts build results (status, repository, branch, commit, duration and a link to the run) as Blocks, using postToWebhook and the Blocks builders of @ketvia/kit.

manifest.json
{
"schemaVersion": 1,
"slug": "acme-ci-notify",
"version": "0.1.0",
"displayName": { "en": "Acme CI" },
"description": { "en": "Posts build results to a channel." },
"developer": { "name": "Acme Inc.", "url": "https://acme.dev", "supportEmail": "[email protected]" },
"privacyPolicyUrl": "https://acme.dev/privacy",
"bot": { "displayName": { "en": "Acme CI" }, "scopes": ["incoming-webhook"] },
"incomingWebhooks": { "maxPerInstallation": 5 },
"distribution": "private"
}

Slugs are global, so change slug (and the names) before you create your own copy.

  1. In Ketvia, open Admin → Connections, choose Create a private Kit and paste the manifest.
  2. Install it with Add a Kit, open the Kit’s API access page and create an incoming webhook for the channel the builds should go to (you must be a member of it).
  3. Copy the URL, which is shown once, into a CI secret named KETVIA_WEBHOOK_URL. Never commit or print it. If it leaks, revoke the webhook and create a new one.

With the sample’s command (inside the repository that contains it):

- name: Notify Ketvia
if: always()
env:
KETVIA_WEBHOOK_URL: ${{ secrets.KETVIA_WEBHOOK_URL }}
run: pnpm --filter @ketvia/sample-ci-webhook notify --status ${{ job.status == 'success' && 'passed' || job.status == 'cancelled' && 'cancelled' || 'failed' }}

The command reads GITHUB_REPOSITORY, GITHUB_REF_NAME, GITHUB_SHA, GITHUB_RUN_NUMBER, GITHUB_SERVER_URL, GITHUB_RUN_ID and GITHUB_ACTOR, which GitHub Actions sets. Options: --status passed|failed|cancelled (required), --duration <seconds> and --author <name>. It prints posted, or a short error with the HTTP status and the correlation id, never the URL.

Without any dependency, a plain curl step does the same job:

- name: Notify Ketvia
if: always()
env:
KETVIA_WEBHOOK_URL: ${{ secrets.KETVIA_WEBHOOK_URL }}
STATUS: ${{ job.status }}
run: |
curl -sf -X POST "$KETVIA_WEBHOOK_URL" \
-H 'Content-Type: application/json' \
-d "{\"text\":\"Build #$GITHUB_RUN_NUMBER of $GITHUB_REPOSITORY: $STATUS\",
\"blocks\":[{\"type\":\"header\",\"text\":\"Build #$GITHUB_RUN_NUMBER: $STATUS\"},
{\"type\":\"fields\",\"fields\":[{\"label\":\"Branch\",\"value\":\"$GITHUB_REF_NAME\"}]}]}"
import { notifyBuild } from '@ketvia/sample-ci-webhook';
await notifyBuild(process.env.KETVIA_WEBHOOK_URL ?? '', {
repository: 'acme/web',
branch: 'main',
commit: '3f2a9c1b7e4d',
status: 'passed',
number: 42,
url: 'https://github.com/acme/web/actions/runs/123',
durationSeconds: 125,
});

404 means the webhook is unknown or revoked; 410 that it was disabled because the channel was archived or the Kit bot was removed; 429 that you post faster than 1 per second (the sample retries after Retry-After). See Incoming webhooks.