Skip to content

Commit b187383

Browse files
committed
test
1 parent f248e68 commit b187383

File tree

3 files changed

+69
-0
lines changed

3 files changed

+69
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
name: Check
2+
description: Wait for the Netlify deployment for the current commit to be ready
3+
4+
runs:
5+
using: node20
6+
main: index.js
+60
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
const core = require('@actions/core');
2+
const github = require('@actions/github');
3+
4+
function raiseError(message) {
5+
throw new Error(message);
6+
}
7+
8+
async function getPullRequest() {
9+
const client = github.getOctokit(process.env.GITHUB_TOKEN);
10+
11+
const pr = github.context.payload.pull_request;
12+
if (!pr) {
13+
throw new Error(
14+
"This action can only be invoked in `pull_request_target` or `pull_request` events. Otherwise the pull request can't be inferred.",
15+
);
16+
}
17+
18+
const owner = pr.base.user.login;
19+
const repo = pr.base.repo.name;
20+
21+
const { data } = await client.rest.pulls.get({
22+
owner,
23+
repo,
24+
pull_number: pr.number,
25+
});
26+
27+
return data;
28+
}
29+
30+
function checkTitle(title) {
31+
if (/!/.test(title)) {
32+
raiseError(`Do not use exclamation mark ('!') in your PR Title.`);
33+
}
34+
}
35+
36+
function checkDescription(body, labels) {
37+
if (!labels.some(label => label.name === 'breaking change')) {
38+
return;
39+
}
40+
const [firstLine, secondLine] = body.split(/\r?\n/);
41+
42+
if (!firstLine || !/^BREAKING CHANGE:/.test(firstLine)) {
43+
raiseError(`Breaking change PR body should starts with "BREAKING CHANGE:"`);
44+
}
45+
if (!secondLine) {
46+
raiseError(`The description of breaking change is missing.`);
47+
}
48+
}
49+
50+
async function run() {
51+
const pullRequest = await getPullRequest();
52+
try {
53+
checkTitle(pullRequest.title);
54+
checkDescription(pullRequest.body, pullRequest.labels);
55+
} catch (e) {
56+
core.setFailed(e.message);
57+
}
58+
}
59+
60+
run();

.github/workflows/semantic-pr-titles.yml

+3
Original file line numberDiff line numberDiff line change
@@ -50,3 +50,6 @@ jobs:
5050
end with a full-stop.
5151
For PRs that add or change ESLint-plugin rules, you should begin
5252
the title with "[rule-name] "
53+
- uses: ./.github/actions/breaking-pr-check
54+
env:
55+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

0 commit comments

Comments
 (0)