From 15cfe4becec074da27bbf38ef9378d0636c1bd98 Mon Sep 17 00:00:00 2001
From: Philip <42116482+PhilipAbed@users.noreply.github.com>
Date: Tue, 8 Aug 2023 18:36:36 +0300
Subject: [PATCH] feat: possibility to change Repository Problems header in
 dependency dashboard issue (#23551)

Co-authored-by: Michael Kriese <michael.kriese@visualon.de>
Co-authored-by: Nabeel Saabna <48175656+nabeelsaabna@users.noreply.github.com>
---
 docs/usage/configuration-options.md           |  8 +++++
 lib/config/options/index.ts                   |  9 ++++++
 lib/config/types.ts                           |  1 +
 lib/config/validation.ts                      |  1 +
 .../dependency-dashboard.spec.ts.snap         | 22 +++++++++++++
 .../repository/dependency-dashboard.spec.ts   | 32 +++++++++++++++++++
 .../repository/dependency-dashboard.ts        |  7 ++--
 7 files changed, 78 insertions(+), 2 deletions(-)

diff --git a/docs/usage/configuration-options.md b/docs/usage/configuration-options.md
index 8edee0cf2c..74dbee9010 100644
--- a/docs/usage/configuration-options.md
+++ b/docs/usage/configuration-options.md
@@ -649,6 +649,14 @@ These datasources can be referred by RegexManagers or can be used to overwrite d
 
 For more details see the [`custom` datasource documentation](/modules/datasource/custom/).
 
+## customizeDashboard
+
+You can use the `customizeDashboard` object to customize dependency dashboard.
+
+Supported fields:
+
+- `repoProblemsHeader`: This field will replace the header of the Repository Problems in dependency dashboard issue.
+
 ### defaultRegistryUrlTemplate
 
 `registryUrl` which is used, if none is return by extraction.
diff --git a/lib/config/options/index.ts b/lib/config/options/index.ts
index 3ab6ac4829..21e855259c 100644
--- a/lib/config/options/index.ts
+++ b/lib/config/options/index.ts
@@ -1977,6 +1977,15 @@ const options: RenovateOptions[] = [
     type: 'string',
     default: `This PR has been generated by [Renovate Bot](https://github.com/renovatebot/renovate).`,
   },
+  {
+    name: 'customizeDashboard',
+    description: 'Customize sections in the dependency dashboard issue.',
+    type: 'object',
+    default: {},
+    additionalProperties: {
+      type: 'string',
+    },
+  },
   {
     name: 'lockFileMaintenance',
     description: 'Configuration for lock file maintenance.',
diff --git a/lib/config/types.ts b/lib/config/types.ts
index 58a36ab501..c66c8941e1 100644
--- a/lib/config/types.ts
+++ b/lib/config/types.ts
@@ -273,6 +273,7 @@ export interface RenovateConfig
   constraintsFiltering?: ConstraintsFilter;
 
   checkedBranches?: string[];
+  customizeDashboard?: Record<string, string>;
 }
 
 export interface CustomDatasourceConfig {
diff --git a/lib/config/validation.ts b/lib/config/validation.ts
index b14ce73fa0..4684c6e877 100644
--- a/lib/config/validation.ts
+++ b/lib/config/validation.ts
@@ -616,6 +616,7 @@ export async function validateConfig(
                 'migratePresets',
                 'productLinks',
                 'secrets',
+                'customizeDashboard',
               ].includes(key)
             ) {
               const res = validatePlainObject(val);
diff --git a/lib/workers/repository/__snapshots__/dependency-dashboard.spec.ts.snap b/lib/workers/repository/__snapshots__/dependency-dashboard.spec.ts.snap
index 9bd3295445..ef4acccd71 100644
--- a/lib/workers/repository/__snapshots__/dependency-dashboard.spec.ts.snap
+++ b/lib/workers/repository/__snapshots__/dependency-dashboard.spec.ts.snap
@@ -472,6 +472,28 @@ None detected
 "
 `;
 
+exports[`workers/repository/dependency-dashboard ensureDependencyDashboard() contains logged problems with custom header 1`] = `
+"This issue lists Renovate updates and detected dependencies. Read the [Dependency Dashboard](https://docs.renovatebot.com/key-concepts/dashboard/) docs to learn more.
+
+## Repository problems
+
+platform is github
+
+ - ERROR: i am a non-duplicated problem
+
+## Pending Status Checks
+
+These updates await pending status checks. To force their creation now, click the checkbox below.
+
+ - [ ] <!-- approvePr-branch=branchName1 -->pr1
+
+## Detected dependencies
+
+None detected
+
+"
+`;
+
 exports[`workers/repository/dependency-dashboard ensureDependencyDashboard() open or update Dependency Dashboard when all branches are closed and dependencyDashboardAutoclose is false 1`] = `
 "This is a header
 
diff --git a/lib/workers/repository/dependency-dashboard.spec.ts b/lib/workers/repository/dependency-dashboard.spec.ts
index 659ee4daaf..0f22e3e558 100644
--- a/lib/workers/repository/dependency-dashboard.spec.ts
+++ b/lib/workers/repository/dependency-dashboard.spec.ts
@@ -641,6 +641,38 @@ describe('workers/repository/dependency-dashboard', () => {
       expect(platform.ensureIssue.mock.calls[0][0].body).toMatchSnapshot();
     });
 
+    it('contains logged problems with custom header', async () => {
+      const branches: BranchConfig[] = [
+        {
+          ...mock<BranchConfig>(),
+          prTitle: 'pr1',
+          upgrades: [
+            { ...mock<PrUpgrade>(), depName: 'dep1', repository: 'repo1' },
+          ],
+          result: 'pending',
+          branchName: 'branchName1',
+        },
+      ];
+      logger.getProblems.mockReturnValueOnce([
+        {
+          level: ERROR,
+          msg: 'i am a non-duplicated problem',
+        },
+      ]);
+      config.dependencyDashboard = true;
+      config.customizeDashboard = {
+        repoProblemsHeader: 'platform is {{platform}}',
+      };
+
+      await dependencyDashboard.ensureDependencyDashboard(config, branches);
+
+      expect(platform.ensureIssue).toHaveBeenCalledTimes(1);
+      expect(platform.ensureIssue.mock.calls[0][0].body).toContain(
+        'platform is github'
+      );
+      expect(platform.ensureIssue.mock.calls[0][0].body).toMatchSnapshot();
+    });
+
     it('dependency Dashboard All Pending Approval', async () => {
       const branches: BranchConfig[] = [
         {
diff --git a/lib/workers/repository/dependency-dashboard.ts b/lib/workers/repository/dependency-dashboard.ts
index 5d80ba35ca..25dc19c08f 100644
--- a/lib/workers/repository/dependency-dashboard.ts
+++ b/lib/workers/repository/dependency-dashboard.ts
@@ -174,8 +174,11 @@ function appendRepoProblems(config: RenovateConfig, issueBody: string): string {
       'repository problems'
     );
     newIssueBody += '## Repository problems\n\n';
-    newIssueBody +=
-      'These problems occurred while renovating this repository.\n\n';
+    const repoProblemsHeader =
+      config.customizeDashboard?.['repoProblemsHeader'] ??
+      'These problems occurred while renovating this repository.';
+    newIssueBody += template.compile(repoProblemsHeader, config) + '\n\n';
+
     for (const repoProblem of repoProblems) {
       newIssueBody += ` - ${repoProblem}\n`;
     }
-- 
GitLab