#!/usr/bin/env -S deno run --check --allow-write=. --allow-read=. --lock=./tools/deno.lock.json
// Copyright 2018-2026 the Deno authors. MIT license.
import { createWorkflow, step } from "jsr:@david/gagen@0.3.1";

const workflow = createWorkflow({
  name: "pr",
  on: {
    pull_request: {
      types: ["opened", "edited", "synchronize"],
    },
  },
  jobs: [{
    id: "main",
    name: "lint title",
    runsOn: "ubuntu-latest",
    steps: [
      step({
        name: "Install Deno",
        uses: "denoland/setup-deno@v2",
        with: { "deno-version": "canary" },
      }),
      step({
        name: "Lint",
        env: { PR_TITLE: "${{ github.event.pull_request.title }}" },
        run:
          'deno run https://raw.githubusercontent.com/denoland/deno/refs/heads/main/tools/verify_pr_title.js "$PR_TITLE"',
      }),
    ],
  }],
});

const header = [
  "# GENERATED BY ./pr.ts -- DO NOT DIRECTLY EDIT",
  "#",
  "# WARNING: This workflow runs in the context of the base repository so the",
  "# GITHUB_TOKEN it has access to has full write permissions to the repository.",
].join("\n");

export function generate() {
  return workflow.toYamlString({ header });
}

export const PR_YML_URL = new URL("./pr.generated.yml", import.meta.url);

if (import.meta.main) {
  workflow.writeOrLint({ filePath: PR_YML_URL, header });
}
