2022-07-29 10:00:49 +02:00
const { danger , warn } = require ( 'danger' )
/ * *
* Note : if you update the checks in this file , please also update the file . / docs / danger . md
* /
// Useful to see what we got in danger object
// warn(JSON.stringify(danger))
const pr = danger . github . pr
2022-08-02 13:17:48 +02:00
const github = danger . github
2022-07-29 15:18:04 +02:00
// User who has created the PR.
const user = pr . user . login
2022-07-29 10:00:49 +02:00
const modified = danger . git . modified _files
const created = danger . git . created _files
2022-08-02 13:19:16 +02:00
const editedFiles = [ ... modified , ... created ]
2022-07-29 10:00:49 +02:00
// Check that the PR has a description
if ( pr . body . length == 0 ) {
warn ( "Please provide a description for this PR." )
}
// Warn when there is a big PR
if ( editedFiles . length > 50 ) {
2022-07-29 15:41:36 +02:00
message ( "This pull request seems relatively large. Please consider splitting it into multiple smaller ones." )
2022-07-29 10:00:49 +02:00
}
// Request a changelog for each PR
2022-07-29 15:18:04 +02:00
const changelogAllowList = [
"dependabot[bot]" ,
]
2022-08-02 13:19:16 +02:00
const requiresChangelog = ! changelogAllowList . includes ( user )
2022-07-29 15:18:04 +02:00
if ( requiresChangelog ) {
2022-08-02 13:19:16 +02:00
const changelogFiles = editedFiles . filter ( file => file . startsWith ( "changelog.d/" ) )
2022-07-29 15:18:04 +02:00
if ( changelogFiles . length == 0 ) {
2023-12-13 11:01:40 +01:00
warn ( "Please add a changelog. See instructions [here](https://github.com/element-hq/element-android/blob/develop/CONTRIBUTING.md#changelog)" )
2022-07-29 15:18:04 +02:00
} else {
const validTowncrierExtensions = [
"bugfix" ,
"doc" ,
"feature" ,
"misc" ,
"sdk" ,
"wip" ,
]
if ( ! changelogFiles . every ( file => validTowncrierExtensions . includes ( file . split ( "." ) . pop ( ) ) ) ) {
2023-12-13 11:01:40 +01:00
fail ( "Invalid extension for changelog. See instructions [here](https://github.com/element-hq/element-android/blob/develop/CONTRIBUTING.md#changelog)" )
2022-07-29 15:18:04 +02:00
}
2022-07-29 10:00:49 +02:00
}
}
2022-08-16 11:37:48 +02:00
// check that frozen classes have not been modified
const frozenClasses = [
"OlmInboundGroupSessionWrapper.kt" ,
"OlmInboundGroupSessionWrapper2.kt" ,
]
frozenClasses . forEach ( frozen => {
if ( editedFiles . some ( file => file . endsWith ( frozen ) ) ) {
fail ( "Frozen class `" + frozen + "` has been modified. Please do not modify frozen class." )
}
}
)
2022-07-29 10:00:49 +02:00
// Check for a sign-off
const signOff = "Signed-off-by:"
// Please add new names following the alphabetical order.
const allowList = [
2022-10-05 13:19:14 +02:00
"amitkma" ,
2022-07-29 10:00:49 +02:00
"aringenbach" ,
"BillCarsonFr" ,
"bmarty" ,
"Claire1817" ,
2022-07-29 15:13:55 +02:00
"dependabot[bot]" ,
2022-07-29 10:00:49 +02:00
"ericdecanini" ,
"fedrunov" ,
"Florian14" ,
"ganfra" ,
"jmartinesp" ,
2022-10-21 18:36:31 +02:00
"jonnyandrew" ,
2022-10-25 14:50:22 +02:00
"kittykat" ,
2022-07-29 10:00:49 +02:00
"langleyd" ,
"MadLittleMods" ,
"manuroe" ,
"mnaturel" ,
"onurays" ,
"ouchadam" ,
"stefanceriu" ,
"yostyle" ,
]
2022-08-02 13:19:16 +02:00
const requiresSignOff = ! allowList . includes ( user )
2022-07-29 10:00:49 +02:00
if ( requiresSignOff ) {
2022-08-02 13:19:16 +02:00
const hasPRBodySignOff = pr . body . includes ( signOff )
const hasCommitSignOff = danger . git . commits . every ( commit => commit . message . includes ( signOff ) )
2022-07-29 10:00:49 +02:00
if ( ! hasPRBodySignOff && ! hasCommitSignOff ) {
2022-08-04 16:54:53 +02:00
fail ( "Please add a sign-off to either the PR description or to the commits themselves. See instructions [here](https://matrix-org.github.io/synapse/latest/development/contributing_guide.html#sign-off)." )
2022-07-29 10:00:49 +02:00
}
}
// Check for screenshots on view changes
2022-08-02 13:19:16 +02:00
const hasChangedViews = editedFiles . filter ( file => file . includes ( "/layout" ) ) . length > 0
2022-07-29 10:00:49 +02:00
if ( hasChangedViews ) {
if ( ! pr . body . includes ( "user-images" ) ) {
warn ( "You seem to have made changes to views. Please consider adding screenshots." )
}
}
// Check for pngs on resources
2022-08-02 13:19:16 +02:00
const hasPngs = editedFiles . filter ( file => file . toLowerCase ( ) . endsWith ( ".png" ) ) . length > 0
2022-07-29 10:00:49 +02:00
if ( hasPngs ) {
warn ( "You seem to have made changes to some images. Please consider using an vector drawable." )
}
// Check for reviewers
2022-08-02 13:34:36 +02:00
if ( github . requested _reviewers . users . length == 0 && ! pr . draft ) {
2022-07-29 15:41:36 +02:00
warn ( "Please add a reviewer to your PR." )
2022-07-29 10:00:49 +02:00
}
2022-09-22 17:03:45 +02:00
// Check that translations have not been modified by developers
if ( user != "RiotTranslateBot" ) {
if ( editedFiles . some ( file => file . endsWith ( "strings.xml" ) && ! file . endsWith ( "values/strings.xml" ) ) ) {
2023-12-13 11:01:40 +01:00
fail ( "Some translation files have been edited. Only user `RiotTranslateBot` (i.e. translations coming from Weblate) is allowed to do that.\nPlease read more about translations management [in the doc](https://github.com/element-hq/element-android/blob/develop/CONTRIBUTING.md#internationalisation)." )
2022-09-22 17:03:45 +02:00
}
}