From 7d120f94f6f45bd41e1c40ce4993a71e261f4f17 Mon Sep 17 00:00:00 2001 From: Adam Brown Date: Tue, 2 Aug 2022 12:17:48 +0100 Subject: [PATCH 1/3] reading the reviewers length from the github object as per the dsl --- tools/danger/dangerfile.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tools/danger/dangerfile.js b/tools/danger/dangerfile.js index 44b97d77c4..6bf0a10bf0 100644 --- a/tools/danger/dangerfile.js +++ b/tools/danger/dangerfile.js @@ -8,6 +8,7 @@ const {danger, warn} = require('danger') // warn(JSON.stringify(danger)) const pr = danger.github.pr +const github = danger.github // User who has created the PR. const user = pr.user.login const modified = danger.git.modified_files @@ -101,6 +102,6 @@ if (hasPngs) { } // Check for reviewers -if (pr.requested_reviewers.length == 0 && !pr.draft) { +if (github.requested_reviewers.length == 0 && !pr.draft) { warn("Please add a reviewer to your PR.") } From ba5d6c9108103e36e6b486ddc6b8ae10d02c2c02 Mon Sep 17 00:00:00 2001 From: Adam Brown Date: Tue, 2 Aug 2022 12:19:16 +0100 Subject: [PATCH 2/3] replacing all danger mutable lets with const --- tools/danger/dangerfile.js | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/tools/danger/dangerfile.js b/tools/danger/dangerfile.js index 6bf0a10bf0..26ab19ce7b 100644 --- a/tools/danger/dangerfile.js +++ b/tools/danger/dangerfile.js @@ -13,7 +13,7 @@ const github = danger.github const user = pr.user.login const modified = danger.git.modified_files const created = danger.git.created_files -let editedFiles = [...modified, ...created] +const editedFiles = [...modified, ...created] // Check that the PR has a description if (pr.body.length == 0) { @@ -30,10 +30,10 @@ const changelogAllowList = [ "dependabot[bot]", ] -let requiresChangelog = !changelogAllowList.includes(user) +const requiresChangelog = !changelogAllowList.includes(user) if (requiresChangelog) { - let changelogFiles = editedFiles.filter(file => file.startsWith("changelog.d/")) + const changelogFiles = editedFiles.filter(file => file.startsWith("changelog.d/")) if (changelogFiles.length == 0) { warn("Please add a changelog. See instructions [here](https://github.com/vector-im/element-android/blob/develop/CONTRIBUTING.md#changelog)") @@ -77,18 +77,18 @@ const allowList = [ "yostyle", ] -let requiresSignOff = !allowList.includes(user) +const requiresSignOff = !allowList.includes(user) if (requiresSignOff) { - let hasPRBodySignOff = pr.body.includes(signOff) - let hasCommitSignOff = danger.git.commits.every(commit => commit.message.includes(signOff)) + const hasPRBodySignOff = pr.body.includes(signOff) + const hasCommitSignOff = danger.git.commits.every(commit => commit.message.includes(signOff)) if (!hasPRBodySignOff && !hasCommitSignOff) { fail("Please add a sign-off to either the PR description or to the commits themselves.") } } // Check for screenshots on view changes -let hasChangedViews = editedFiles.filter(file => file.includes("/layout")).length > 0 +const hasChangedViews = editedFiles.filter(file => file.includes("/layout")).length > 0 if (hasChangedViews) { if (!pr.body.includes("user-images")) { warn("You seem to have made changes to views. Please consider adding screenshots.") @@ -96,7 +96,7 @@ if (hasChangedViews) { } // Check for pngs on resources -let hasPngs = editedFiles.filter(file => file.toLowerCase().endsWith(".png")).length > 0 +const hasPngs = editedFiles.filter(file => file.toLowerCase().endsWith(".png")).length > 0 if (hasPngs) { warn("You seem to have made changes to some images. Please consider using an vector drawable.") } From c99f67bea415a081eee075229646c6bfe4fe1609 Mon Sep 17 00:00:00 2001 From: Adam Brown Date: Tue, 2 Aug 2022 12:34:36 +0100 Subject: [PATCH 3/3] reading users field from the reviews object for calculating if reviewers have been set --- tools/danger/dangerfile.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/danger/dangerfile.js b/tools/danger/dangerfile.js index 26ab19ce7b..59a616db4a 100644 --- a/tools/danger/dangerfile.js +++ b/tools/danger/dangerfile.js @@ -102,6 +102,6 @@ if (hasPngs) { } // Check for reviewers -if (github.requested_reviewers.length == 0 && !pr.draft) { +if (github.requested_reviewers.users.length == 0 && !pr.draft) { warn("Please add a reviewer to your PR.") }