diff --git a/.github/composite/pr-description-check/action.yml b/.github/composite/pr-description-check/action.yml new file mode 100644 index 000000000..75a3040e5 --- /dev/null +++ b/.github/composite/pr-description-check/action.yml @@ -0,0 +1,18 @@ +name: "Verify PR Description" +description: "Ensure the GH PR description is filled out" + +inputs: + PR_ID: + description: "PR ID" + required: true + +runs: + using: "composite" + steps: + - name: Setup CI + uses: ./.github/composite/setup-ci + + - name: Run script + id: run_script + shell: bash + run: bun .github/scripts/pr-description-check --prId=${{ inputs.PR_ID }} diff --git a/.github/scripts/pr-description-check/index.ts b/.github/scripts/pr-description-check/index.ts new file mode 100644 index 000000000..c519ee6c3 --- /dev/null +++ b/.github/scripts/pr-description-check/index.ts @@ -0,0 +1,60 @@ +import { Octokit } from "@octokit/rest"; +import { sendMessage } from "utils/send-message"; +import yargs from "yargs"; +import { hideBin } from "yargs/helpers"; + +const { prId } = await yargs(hideBin(process.argv)) + .option("prId", { + type: "number", + describe: "Pull request number", + demandOption: true, + }) + .strict() + .parse(); + +const [owner, repo] = (() => { + const v = process.env.GITHUB_REPOSITORY; + if (!v) throw new Error("GITHUB_REPOSITORY is required"); + return v.split("/") as [string, string]; +})(); + +async function main() { + const client = new Octokit({ auth: process.env.GH_TOKEN }); + const { data } = await client.rest.pulls.get({ + owner, + repo, + pull_number: prId, + }); + const { body } = data; + + const descriptionContent = (() => { + const match = (body ?? "").match( + /## Description of changes([\s\S]*?)(?=\n##|$)/, + ); + return (match?.[1] ?? "").trim(); + })(); + + if (descriptionContent) { + console.log("PR description is filled out"); + return; + } + + await sendMessage( + prId, + ` +### PR Description Required +Please fill out the \`Description of changes\` section of the PR.`.trim(), + ); + + console.error("PR description is empty."); + process.exit(1); +} + +main() + .then(() => { + process.exit(0); + }) + .catch((e) => { + console.error(e); + process.exit(1); + }); diff --git a/.github/workflows/pr-verifications.yml b/.github/workflows/pr-verifications.yml index 9dc4b9073..d09788c13 100644 --- a/.github/workflows/pr-verifications.yml +++ b/.github/workflows/pr-verifications.yml @@ -22,6 +22,11 @@ jobs: - name: Checkout Repository uses: actions/checkout@v4 + - name: Verify PR description is filled out + uses: ./.github/composite/pr-description-check + with: + PR_ID: ${{ github.event.number }} + - name: Run composite workflow uses: ./.github/composite/notion-checks id: notion_check