Ignitify.dev
Tutorials

Nightly GitHub report

Every night, a short task reads one GitHub repository through its API and returns a Markdown digest of the day. A cron starts it through a signed webhook, and a callback tells your server when the report is ready.

nodeegresssecretswebhooksschedulesabout 20 minStarter tier

What this tutorial proves

  • A task reads a secret by name (ctx.secrets). The value is never in the code, the config or the command line.
  • A task reaches only the hosts you allow (egress_allow), and nothing can connect in.
  • A run can start at a set time (task:run --at), or from a signed webhook that a cron calls.
  • A repeated webhook delivery returns the same run, so a retried cron job does not start a second report.
  • The platform calls your server when a run ends (notify:set), signed, so you know it is from us.

What you build

A daily digest of one GitHub repository, as Markdown: releases, merged and new pull requests, new and closed issues, and commits.

  1. A cron calls the task's webhook every night, with the repository in the body.
  2. The task reads four GitHub endpoints at the same time, with your token.
  3. It returns the counts and the Markdown report as the run's result.
  4. The platform calls your server. Your server reads the report from the run.
the flow
cron (06:00 UTC) ──signed POST──▶ api.ignitify.dev/hooks/trigger/<hook-id>
                                        │ starts a run
                                        ▼
                       VM: nightly-report ──HTTPS──▶ api.github.com (only)
                                        │ run ends
                                        ▼
your server ◀──signed POST (notify)── api.ignitify.dev ── run:get ──▶ the report

The task's nature

SettingValueWhy
secrets[GITHUB_TOKEN]The name the task reads. A run fails if the name has no value yet.
network.typeegressOutbound only. Nothing can connect to the task.
egress_allow[api.github.com]The only host the task may reach.
durationshortFour API calls and some text: a few seconds.
presetstd.micro128 MiB is enough. The smallest size costs the least.

Before you start

  • A plan with webhooks. This tutorial uses Starter. Free allows the secret, but not the outbound call, hook:create or notify:set.
  • The CLI, installed and signed in. See Install.
  • A GitHub token that can read the repository: a fine-grained token with read-only access is enough.
terminal
$ ignitify login

Create the task

terminal
$ ignitify task:create nightly-report
tasks/nightly-report/
tasks/nightly-report/
├── task.yaml     the secret name, outbound access, run defaults
├── index.ts      the shell: the GitHub calls, the metrics, the result
├── utils.ts      the pure parts: payload rules, the digest, the Markdown report
└── README.md     how to run it

The code

index.ts makes the four GitHub calls at the same time and turns a GitHub refusal into a clear error, so a failed run says what to fix. utils.ts sorts what GitHub returned into the report and keeps it under the 10 KiB result limit: at most 10 items per section, and a note when GitHub returned a full page.

index.ts
// Nightly report: a digest of the last N hours of one GitHub repository — releases, merged and new
// pull requests, new and closed issues, commits — returned as Markdown.
//
// Payload: { repo: "owner/name" (required), hours?: number (default 24, at most 168) }
// Secret:  GITHUB_TOKEN (a read-only token), from `ignitify secret:set GITHUB_TOKEN --stdin`.
// Network: outbound to api.github.com only (egress_allow in task.yaml).
//
// Run it at a set time with `task:run --at`, or every night from a cron that calls a webhook.
// When the run ends, notify:set calls your URL; read the report with `run:get <run-id> --json`.
//
// This file is the shell: the GitHub calls and the result. The pure parts live in utils.ts.

import {
  PAGE_SIZE, counts, digest, parseInput, renderReport,
  type Commit, type Issue, type Release, type Repo,
} from "./utils.js";

type Ctx = {
  secrets: Record<string, string>;
  metric(name: string, value: number): void;
};

type ReportResult = {
  repo: string;
  since: string;
  hours: number;
  counts: Record<string, number>;
  report: string;
};

const API = "https://api.github.com";
const TIMEOUT_MS = 20_000;

/** One GitHub GET. A refusal names its cause, so the failed run says what to fix. */
async function github<T>(token: string, path: string): Promise<T> {
  const res = await fetch(`${API}${path}`, {
    headers: {
      accept: "application/vnd.github+json",
      authorization: `Bearer ${token}`,
      "user-agent": "ignitify-nightly-report",
      "x-github-api-version": "2022-11-28",
    },
    signal: AbortSignal.timeout(TIMEOUT_MS),
  });
  if (res.status === 401) throw new Error("GitHub refused GITHUB_TOKEN (401): set a valid token with `ignitify secret:set GITHUB_TOKEN --stdin`");
  if (res.status === 404) throw new Error(`GitHub has no repository at ${path.split("/").slice(2, 4).join("/")} (404), or the token cannot see it`);
  if (res.status === 403 || res.status === 429) {
    const reset = Number(res.headers.get("x-ratelimit-reset"));
    const when = Number.isFinite(reset) && reset > 0 ? new Date(reset * 1000).toISOString() : "a while";
    throw new Error(`GitHub refused the request (${res.status}): a rate limit, or the token has no access. Rate limit resets at ${when}`);
  }
  if (!res.ok) throw new Error(`GitHub answered ${res.status} for ${path}`);
  return (await res.json()) as T;
}

export async function run(payload: Record<string, unknown>, ctx: Ctx): Promise<ReportResult> {
  const now = new Date();
  const input = parseInput(payload, now);
  const token = ctx.secrets.GITHUB_TOKEN ?? "";
  const base = `/repos/${input.repo}`;
  const since = encodeURIComponent(input.since);
  console.log(`report for ${input.repo} since ${input.since}`);

  // The four reads are independent, so they run at the same time.
  const [repo, commits, issues, releases] = await Promise.all([
    github<Repo>(token, base),
    github<Commit[]>(token, `${base}/commits?since=${since}&per_page=${PAGE_SIZE}`),
    github<Issue[]>(token, `${base}/issues?state=all&since=${since}&sort=updated&per_page=${PAGE_SIZE}`),
    github<Release[]>(token, `${base}/releases?per_page=20`),
  ]);

  const d = digest(commits, issues, releases, input.since);
  const numbers = counts(d);
  for (const [name, value] of Object.entries(numbers)) ctx.metric(`report_${name}`, value);
  console.log(`done: ${Object.entries(numbers).map(([k, v]) => `${k}=${v}`).join(" ")}`);

  return { repo: repo.full_name, since: input.since, hours: input.hours, counts: numbers, report: renderReport(input, repo, d, now) };
}
utils.ts
// The pure parts of nightly-report: payload rules, the digest of what GitHub returned, and the
// Markdown report. No I/O here, so every function is a plain input → output.

/** What the task needs, after the payload is checked. */
export type ReportInput = { readonly repo: string; readonly hours: number; readonly since: string };

/** The fields the report reads from GitHub's REST answers. */
export type Repo = { full_name: string; html_url: string; stargazers_count: number; forks_count: number; open_issues_count: number };
export type Commit = { sha: string; html_url: string; commit: { message: string; author: { name: string } | null } };
export type Issue = {
  number: number; title: string; html_url: string; state: "open" | "closed";
  created_at: string; closed_at: string | null; user: { login: string } | null;
  pull_request?: { merged_at: string | null };
};
export type Release = { tag_name: string; name: string | null; html_url: string; published_at: string | null };

/** One line of the report: a title, a link, and who. */
export type Item = { readonly title: string; readonly url: string; readonly by: string };

export type Digest = {
  readonly commits: readonly Item[];
  readonly openedIssues: readonly Item[];
  readonly closedIssues: readonly Item[];
  readonly openedPulls: readonly Item[];
  readonly mergedPulls: readonly Item[];
  readonly releases: readonly Item[];
  /** GitHub returned a full page (PAGE_SIZE) of commits or issues: the counts are "at least". */
  readonly truncated: boolean;
};

export const PAGE_SIZE = 100;
const MAX_HOURS = 168;
const ITEMS_PER_SECTION = 10;
/** The result limit is 10 KiB; the report keeps under this, with room for the other fields. */
const REPORT_MAX_BYTES = 8000;

/** Check the payload: `repo` is "owner/name"; `hours` defaults to 24, at most a week. */
export function parseInput(payload: Record<string, unknown>, now: Date): ReportInput {
  const repo = typeof payload.repo === "string" ? payload.repo.trim() : "";
  if (!/^[\w.-]+\/[\w.-]+$/.test(repo)) throw new Error('payload.repo must be "owner/name", for example "nodejs/node"');
  const hours = typeof payload.hours === "number" && payload.hours > 0 ? Math.min(payload.hours, MAX_HOURS) : 24;
  return { repo, hours, since: new Date(now.getTime() - hours * 3_600_000).toISOString() };
}

const after = (iso: string | null | undefined, since: string): boolean => iso != null && iso >= since;
const firstLine = (s: string): string => s.split("\n")[0]?.trim() ?? "";
const issueItem = (i: Issue): Item => ({ title: `#${i.number} ${i.title}`, url: i.html_url, by: i.user?.login ?? "unknown" });

/** Sort GitHub's answers into what happened since `since`. The issues list holds pull requests too. */
export function digest(commits: readonly Commit[], issues: readonly Issue[], releases: readonly Release[], since: string): Digest {
  const pulls = issues.filter((i) => i.pull_request !== undefined);
  const plain = issues.filter((i) => i.pull_request === undefined);
  return {
    commits: commits.map((c) => ({ title: firstLine(c.commit.message), url: c.html_url, by: c.commit.author?.name ?? "unknown" })),
    openedIssues: plain.filter((i) => after(i.created_at, since)).map(issueItem),
    closedIssues: plain.filter((i) => i.state === "closed" && after(i.closed_at, since)).map(issueItem),
    openedPulls: pulls.filter((i) => after(i.created_at, since)).map(issueItem),
    mergedPulls: pulls.filter((i) => after(i.pull_request?.merged_at, since)).map(issueItem),
    releases: releases.filter((r) => after(r.published_at, since)).map((r) => ({ title: r.name || r.tag_name, url: r.html_url, by: r.tag_name })),
    truncated: commits.length >= PAGE_SIZE || issues.length >= PAGE_SIZE,
  };
}

/** The numbers, for the result and the metrics. */
export function counts(d: Digest): Record<string, number> {
  return {
    commits: d.commits.length,
    issues_opened: d.openedIssues.length,
    issues_closed: d.closedIssues.length,
    pulls_opened: d.openedPulls.length,
    pulls_merged: d.mergedPulls.length,
    releases: d.releases.length,
  };
}

function section(title: string, items: readonly Item[]): string[] {
  if (items.length === 0) return [];
  const more = items.length > ITEMS_PER_SECTION ? [`- …and ${items.length - ITEMS_PER_SECTION} more`] : [];
  return [`## ${title} (${items.length})`, ...items.slice(0, ITEMS_PER_SECTION).map((i) => `- [${i.title}](${i.url}) by ${i.by}`), ...more, ""];
}

/** The Markdown report, cut to fit the result limit. */
export function renderReport(input: ReportInput, repo: Repo, d: Digest, now: Date): string {
  const quiet = Object.values(counts(d)).every((n) => n === 0);
  const lines = [
    `# ${repo.full_name}: the last ${input.hours} h`,
    "",
    `${input.since.slice(0, 16)}Z → ${now.toISOString().slice(0, 16)}Z · ★ ${repo.stargazers_count} · forks ${repo.forks_count} · open issues and PRs ${repo.open_issues_count}`,
    "",
    ...(quiet ? ["Nothing happened in this window.", ""] : []),
    ...section("Releases", d.releases),
    ...section("Merged pull requests", d.mergedPulls),
    ...section("New pull requests", d.openedPulls),
    ...section("New issues", d.openedIssues),
    ...section("Closed issues", d.closedIssues),
    ...section("Commits", d.commits),
    ...(d.truncated ? [`Note: GitHub returned a full page (${PAGE_SIZE}), so some counts are at least that many.`] : []),
  ];
  const text = lines.join("\n").trim();
  return Buffer.byteLength(text) <= REPORT_MAX_BYTES ? text : `${Buffer.from(text).subarray(0, REPORT_MAX_BYTES).toString().replace(/�*$/, "")}\n\n…(cut to fit the result limit)`;
}
task.yaml
schema_version: 1
slug: nightly-report            # must match this directory's name
runtime: node

# Secret NAMES the task reads from ctx.secrets. Set the value with `ignitify secret:set GITHUB_TOKEN --stdin`.
# A run fails if a declared name has no value.
secrets: [GITHUB_TOKEN]

execution:
  duration: short               # a few seconds of API calls
  network:
    type: egress                # outbound only: nothing can connect to this task
    egress_allow: [api.github.com]   # the only host the task may reach

run:
  payload:
    repo: nodejs/node
    hours: 24
  preset: std.micro             # 128 MiB is enough: four HTTP calls and some text
  timeout_sec: 120
README.md
# nightly-report

A digest of the last N hours of one GitHub repository: releases, merged and new pull requests, new and closed issues, and commits, as Markdown. Run it once at a set time, or every night from a cron that calls a webhook. When a run ends, the platform calls your URL, and you read the report from the run.

## Files

- `task.yaml`: slug, runtime, the secret name, outbound access to `api.github.com` only, and run defaults.
- `index.ts`: the shell: four GitHub calls at the same time, the metrics and the result.
- `utils.ts`: the pure parts: payload rules, the digest and the Markdown report.

## Payload

| Field | Default | Meaning |
| :-- | :-- | :-- |
| `repo` | `nodejs/node` (in task.yaml) | The repository, as `owner/name` (required) |
| `hours` | 24 | The window, at most 168 (one week) |

## Result

`{ repo, since, hours, counts: { commits, issues_opened, issues_closed, pulls_opened, pulls_merged, releases }, report }`. `report` is Markdown, cut to fit the 10 KiB result limit. Each section lists 10 items at most.

## Lifecycle

```bash
ignitify login
ignitify task:create nightly-report
ignitify secret:set GITHUB_TOKEN --stdin < github-token.txt   # a read-only token
ignitify task:validate nightly-report
ignitify task:deploy nightly-report
ignitify task:run nightly-report --wait
ignitify task:run nightly-report --payload '{"repo":"nodejs/node","hours":24}' --at 2027-01-15T06:00:00Z
ignitify schedule:list
```

Every night: create a webhook with `ignitify hook:create nightly-report`, and call it from a cron (for example a GitHub Actions schedule). Get a callback when the run ends with `ignitify notify:set <deployment-id> --url https://… --secret-stdin`.

Read a report:

```bash
ignitify run:get <run-id> --json | jq -r .result.report
```

Store the token

Read the value from a file or a pipe, so it stays out of your shell history. A value on the command line is refused.

terminal
$ ignitify secret:set GITHUB_TOKEN --stdin < github-token.txt✓ secret GITHUB_TOKEN stored
terminal
$ ignitify secret:list

Validate and deploy

terminal
$ ignitify task:validate nightly-report✓ task config valid
terminal
$ ignitify task:deploy nightly-report✓ Image built · <build time>✓ Deployment Createddeployment_id  <deployment-id>

Run it once

The default payload in task.yaml reads nodejs/node for the last 24 hours. --wait follows the run and prints the result.

terminal
$ ignitify task:run nightly-report --wait
another repository
$ ignitify task:run nightly-report --wait --payload '{"repo":"your-org/your-repo","hours":72}'

Print only the Markdown report:

terminal
$ ignitify run:get <run-id> --json | jq -r .result.report
report (example)
# octo-org/widgets: the last 24 h

2026-10-19T06:00Z → 2026-10-20T06:00Z · ★ 4210 · forks 388 · open issues and PRs 57

## Merged pull requests (2)
- [#812 cache: drop stale entries on reload](https://github.com/octo-org/widgets/pull/812) by ana
- [#809 docs: fix the install command](https://github.com/octo-org/widgets/pull/809) by lee

## New issues (1)
- [#815 Crash when the config file is empty](https://github.com/octo-org/widgets/issues/815) by sam

## Commits (5)
- [cache: drop stale entries on reload](https://github.com/octo-org/widgets/commit/3f2a1c9) by Ana
- …

A wrong repository or token fails the run with the reason, for example GitHub has no repository at owner/name (404), or the token cannot see it. Read it with run:get <run-id>.

Run it at a set time

For one run at a known time, use --at with a future UTC time. No run exists until it fires.

terminal
$ ignitify task:run nightly-report --at 2027-01-15T06:00:00ZScheduled: sch_<schedule-id> fires at 2027-01-15T06:00:00.000ZNo run exists until it fires. List with 'ignitify schedule:list'; cancel with 'ignitify schedule:cancel sch_<schedule-id>'.
terminal
$ ignitify schedule:list
terminal
$ ignitify schedule:cancel sch_<schedule-id> -y

Run it every night

Create a webhook for the task. The reply shows the secret once, so store it now. A new deploy of the task keeps the same URL and secret.

terminal
$ ignitify hook:create nightly-report⚠️ The `secret` below is shown ONCE and cannot be read back — `hook:list` never returns it.✓ Webhook Createdurl     https://api.ignitify.dev/hooks/trigger/<hook-id>secret  <hook-secret> (shown ONCE)

Put the URL and the secret in your repository's Actions secrets as IGNITIFY_HOOK_URL and IGNITIFY_HOOK_SECRET, and add this workflow. It signs the body and sends one delivery id per day, so a retried job returns the same run.

.github/workflows/nightly-report.yml
# .github/workflows/nightly-report.yml — starts one report run every night by calling the webhook.
# Repository secrets: IGNITIFY_HOOK_URL and IGNITIFY_HOOK_SECRET (from `ignitify hook:create`).
name: nightly-report
on:
  schedule:
    - cron: "0 6 * * *"        # 06:00 UTC every day
  workflow_dispatch: {}         # and a "Run workflow" button for a test
jobs:
  trigger:
    runs-on: ubuntu-latest
    steps:
      - name: Start the report run
        env:
          HOOK_URL: ${{ secrets.IGNITIFY_HOOK_URL }}
          HOOK_SECRET: ${{ secrets.IGNITIFY_HOOK_SECRET }}
        run: |
          BODY='{"repo":"nodejs/node","hours":24}'
          SIG=$(printf %s "$BODY" | openssl dgst -sha256 -hmac "$HOOK_SECRET" -hex | sed 's/^.* //')
          # One delivery id per day: if the job is retried, the platform returns the same run.
          curl -fsS -X POST "$HOOK_URL" \
            -H "content-type: application/json" \
            -H "x-ignitify-signature: sha256=$SIG" \
            -H "x-ignitify-delivery: nightly-report-$(date -u +%F)" \
            -d "$BODY"

A good call answers 202 with the new run id. A wrong signature answers 401.

Get told when it is ready

Give the deployment a callback URL and a signing secret of your own. The platform POSTs there when a run ends.

terminal
$ printf %s "$NOTIFY_SECRET" | ignitify notify:set <deployment-id> --url https://reports.your-domain.example/ignitify --secret-stdin

The callback body has the run id and status, not the result. Check the signature, then read the report from the run:

receiver.ts
// receiver.ts — your endpoint for `notify:set`. The platform POSTs here when a run ends:
//   {"run_id":"run_…","status":"COMPLETED","deployment_id":"…","tenant_id":"…"}
// signed like a webhook (x-ignitify-signature: sha256=<hmac of the raw body>). The body has no
// result, so read the report from the run.
import { createHmac, timingSafeEqual } from "node:crypto";
import { createServer } from "node:http";
import { execFile } from "node:child_process";

const SECRET = process.env.NOTIFY_SECRET ?? "";

function isFromIgnitify(rawBody: string, header: string): boolean {
  const expected = createHmac("sha256", SECRET).update(rawBody).digest("hex");
  const got = header.replace(/^sha256=/, "");
  return got.length === expected.length && timingSafeEqual(Buffer.from(got), Buffer.from(expected));
}

createServer((req, res) => {
  let body = "";
  req.on("data", (c) => (body += c));
  req.on("end", () => {
    if (!isFromIgnitify(body, String(req.headers["x-ignitify-signature"] ?? ""))) return void res.writeHead(401).end();
    res.writeHead(204).end();
    const { run_id, status } = JSON.parse(body) as { run_id: string; status: string };
    if (status !== "COMPLETED") return console.log(`run ${run_id} ended ${status}`);
    // Read the result with the CLI (or the API): the Markdown report is result.report.
    execFile("ignitify", ["run:get", run_id, "--json"], (err, out) => {
      if (err) return console.error(err.message);
      console.log((JSON.parse(out) as { result: { report: string } }).result.report);
    });
  });
}).listen(8080);

Remove the callback with ignitify notify:set <deployment-id> --clear.

Clean up

terminal
$ ignitify hook:list nightly-report
terminal
$ ignitify hook:delete <hook-resource-id> -y
terminal
$ ignitify secret:delete GITHUB_TOKEN -y
terminal
$ ignitify task:delete nightly-report --yes

Next steps