File tree 2 files changed +62
-0
lines changed
2 files changed +62
-0
lines changed Original file line number Diff line number Diff line change
1
+ name : Block Invalid PR
2
+
3
+ on :
4
+ pull_request_target :
5
+ types : [opened, reopened, edited]
6
+
7
+ jobs :
8
+ check-template :
9
+ runs-on : ubuntu-latest
10
+ permissions :
11
+ pull-requests : write
12
+ steps :
13
+ - name : Checkout Code
14
+ uses : actions/checkout@v4
15
+
16
+ - name : Check PR Content
17
+ uses : actions/github-script@v7
18
+ with :
19
+ github-token : ${{ secrets.GITHUB_TOKEN }}
20
+ script : |
21
+ const script = require('.github/workflows/scripts/pr-filter.js');
22
+ await script({ github, context });
Original file line number Diff line number Diff line change
1
+ function noTypes ( markdown ) {
2
+ if ( / # # T y p e o f c h a n g e / . test ( markdown ) && / - \[ x \] / i. test ( markdown ) ) {
3
+ return false ;
4
+ }
5
+ return true ;
6
+ }
7
+
8
+ function noDescription ( markdown ) {
9
+ return (
10
+ / # # D e s c r i p t i o n / . test ( markdown ) === false ||
11
+ / # # D e s c r i p t i o n \s * \n \s * # # \w + / . test ( markdown ) ||
12
+ / # # D e s c r i p t i o n \s * \n \s * $ / . test ( markdown )
13
+ ) ;
14
+ }
15
+
16
+ module . exports = async ( { github, context } ) => {
17
+ const pr = context . payload . pull_request ;
18
+
19
+ if ( pr . labels . length > 0 ) {
20
+ // Skip if the PR is already labeled (typically created by a deps-bot.)
21
+ return ;
22
+ }
23
+
24
+ const body = pr . body === null ? '' : pr . body . trim ( ) ;
25
+ const markdown = body . replace ( / < ! - - [ \s \S ] * ?- - > / g, '' ) ;
26
+
27
+ if ( body === '' || noTypes ( markdown ) || noDescription ( markdown ) ) {
28
+ await github . rest . pulls . update ( {
29
+ ...context . repo ,
30
+ pull_number : pr . number ,
31
+ state : 'closed'
32
+ } ) ;
33
+
34
+ await github . rest . issues . createComment ( {
35
+ ...context . repo ,
36
+ issue_number : pr . number ,
37
+ body : "Oops, it seems you've submitted an invalid pull request. No worries, we'll close it for you."
38
+ } ) ;
39
+ }
40
+ } ;
You can’t perform that action at this time.
0 commit comments