File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Load Diff This file was deleted.
Original file line number Diff line number Diff line change 1+ const { danger, fail } = require ( "danger" ) ;
2+ const { validate } = require ( "./validate" ) ;
3+
4+ validate ( { title : danger . github . pr . title , onError : fail } ) ;
Original file line number Diff line number Diff line change 1+ This folder contains configuration files which are used to run validation rules on Github pull requests titles.
2+
3+ It is done by running [ Danger JS] ( https://danger.systems/js/ ) tool in [ github action] ( ../../.github/workflows/danger.yml ) .
4+
5+ In addition, the validation rules are tested. Tests can be executed with node, by running ` node ./validate.test.js `
Original file line number Diff line number Diff line change 1+ const allowedTypes = [
2+ "feat" ,
3+ "fix" ,
4+ "chore" ,
5+ "docs" ,
6+ "style" ,
7+ "refactor" ,
8+ "perf" ,
9+ "test" ,
10+ "ci" ,
11+ "revert" ,
12+ ] ;
13+
14+ const allowedSubTypes = [
15+ "build" ,
16+ "sql" ,
17+ "log" ,
18+ "mig" ,
19+ "core" ,
20+ "ilp" ,
21+ "pgwire" ,
22+ "http" ,
23+ "conf" ,
24+ "ui" ,
25+ "wal" ,
26+ "parquet" ,
27+ "utils"
28+ ] ;
29+
30+ const errorMessage = `
31+ Please update the PR title to match this format:
32+ \`type(subType): description\`
33+
34+ Where \`type\` is one of:
35+ ${ allowedTypes . map ( ( t ) => `\`${ t } \`` ) . join ( ", " ) }
36+
37+ And: \`subType\` is one of:
38+ ${ allowedSubTypes . map ( ( t ) => `\`${ t } \`` ) . join ( ", " ) }
39+
40+ For Example:
41+
42+ \`\`\`
43+ perf(sql): improve pattern matching performance for SELECT sub-queries
44+ \`\`\`
45+ ` . trim ( ) ;
46+
47+ /* The basic valid PR title formats are:
48+ * 1. allowedType(allowedSubtype): optional description
49+ * 2. allowedType: optional description
50+ *
51+ * consult ./validate.test.js for a full list
52+ * */
53+ const prTitleRegex = new RegExp (
54+ `^(((?:${ allowedTypes . join ( "|" ) } )\\((?:${ allowedSubTypes . join (
55+ "|"
56+ ) } )\\))|build): .*`
57+ ) ;
58+
59+ function validate ( { title, onError } ) {
60+ // Early return for title that matches predefined regex.
61+ // No action required in such case.
62+ if ( title . match ( prTitleRegex ) ) {
63+ return ;
64+ }
65+
66+ onError ( errorMessage ) ;
67+ }
68+
69+ module . exports = {
70+ allowedTypes,
71+ allowedSubTypes,
72+ validate,
73+ } ;
Original file line number Diff line number Diff line change 1+ const assert = require ( "node:assert" ) . strict ;
2+ const { validate, allowedTypes, allowedSubTypes } = require ( "./validate" ) ;
3+
4+ const testValid = ( title ) =>
5+ assert . doesNotThrow ( ( ) =>
6+ validate ( {
7+ title,
8+ onError : ( ) => {
9+ throw `should accept "${ title } "` ;
10+ } ,
11+ } )
12+ ) ;
13+
14+ const testInvalid = ( title ) =>
15+ assert . throws (
16+ ( ) => validate ( { title, onError } ) ,
17+ `should NOT accept "${ title } "`
18+ ) ;
19+
20+ allowedTypes . forEach ( ( type ) => {
21+ allowedSubTypes . forEach ( ( subType ) => {
22+ testValid (
23+ `${ type } (${ subType } ): foo` ,
24+ `should accept "${ type } (${ subType } ): foo"`
25+ ) ;
26+ } ) ;
27+ } ) ;
28+
29+ testValid ( "build: 6.6" ) ;
30+ testValid ( "build: hello world" ) ;
31+ testInvalid ( "build" ) ;
32+
33+ testValid ( `build: house` ) ;
34+ testInvalid ( `build(house)` ) ;
35+
36+ testInvalid ( `foo: bar` ) ;
37+ testInvalid ( `update(bar): baz` ) ;
38+ testInvalid ( `ui: updating stuff` ) ;
You can’t perform that action at this time.
0 commit comments