Skip to content
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
18 changes: 18 additions & 0 deletions .github/composite/pr-description-check/action.yml
Original file line number Diff line number Diff line change
@@ -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 }}
60 changes: 60 additions & 0 deletions .github/scripts/pr-description-check/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import { Octokit } from "@octokit/rest";
import { sendMessage } from "utils/send-message";
Comment thread
angelayu0530 marked this conversation as resolved.
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##|$)/,
);
Comment thread
angelayu0530 marked this conversation as resolved.
Comment thread
angelayu0530 marked this conversation as resolved.
Comment thread
angelayu0530 marked this conversation as resolved.
Comment thread
angelayu0530 marked this conversation as resolved.
return (match?.[1] ?? "").trim();
})();
Comment thread
angelayu0530 marked this conversation as resolved.

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(),
);
Comment thread
angelayu0530 marked this conversation as resolved.

console.error("PR description is empty.");
Comment thread
angelayu0530 marked this conversation as resolved.
process.exit(1);
}

main()
.then(() => {
process.exit(0);
})
.catch((e) => {
console.error(e);
process.exit(1);
Comment thread
angelayu0530 marked this conversation as resolved.
});
5 changes: 5 additions & 0 deletions .github/workflows/pr-verifications.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading