From 9ceeb235fd3ff25b90fa5ff2e3f4de3ef62e10e0 Mon Sep 17 00:00:00 2001 From: epolon Date: Thu, 12 Mar 2020 14:12:34 +0200 Subject: [PATCH 1/4] support exempting readme changes from pr based on a label --- tools/prlint/index.js | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/tools/prlint/index.js b/tools/prlint/index.js index 7e4212d1ef9ea..66c6989801ef3 100755 --- a/tools/prlint/index.js +++ b/tools/prlint/index.js @@ -18,7 +18,7 @@ function createGitHubClient() { } else { console.log("Creating un-authenticated GitHub Client") } - + return new GitHub({'token': token}); } @@ -60,6 +60,12 @@ function fixContainsTest(issue, files) { }; }; +function shouldExemptReadme(issue) { + return issue.labels.some(function (l) { + return l.name === 'pr-linter/exempt-readme'; + }) +} + async function mandatoryChanges(number) { if (!number) { @@ -67,10 +73,10 @@ async function mandatoryChanges(number) { } const gh = createGitHubClient(); - + const issues = gh.getIssues(OWNER, REPO); const repo = gh.getRepo(OWNER, REPO); - + console.log(`⌛ Fetching PR number ${number}`) const issue = (await issues.getIssue(number)).data; @@ -79,12 +85,15 @@ async function mandatoryChanges(number) { console.log("⌛ Validating..."); - featureContainsReadme(issue, files); + if (!shouldExemptReadme(issue)) { + featureContainsReadme(issue, files); + } + featureContainsTest(issue, files); fixContainsTest(issue, files); console.log("✅ Success") - + } // we don't use the 'export' prefix because github actions From 0ab67ac316f96fee0b6cfecc89f399be0de76a2d Mon Sep 17 00:00:00 2001 From: epolon Date: Thu, 12 Mar 2020 14:20:36 +0200 Subject: [PATCH 2/4] added test exemption as well --- tools/prlint/index.js | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/tools/prlint/index.js b/tools/prlint/index.js index 66c6989801ef3..d8e0f86c972fc 100755 --- a/tools/prlint/index.js +++ b/tools/prlint/index.js @@ -61,8 +61,16 @@ function fixContainsTest(issue, files) { }; function shouldExemptReadme(issue) { + return hasLabel(issue, 'pr-linter/exempt-readme'); +} + +function shouldExemptTest(issue) { + return hasLabel(issue, 'pr-linter/exempt-test'); +} + +function hasLabel(issue, labelName) { return issue.labels.some(function (l) { - return l.name === 'pr-linter/exempt-readme'; + return l.name === labelName; }) } @@ -89,8 +97,10 @@ async function mandatoryChanges(number) { featureContainsReadme(issue, files); } - featureContainsTest(issue, files); - fixContainsTest(issue, files); + if (!shouldExemptTest(issue)) { + featureContainsTest(issue, files); + fixContainsTest(issue, files); + } console.log("✅ Success") From 043a05a52609aa0a86addd1ba44ca9c3ceac3270 Mon Sep 17 00:00:00 2001 From: epolon Date: Thu, 12 Mar 2020 14:46:16 +0200 Subject: [PATCH 3/4] add logs when exempting PR's --- tools/prlint/index.js | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/tools/prlint/index.js b/tools/prlint/index.js index d8e0f86c972fc..6d9a1c3c42779 100755 --- a/tools/prlint/index.js +++ b/tools/prlint/index.js @@ -3,6 +3,8 @@ const GitHub = require("github-api") const OWNER = "aws" const REPO = "aws-cdk" +const EXEMPT_README = 'pr-linter/exempt-readme' +const EXEMPT_TEST = 'pr-linter/exempt-test' class LinterError extends Error { constructor(message) { @@ -61,11 +63,11 @@ function fixContainsTest(issue, files) { }; function shouldExemptReadme(issue) { - return hasLabel(issue, 'pr-linter/exempt-readme'); + return hasLabel(issue, EXEMPT_README); } function shouldExemptTest(issue) { - return hasLabel(issue, 'pr-linter/exempt-test'); + return hasLabel(issue, EXEMPT_TEST); } function hasLabel(issue, labelName) { @@ -93,11 +95,15 @@ async function mandatoryChanges(number) { console.log("⌛ Validating..."); - if (!shouldExemptReadme(issue)) { + if (shouldExemptReadme(issue)) { + console.log(`Not validating README changes since the PR is labeled with '${EXEMPT_README}'`) + } else { featureContainsReadme(issue, files); } - if (!shouldExemptTest(issue)) { + if (shouldExemptTest(issue)) { + console.log(`Not validating test changes since the PR is labeled with '${EXEMPT_TEST}'`) + } else { featureContainsTest(issue, files); fixContainsTest(issue, files); } From 3ebf5f24a6971a4705d83610f0389ac1655542ef Mon Sep 17 00:00:00 2001 From: epolon Date: Thu, 12 Mar 2020 16:37:45 +0200 Subject: [PATCH 4/4] dummy to trigger build --- tools/prlint/README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tools/prlint/README.md b/tools/prlint/README.md index 085bc115dc691..b38d330d4ebd9 100644 --- a/tools/prlint/README.md +++ b/tools/prlint/README.md @@ -1,6 +1,6 @@ # prlint (beta) -A linter that can run various checks to validate a PR adheres to our standards. +A linter that can run various checks to validate a PR adheres to our standards. ### Disclaimer @@ -41,3 +41,4 @@ Error: Features must contain a change to a README file ``` Note that an **un-authenticated** GitHub client is created, unless you set the `GITHUB_TOKEN` env variable. +