mirror of
https://github.com/louislam/uptime-kuma.git
synced 2026-08-07 10:14:59 +00:00
60 lines
2.3 KiB
YAML
60 lines
2.3 KiB
YAML
name: "PR description template check"
|
|
|
|
on: # zizmor: ignore[dangerous-triggers]
|
|
pull_request_target:
|
|
types: [opened, reopened]
|
|
|
|
permissions:
|
|
pull-requests: write
|
|
issues: write
|
|
contents: read
|
|
|
|
jobs:
|
|
check-pr-description:
|
|
if: github.repository == 'louislam/uptime-kuma'
|
|
name: Check PR description and close if missing template phrase
|
|
runs-on: ubuntu-latest
|
|
permissions:
|
|
pull-requests: write
|
|
issues: write
|
|
steps:
|
|
- name: Check PR description
|
|
uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v8.0.0
|
|
with:
|
|
script: |
|
|
const pr = context.payload.pull_request;
|
|
const body = (pr && pr.body) ? pr.body : "";
|
|
const requiredPhrase = "avoid unnecessary back and forth";
|
|
|
|
const exclude = ["UptimeKumaBot", "Copilot", "copilot-swe-agent"];
|
|
const excludeLower = exclude.map((e) => e.toLowerCase());
|
|
const author = pr?.user?.login || "";
|
|
|
|
// If author is in exclude list, skip
|
|
if (author && excludeLower.includes(author.toLowerCase())) {
|
|
core.info(`PR #${pr.number} opened by excluded user '${author}', skipping template check.`);
|
|
return;
|
|
}
|
|
|
|
const owner = context.repo.owner;
|
|
const repo = context.repo.repo;
|
|
const number = pr.number;
|
|
|
|
if (!body || !body.toLowerCase().includes(requiredPhrase.toLowerCase())) {
|
|
|
|
const commentBody = `Hello! This pull request does not follow the repository's PR template and is being closed automatically.`;
|
|
|
|
// Post comment
|
|
await github.rest.issues.createComment({ owner, repo, issue_number: number, body: commentBody });
|
|
|
|
// Close
|
|
await github.rest.pulls.update({ owner, repo, pull_number: number, state: "closed" });
|
|
|
|
core.info(`Closed PR #${number} because required phrase was not present.`);
|
|
} else {
|
|
core.info("PR description contains required phrase; no action taken.");
|
|
|
|
const commentBody = `Thanks for the PR! If anyone would like to help with testing, run: \`npx kuma-pr ${pr.user.login}:${pr.head.ref}\` (requires Node.js and Docker)`;
|
|
await github.rest.issues.createComment({ owner, repo, issue_number: number, body: commentBody });
|
|
}
|