From c1c2e05f15281872b1e6c8bacc69448f1fe135e2 Mon Sep 17 00:00:00 2001 From: Ilya Konstantinov Date: Mon, 14 Nov 2022 11:12:55 -0500 Subject: [PATCH 1/3] mypy_primer: truncate per-project output --- .github/workflows/mypy_primer_comment.yml | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/.github/workflows/mypy_primer_comment.yml b/.github/workflows/mypy_primer_comment.yml index 2056fc5a40c0..1b7094f3c5b7 100644 --- a/.github/workflows/mypy_primer_comment.yml +++ b/.github/workflows/mypy_primer_comment.yml @@ -48,15 +48,27 @@ jobs: with: github-token: ${{ secrets.GITHUB_TOKEN }} script: | + const MAX_CHARACTERS = 30000 + const MAX_CHARACTERS_PER_PROJECT = MAX_CHARACTERS / 3 + const fs = require('fs') let data = fs.readFileSync('fulldiff.txt', { encoding: 'utf8' }) - // posting comment fails if too long, so truncate - if (data.length > 30000) { - let truncated_data = data.substring(0, 30000) - let lines_truncated = data.split('\n').length - truncated_data.split('\n').length - data = truncated_data + `\n\n... (truncated ${lines_truncated} lines) ...\n` + + function truncateIfNeeded(s, maxLength) { + let truncated = s.substring(0, maxLength) + if (s.length === truncated.length) { + return s + } + let lines_truncated = s.split('\n').length - truncated.split('\n').length + return `${truncated}\n\n... (truncated ${lines_truncated} lines) ...\n` } + const projects = data.split('\n\n') + // don't let one project dominate + data = projects.map(project => truncateIfNeeded(project, MAX_CHARACTERS_PER_PROJECT)).join('\n\n') + // posting comment fails if too long, so truncate + data = truncateIfNeeded(data, MAX_CHARACTERS) + console.log("Diff from mypy_primer:") console.log(data) From 15eeecd8751296536b95b673cd7fd55166f5870f Mon Sep 17 00:00:00 2001 From: Ilya Konstantinov Date: Mon, 14 Nov 2022 12:31:20 -0500 Subject: [PATCH 2/3] improve truncation --- .github/workflows/mypy_primer_comment.yml | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/.github/workflows/mypy_primer_comment.yml b/.github/workflows/mypy_primer_comment.yml index 1b7094f3c5b7..c95350e74250 100644 --- a/.github/workflows/mypy_primer_comment.yml +++ b/.github/workflows/mypy_primer_comment.yml @@ -54,13 +54,15 @@ jobs: const fs = require('fs') let data = fs.readFileSync('fulldiff.txt', { encoding: 'utf8' }) - function truncateIfNeeded(s, maxLength) { - let truncated = s.substring(0, maxLength) - if (s.length === truncated.length) { - return s + function truncateIfNeeded(original, maxLength) { + let truncated = original.substring(0, maxLength) + if (original.length === truncated.length) { + return original } - let lines_truncated = s.split('\n').length - truncated.split('\n').length - return `${truncated}\n\n... (truncated ${lines_truncated} lines) ...\n` + // further, remove last line that might be truncated + truncated = truncated.substring(0, truncated.lastIndexOf('\n')) + let lines_truncated = original.split('\n').length - truncated.split('\n').length + return `${truncated}\n\n... (truncated ${lines_truncated} lines) ...` } const projects = data.split('\n\n') From 6824fdd31f96f0811434aebc4451d55a66303d58 Mon Sep 17 00:00:00 2001 From: Shantanu <12621235+hauntsaninja@users.noreply.github.com> Date: Thu, 17 Nov 2022 21:32:08 -0800 Subject: [PATCH 3/3] Update .github/workflows/mypy_primer_comment.yml --- .github/workflows/mypy_primer_comment.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/mypy_primer_comment.yml b/.github/workflows/mypy_primer_comment.yml index c95350e74250..b20eaf471c9a 100644 --- a/.github/workflows/mypy_primer_comment.yml +++ b/.github/workflows/mypy_primer_comment.yml @@ -55,10 +55,10 @@ jobs: let data = fs.readFileSync('fulldiff.txt', { encoding: 'utf8' }) function truncateIfNeeded(original, maxLength) { - let truncated = original.substring(0, maxLength) - if (original.length === truncated.length) { + if (original.length <= maxLength) { return original } + let truncated = original.substring(0, maxLength) // further, remove last line that might be truncated truncated = truncated.substring(0, truncated.lastIndexOf('\n')) let lines_truncated = original.split('\n').length - truncated.split('\n').length