forked from Automattic/jetpack
-
Notifications
You must be signed in to change notification settings - Fork 0
/
dangerfile.js
116 lines (100 loc) · 3.96 KB
/
dangerfile.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
/**
* External dependencies
*/
import { danger, warn, markdown, results, schedule } from 'danger';
const moment = require( 'moment' );
const phpWhitelist = require( './bin/phpcs-whitelist' );
const github = danger.github;
const pr = github.pr;
const newFiles = danger.git.created_files;
// No PR is too small to include a description of why you made a change
if ( pr.body.length < 10 ) {
warn( 'Please include a description of your PR changes.' );
}
// Use labels please!
const ghLabels = github.issue.labels;
if ( ! ghLabels.find( l => l.name.toLowerCase().includes( '[status]' ) ) ) {
warn(
'The PR is missing at least one `[Status]` label. Suggestions: `[Status] In Progress`, `[Status] Needs Review`'
);
}
// Test instructions
if ( ! pr.body.includes( 'Testing instructions' ) ) {
warn( '"Testing instructions" are missing for this PR. Please add some' );
}
// Proposed changelog entry
if ( ! pr.body.includes( 'Proposed changelog entry' ) ) {
warn(
'"Proposed changelog entry" is missing for this PR. Please include any meaningful changes'
);
}
// Check if newly added .php files were added to phpcs linter whitelist
if ( newFiles.length > 0 ) {
const newPHPFiles = danger.git.created_files.filter(
fileName => fileName.includes( '.php' ) && ! fileName.includes( 'tests/php' )
);
const notWhitelistedFiles = [];
newPHPFiles.forEach( file => {
const whitelistedPath = phpWhitelist.find( path => file.includes( path ) );
if ( ! whitelistedPath ) {
notWhitelistedFiles.push( file );
}
} );
if ( notWhitelistedFiles.length > 0 ) {
const stringifiedFilesList = '\n' + notWhitelistedFiles.join( '\n' );
warn(
'Consider adding new PHP files to PHPCS whitelist for automatic linting:' +
stringifiedFilesList
);
}
}
// skip if there are no warnings.
if ( results.warnings.length > 0 || results.fails.length > 0 ) {
markdown(
"This is an automated check which relies on [`PULL_REQUEST_TEMPLATE`](https://github.com/Automattic/jetpack/blob/master/.github/PULL_REQUEST_TEMPLATE.md). We encourage you to follow that template as it helps Jetpack maintainers do their job. If you think 'Testing instructions' or 'Proposed changelog entry' are not needed for your PR - please explain why you think so. Thanks for cooperation :robot:"
);
} else {
markdown(
`**Thank you for the great PR description!**
When this PR is ready for review, please apply the \`[Status] Needs Review\` label. If you are an a11n, please have someone from your team review the code if possible. The Jetpack team will also review this PR and merge it to be included in the next Jetpack release.`
);
setReleaseDates();
}
// Adds release and code freeze dates according to x.x milestone due date
function setReleaseDates() {
schedule( async () => {
let jetpackReleaseDate;
let codeFreezeDate;
const milestones = await github.api.issues.listMilestonesForRepo( {
owner: 'Automattic',
repo: 'jetpack',
} );
// Find a milestone which name is a version number
// and it's due dates is earliest in a future
const nextMilestone = milestones.data
.filter( m => m.title.match( /\d\.\d/ ) )
.sort( ( m1, m2 ) => parseFloat( m1.title ) - parseFloat( m2.title ) )
.find( milestone => milestone.due_on && moment( milestone.due_on ) > moment() );
if ( nextMilestone ) {
jetpackReleaseDate = moment( nextMilestone.due_on ).format( 'LL' );
codeFreezeDate = moment( nextMilestone.due_on )
.subtract( 7, 'd' )
.format( 'LL' );
} else {
// Fallback to raw math calculation
// Calculate next release date
const firstTuesdayOfMonth = moment()
.add( 1, 'months' )
.startOf( 'month' );
while ( firstTuesdayOfMonth.day() !== 2 ) {
firstTuesdayOfMonth.add( 1, 'day' );
}
jetpackReleaseDate = firstTuesdayOfMonth.format( 'LL' );
// Calculate next code freeze date
codeFreezeDate = firstTuesdayOfMonth.subtract( 8, 'd' ).format( 'LL' );
}
markdown( `
Scheduled Jetpack release: _${ jetpackReleaseDate }_.
Scheduled code freeze: _${ codeFreezeDate }_` );
} );
}