File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ name : PR Title Check
2+
3+ on :
4+ pull_request_target :
5+ types : [opened, edited, reopened, synchronize]
6+
7+ jobs :
8+ title-format :
9+ runs-on : ubuntu-latest
10+ permissions :
11+ pull-requests : write
12+ issues : write
13+
14+ steps :
15+ - name : Validate PR title
16+ uses : actions/github-script@v7
17+ with :
18+ script : |
19+ const title = (context.payload.pull_request.title || "").trim();
20+ // allow only:
21+ // feat: xxx
22+ // feat(scope): xxx
23+ const pattern = /^(feat)(\([a-z0-9-]+\))?:\s.+$/i;
24+ const isValid = pattern.test(title);
25+ const isSameRepo =
26+ context.payload.pull_request.head.repo.full_name === context.payload.repository.full_name;
27+
28+ if (!isValid) {
29+ if (isSameRepo) {
30+ try {
31+ await github.rest.issues.createComment({
32+ owner: context.repo.owner,
33+ repo: context.repo.repo,
34+ issue_number: context.payload.pull_request.number,
35+ body: [
36+ "⚠️ PR title format check failed.",
37+ "Required formats:",
38+ "- `feat: xxx`",
39+ "- `feat(scope): xxx`",
40+ "Please update your PR title and push again."
41+ ].join("\n")
42+ });
43+ } catch (e) {
44+ core.warning(`Failed to post PR title comment: ${e.message}`);
45+ }
46+ } else {
47+ core.warning("Fork PR: comment permission is restricted; skip posting review comment.");
48+ }
49+ }
50+
51+ if (!isValid) {
52+ core.setFailed("Invalid PR title. Expected format: feat: xxx or feat(scope): xxx.");
53+ }
You can’t perform that action at this time.
0 commit comments