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